use of io.cdap.cdap.proto.MetricQueryResult in project cdap by caskdata.
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 caskdata.
the class MetricsHandlerTest method verifyGroupByResult.
private void verifyGroupByResult(String url, List<TimeSeriesResult> groupByResult) throws Exception {
MetricQueryResult result = post(url, MetricQueryResult.class);
Assert.assertEquals(groupByResult.size(), result.getSeries().length);
for (MetricQueryResult.TimeSeries timeSeries : result.getSeries()) {
boolean timeSeriesMatchFound = false;
for (TimeSeriesResult expectedTs : groupByResult) {
if (expectedTs.getTagValues().equals(timeSeries.getGrouping())) {
assertTimeValues(expectedTs, timeSeries);
timeSeriesMatchFound = true;
}
}
Assert.assertTrue(timeSeriesMatchFound);
}
}
use of io.cdap.cdap.proto.MetricQueryResult in project cdap by caskdata.
the class MetricsHandlerTest method verifyAggregateQueryResult.
private void verifyAggregateQueryResult(String url, long expectedValue) throws Exception {
// todo : can refactor this to test only the new tag name queries once we deprecate queryParam using context.
MetricQueryResult queryResult = post(url, MetricQueryResult.class);
Assert.assertEquals(expectedValue, queryResult.getSeries()[0].getData()[0].getValue());
}
use of io.cdap.cdap.proto.MetricQueryResult in project cdap by caskdata.
the class MetricsHandlerTest method verifyResolution.
private void verifyResolution(@Nullable String resolution, @Nullable Long start, @Nullable Long end, @Nullable Integer count, int expectedCode, @Nullable String expectedResolution) throws Exception {
StringBuilder url = new StringBuilder("/v3/metrics/query?tag=namespace:default&tag=app:nonexist&metric=system.read");
url.append(resolution == null ? "" : "&resolution=" + resolution);
url.append(start == null ? "" : "&start=" + start);
url.append(end == null ? "" : "&end=" + end);
url.append(count == null ? "" : "&count=" + count);
MetricQueryResult result = post(url.toString(), null, MetricQueryResult.class, expectedCode);
if (result != null) {
Assert.assertEquals(expectedResolution, result.getResolution());
}
}
use of io.cdap.cdap.proto.MetricQueryResult in project cdap by caskdata.
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);
}
}
Aggregations