use of co.cask.cdap.api.metrics.MetricDeleteQuery in project cdap by caskdata.
the class MetricsHandlerTestRun method testAutoResolutions.
@Test
public void testAutoResolutions() throws Exception {
long start = 1;
Map<String, String> sliceBy = getFlowletContext("resolutions", "WordCount1", "WordCounter", "run1", "splitter");
// 1 second
metricStore.add(new MetricValues(sliceBy, "reads", start, 1, MetricType.COUNTER));
// 30 second
metricStore.add(new MetricValues(sliceBy, "reads", start + 30, 1, MetricType.COUNTER));
// 1 minute
metricStore.add(new MetricValues(sliceBy, "reads", start + 60, 1, MetricType.COUNTER));
// 10 minutes
metricStore.add(new MetricValues(sliceBy, "reads", start + 600, 1, MetricType.COUNTER));
// 1 hour
metricStore.add(new MetricValues(sliceBy, "reads", start + 3600, 1, MetricType.COUNTER));
// 10 hour
metricStore.add(new MetricValues(sliceBy, "reads", start + 36000, 1, MetricType.COUNTER));
// seconds
verifyRangeQueryResult("/v3/metrics/query?" + getTags("resolutions", "WordCount1", "WordCounter", "splitter") + "&metric=system.reads&resolution=auto&start=" + start + "&end=" + (start + 600), 4, 4);
// minutes
verifyRangeQueryResult("/v3/metrics/query?" + getTags("resolutions", "WordCount1", "WordCounter", "splitter") + "&metric=system.reads&resolution=auto&start=" + (start - 1) + "&end=" + (start + 600), 3, 4);
// minutes
verifyRangeQueryResult("/v3/metrics/query?" + getTags("resolutions", "WordCount1", "WordCounter", "splitter") + "&metric=system.reads&resolution=auto&start=" + (start - 1) + "&end=" + (start + 3600), 4, 5);
// hours
verifyRangeQueryResult("/v3/metrics/query?" + getTags("resolutions", "WordCount1", "WordCounter", "splitter") + "&metric=system.reads&resolution=auto&start=" + (start - 1) + "&end=" + (start + 36000), 3, 6);
// delete the added metrics for testing auto resolutions
MetricDeleteQuery deleteQuery = new MetricDeleteQuery(start, (start + 36000), sliceBy);
metricStore.delete(deleteQuery);
}
use of co.cask.cdap.api.metrics.MetricDeleteQuery in project cdap by caskdata.
the class FlowUtils method deleteFlowPendingMetrics.
/**
* Delete the "system.queue.pending" metrics for a flow or for all flows in an app or a namespace.
*
* @param namespace the namespace id; may only be null if the appId and flowId are null
* @param appId the application id; may only be null if the flowId is null
*/
public static void deleteFlowPendingMetrics(MetricStore metricStore, @Nullable String namespace, @Nullable String appId, @Nullable String flowId) throws Exception {
Preconditions.checkArgument(namespace != null || appId == null, "Namespace may only be null if AppId is null");
Preconditions.checkArgument(appId != null || flowId == null, "AppId may only be null if FlowId is null");
Collection<String> names = Collections.singleton("system.queue.pending");
Map<String, String> tags = Maps.newHashMap();
if (namespace != null) {
tags.put(Constants.Metrics.Tag.NAMESPACE, namespace);
if (appId != null) {
tags.put(Constants.Metrics.Tag.APP, appId);
if (flowId != null) {
tags.put(Constants.Metrics.Tag.FLOW, flowId);
}
}
}
LOG.info("Deleting 'system.queue.pending' metric for context {}", tags);
// we must delete up to the current time - let's round up to the next second.
long nextSecond = System.currentTimeMillis() / 1000 + 1;
metricStore.delete(new MetricDeleteQuery(0L, nextSecond, names, tags));
}
use of co.cask.cdap.api.metrics.MetricDeleteQuery in project cdap by caskdata.
the class DefaultMetricStore method deleteAll.
@Override
public void deleteAll() throws Exception {
// this will delete all aggregates metrics data
delete(new MetricDeleteQuery(0, System.currentTimeMillis() / 1000, Maps.<String, String>newHashMap()));
// this will delete all timeseries data
deleteBefore(System.currentTimeMillis() / 1000);
}
use of co.cask.cdap.api.metrics.MetricDeleteQuery in project cdap by caskdata.
the class DeletedProgramHandlerStage method deleteMetrics.
private void deleteMetrics(ApplicationId applicationId, Iterable<String> flows) throws Exception {
LOG.debug("Deleting metrics for application {}", applicationId);
for (String flow : flows) {
long endTs = System.currentTimeMillis() / 1000;
Map<String, String> tags = Maps.newHashMap();
tags.put(Constants.Metrics.Tag.NAMESPACE, applicationId.getNamespace());
tags.put(Constants.Metrics.Tag.APP, applicationId.getApplication());
tags.put(Constants.Metrics.Tag.FLOW, flow);
MetricDeleteQuery deleteQuery = new MetricDeleteQuery(0, endTs, Collections.<String>emptyList(), tags);
metricStore.delete(deleteQuery);
}
}
use of co.cask.cdap.api.metrics.MetricDeleteQuery in project cdap by caskdata.
the class AbstractNamespaceResourceDeleter method deleteMetrics.
private void deleteMetrics(NamespaceId namespaceId) throws Exception {
long endTs = System.currentTimeMillis() / 1000;
Map<String, String> tags = new HashMap<>();
tags.put(Constants.Metrics.Tag.NAMESPACE, namespaceId.getNamespace());
MetricDeleteQuery deleteQuery = new MetricDeleteQuery(0, endTs, tags);
metricStore.delete(deleteQuery);
}
Aggregations