use of io.cdap.cdap.proto.MetricQueryResult in project cdap by cdapio.
the class MetricsHandlerTest method batchTest.
private void batchTest(Map<String, QueryRequestFormat> jsonBatch, ImmutableMap<String, QueryResult> expected) throws Exception {
String url = "/v3/metrics/query";
Map<String, MetricQueryResult> results = post(url, GSON.toJson(jsonBatch), new TypeToken<Map<String, MetricQueryResult>>() {
}.getType());
// check we have all the keys
Assert.assertEquals(expected.keySet(), results.keySet());
for (Map.Entry<String, MetricQueryResult> entry : results.entrySet()) {
ImmutableList<TimeSeriesSummary> expectedTimeSeriesSummary = expected.get(entry.getKey()).getExpectedList();
MetricQueryResult actualQueryResult = entry.getValue();
compareQueryResults(expectedTimeSeriesSummary, actualQueryResult);
Assert.assertEquals(expected.get(entry.getKey()).getExpectedResolution(), actualQueryResult.getResolution());
}
}
use of io.cdap.cdap.proto.MetricQueryResult in project cdap by cdapio.
the class MetricsHandlerTest method testResolutionInResponse.
@Test
public void testResolutionInResponse() throws Exception {
long start = 1;
String url = "/v3/metrics/query?" + getTags("resolutions", "WordCount1", "WordCounter", "splitter") + "&metric=system.reads&resolution=auto&start=" + (start - 1) + "&end=" + (start + 36000);
MetricQueryResult queryResult = post(url, MetricQueryResult.class);
Assert.assertEquals("3600s", queryResult.getResolution());
url = "/v3/metrics/query?" + getTags("resolutions", "WordCount1", "WordCounter", "splitter") + "&metric=system.reads&resolution=1m&start=" + (start - 1) + "&end=" + (start + 36000);
queryResult = post(url, MetricQueryResult.class);
Assert.assertEquals("60s", queryResult.getResolution());
// Have an aggregate query and ensure that its resolution is INT_MAX
url = "/v3/metrics/query?" + getTags("WordCount1", "WordCounter", "splitter") + "&metric=system.reads";
queryResult = post(url, MetricQueryResult.class);
Assert.assertEquals(Integer.MAX_VALUE + "s", queryResult.getResolution());
}
use of io.cdap.cdap.proto.MetricQueryResult in project cdap by cdapio.
the class MetricsClientTestRun method testAll.
@Test
public void testAll() throws Exception {
appClient.deploy(NamespaceId.DEFAULT, createAppJarFile(FakeApp.class));
ApplicationId app = NamespaceId.DEFAULT.app(FakeApp.NAME);
ServiceId service = app.service(PingService.NAME);
try {
programClient.start(service);
programClient.waitForStatus(service, ProgramStatus.RUNNING, 15, TimeUnit.SECONDS);
URL serviceURL = serviceClient.getServiceURL(service);
URL pingURL = new URL(serviceURL, "ping");
HttpResponse response = HttpRequests.execute(HttpRequest.get(pingURL).build(), new DefaultHttpRequestConfig(false));
Assert.assertEquals(200, response.getResponseCode());
Tasks.waitFor(true, () -> metricsClient.query(MetricsTags.service(service), Collections.singletonList(Constants.Metrics.Name.Service.SERVICE_INPUT), Collections.emptyList(), ImmutableMap.of("start", "now-20s", "end", "now")).getSeries().length > 0, 10, TimeUnit.SECONDS);
MetricQueryResult result = metricsClient.query(MetricsTags.service(service), Constants.Metrics.Name.Service.SERVICE_INPUT);
Assert.assertEquals(1, result.getSeries()[0].getData()[0].getValue());
result = metricsClient.query(MetricsTags.service(service), Collections.singletonList(Constants.Metrics.Name.Service.SERVICE_INPUT), Collections.emptyList(), Collections.singletonMap("aggregate", "true"));
Assert.assertEquals(1, result.getSeries()[0].getData()[0].getValue());
result = metricsClient.query(MetricsTags.service(service), Collections.singletonList(Constants.Metrics.Name.Service.SERVICE_INPUT), Collections.emptyList(), ImmutableMap.of("start", "now-20s", "end", "now"));
Assert.assertEquals(1, result.getSeries()[0].getData()[0].getValue());
List<MetricTagValue> tags = metricsClient.searchTags(MetricsTags.service(service));
Assert.assertEquals(1, tags.size());
Assert.assertEquals("run", tags.get(0).getName());
List<String> metrics = metricsClient.searchMetrics(MetricsTags.service(service));
Assert.assertTrue(metrics.contains(Constants.Metrics.Name.Service.SERVICE_INPUT));
} finally {
programClient.stop(service);
assertProgramRuns(programClient, service, ProgramRunStatus.KILLED, 1, 10);
appClient.delete(app);
}
}
use of io.cdap.cdap.proto.MetricQueryResult in project cdap by caskdata.
the class MetricsQueryHelper method executeBatchQueries.
public Map<String, MetricQueryResult> executeBatchQueries(Map<String, QueryRequestFormat> queries) throws Exception {
LOG.trace("Received Queries {}", queries);
Map<String, MetricQueryResult> queryFinalResponse = Maps.newHashMap();
for (Map.Entry<String, QueryRequestFormat> query : queries.entrySet()) {
MetricQueryRequest queryRequest = getQueryRequestFromFormat(query.getValue());
queryFinalResponse.put(query.getKey(), executeQuery(queryRequest));
}
return queryFinalResponse;
}
use of io.cdap.cdap.proto.MetricQueryResult 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);
}
Aggregations