Search in sources :

Example 1 with MetricQueryResult

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());
}
Also used : MetricQueryResult(io.cdap.cdap.proto.MetricQueryResult) Test(org.junit.Test)

Example 2 with MetricQueryResult

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);
    }
}
Also used : MetricQueryResult(io.cdap.cdap.proto.MetricQueryResult)

Example 3 with MetricQueryResult

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());
}
Also used : MetricQueryResult(io.cdap.cdap.proto.MetricQueryResult)

Example 4 with MetricQueryResult

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());
    }
}
Also used : MetricQueryResult(io.cdap.cdap.proto.MetricQueryResult)

Example 5 with MetricQueryResult

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);
    }
}
Also used : FakeApp(io.cdap.cdap.client.app.FakeApp) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) MetricTagValue(io.cdap.cdap.proto.MetricTagValue) HttpResponse(io.cdap.common.http.HttpResponse) MetricQueryResult(io.cdap.cdap.proto.MetricQueryResult) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) URL(java.net.URL) ServiceId(io.cdap.cdap.proto.id.ServiceId) Test(org.junit.Test)

Aggregations

MetricQueryResult (io.cdap.cdap.proto.MetricQueryResult)16 Test (org.junit.Test)4 TypeToken (com.google.gson.reflect.TypeToken)3 HttpResponse (io.cdap.common.http.HttpResponse)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 TimeValue (io.cdap.cdap.api.dataset.lib.cube.TimeValue)2 MetricDeleteQuery (io.cdap.cdap.api.metrics.MetricDeleteQuery)2 MetricTimeSeries (io.cdap.cdap.api.metrics.MetricTimeSeries)2 MetricsSystemClient (io.cdap.cdap.api.metrics.MetricsSystemClient)2 RandomEndpointStrategy (io.cdap.cdap.common.discovery.RandomEndpointStrategy)2 DefaultHttpRequestConfig (io.cdap.cdap.common.http.DefaultHttpRequestConfig)2 HttpRequest (io.cdap.common.http.HttpRequest)2 IOException (java.io.IOException)2 Map (java.util.Map)2 Joiner (com.google.common.base.Joiner)1 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)1 Gson (com.google.gson.Gson)1 Inject (com.google.inject.Inject)1