use of io.cdap.cdap.api.metrics.MetricDeleteQuery in project cdap by caskdata.
the class MetricsHandlerTest method testInterpolate.
@Test
public void testInterpolate() throws Exception {
long start = System.currentTimeMillis() / 1000;
long end = start + 3;
Map<String, String> sliceBy = getServiceContext("interspace", "WordCount1", "WordCounter", "run1", "splitter");
MetricValues value = new MetricValues(sliceBy, "reads", start, 100, MetricType.COUNTER);
metricStore.add(value);
value = new MetricValues(sliceBy, "reads", end, 400, MetricType.COUNTER);
metricStore.add(value);
verifyRangeQueryResult("/v3/metrics/query?" + getTags("interspace", "WordCount1", "WordCounter", "splitter") + "&metric=system.reads&interpolate=step&start=" + start + "&end=" + end, 4, 700);
verifyRangeQueryResult("/v3/metrics/query?" + getTags("interspace", "WordCount1", "WordCounter", "splitter") + "&metric=system.reads&interpolate=linear&start=" + start + "&end=" + end, 4, 1000);
Map<String, String> deleteTags = new LinkedHashMap<>();
deleteTags.put(Constants.Metrics.Tag.NAMESPACE, "interspace");
deleteTags.put(Constants.Metrics.Tag.APP, "WordCount1");
deleteTags.put(Constants.Metrics.Tag.SERVICE, "WordCounter");
// delete the added metrics for testing interpolator
MetricDeleteQuery deleteQuery = new MetricDeleteQuery(start, end, Collections.emptySet(), deleteTags, new ArrayList<>(deleteTags.keySet()));
metricStore.delete(deleteQuery);
}
use of io.cdap.cdap.api.metrics.MetricDeleteQuery in project cdap by caskdata.
the class ApplicationLifecycleService method deleteMetrics.
/**
* Delete the metrics for an application.
*
* @param applicationId the application to delete metrics for.
*/
private void deleteMetrics(ApplicationId applicationId, ApplicationSpecification spec) throws IOException {
long endTs = System.currentTimeMillis() / 1000;
Map<String, String> tags = new LinkedHashMap<>();
tags.put(Constants.Metrics.Tag.NAMESPACE, applicationId.getNamespace());
// add or replace application name in the tagMap
tags.put(Constants.Metrics.Tag.APP, spec.getName());
MetricDeleteQuery deleteQuery = new MetricDeleteQuery(0, endTs, Collections.emptySet(), tags, new ArrayList<>(tags.keySet()));
metricsSystemClient.delete(deleteQuery);
}
use of io.cdap.cdap.api.metrics.MetricDeleteQuery in project cdap by caskdata.
the class DefaultMetricStore method deleteAll.
@Override
public void deleteAll() {
// this will delete all aggregates metrics data
delete(new MetricDeleteQuery(0, System.currentTimeMillis() / 1000, Collections.emptySet(), Collections.emptyMap(), Collections.emptyList()));
// this will delete all timeseries data
deleteBefore(System.currentTimeMillis() / 1000);
}
use of io.cdap.cdap.api.metrics.MetricDeleteQuery in project cdap by caskdata.
the class MetricsServiceMainTest method testMetricsService.
@Test
public void testMetricsService() throws Exception {
Injector injector = getServiceMainInstance(MetricsServiceMain.class).getInjector();
// make sure the metrics clean up service is running
MetricsCleanUpService service = injector.getInstance(MetricsCleanUpService.class);
Assert.assertTrue(service.isRunning());
// Publish some metrics via the MetricsCollectionService
MetricsCollectionService metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
MetricsContext context = metricsCollectionService.getContext(ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, NamespaceId.SYSTEM.getNamespace(), Constants.Metrics.Tag.APP, "test"));
context.increment("name", 10);
// Discovery the location of metrics query service
DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
Discoverable metricsEndpoint = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(Constants.Service.METRICS)).pick(5, TimeUnit.SECONDS);
Assert.assertNotNull(metricsEndpoint);
// Try to query the metrics
InetSocketAddress metricsAddr = metricsEndpoint.getSocketAddress();
ConnectionConfig connConfig = ConnectionConfig.builder().setSSLEnabled(URIScheme.HTTPS.isMatch(metricsEndpoint)).setHostname(metricsAddr.getHostName()).setPort(metricsAddr.getPort()).build();
MetricsClient metricsClient = new MetricsClient(ClientConfig.builder().setVerifySSLCert(false).setConnectionConfig(connConfig).build());
// Need to poll because metrics processing is async.
Tasks.waitFor(10L, () -> {
MetricQueryResult result = metricsClient.query(context.getTags(), "system.name");
MetricQueryResult.TimeSeries[] series = result.getSeries();
if (series.length == 0) {
return 0L;
}
return series[0].getData()[0].getValue();
}, 10, TimeUnit.SECONDS, 1, TimeUnit.SECONDS);
MetricsSystemClient metricsSystemClient = injector.getInstance(RemoteMetricsSystemClient.class);
metricsSystemClient.delete(new MetricDeleteQuery(0, Integer.MAX_VALUE, Collections.emptySet(), context.getTags(), new ArrayList<>(context.getTags().keySet())));
Tasks.waitFor(0L, () -> {
MetricQueryResult result = metricsClient.query(context.getTags(), "system.name");
MetricQueryResult.TimeSeries[] series = result.getSeries();
if (series.length == 0) {
return 0L;
}
return series[0].getData()[0].getValue();
}, 10, TimeUnit.SECONDS, 1, TimeUnit.SECONDS);
}
use of io.cdap.cdap.api.metrics.MetricDeleteQuery in project cdap by caskdata.
the class MetricsHandlerTest method testAutoResolutions.
@Test
public void testAutoResolutions() throws Exception {
long start = 1;
Map<String, String> sliceBy = getServiceContext("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);
Map<String, String> deleteTags = new LinkedHashMap<>();
deleteTags.put(Constants.Metrics.Tag.NAMESPACE, "resolutions");
deleteTags.put(Constants.Metrics.Tag.APP, "WordCount1");
deleteTags.put(Constants.Metrics.Tag.SERVICE, "WordCounter");
// delete the added metrics for testing auto resolutions
MetricDeleteQuery deleteQuery = new MetricDeleteQuery(start, (start + 36000), Collections.emptySet(), deleteTags, new ArrayList<>(deleteTags.keySet()));
metricStore.delete(deleteQuery);
}
Aggregations