Search in sources :

Example 1 with MetricTagValue

use of io.cdap.cdap.proto.MetricTagValue 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)

Example 2 with MetricTagValue

use of io.cdap.cdap.proto.MetricTagValue in project cdap by caskdata.

the class MetricsQueryHelper method humanToTagNames.

private List<MetricTagValue> humanToTagNames(List<MetricTagValue> tagValues) {
    List<MetricTagValue> result = Lists.newArrayList();
    for (MetricTagValue tagValue : tagValues) {
        String tagName = humanToTagName(tagValue.getName());
        result.add(new MetricTagValue(tagName, tagValue.getValue()));
    }
    return result;
}
Also used : MetricTagValue(io.cdap.cdap.proto.MetricTagValue)

Example 3 with MetricTagValue

use of io.cdap.cdap.proto.MetricTagValue in project cdap by caskdata.

the class MetricsQueryHelper method parseTagValuesAsMap.

private Map<String, String> parseTagValuesAsMap(List<String> tags) {
    List<MetricTagValue> tagValues = parseTagValues(tags);
    Map<String, String> result = Maps.newHashMap();
    for (MetricTagValue tagValue : tagValues) {
        result.put(tagValue.getName(), tagValue.getValue());
    }
    return result;
}
Also used : MetricTagValue(io.cdap.cdap.proto.MetricTagValue)

Example 4 with MetricTagValue

use of io.cdap.cdap.proto.MetricTagValue in project cdap by caskdata.

the class MetricsQueryHelper method parseTagValues.

private List<MetricTagValue> parseTagValues(List<String> tags) {
    List<MetricTagValue> result = Lists.newArrayList();
    for (String tag : tags) {
        // split by ':' and add the tagValue to result list
        String[] tagSplit = tag.split(":", 2);
        if (tagSplit.length == 2) {
            String value = tagSplit[1].equals(ANY_TAG_VALUE) ? null : tagSplit[1];
            result.add(new MetricTagValue(tagSplit[0], value));
        }
    }
    return result;
}
Also used : MetricTagValue(io.cdap.cdap.proto.MetricTagValue)

Example 5 with MetricTagValue

use of io.cdap.cdap.proto.MetricTagValue in project cdap by caskdata.

the class MetricsQueryHelper method tagValuesToHuman.

private List<MetricTagValue> tagValuesToHuman(Collection<TagValue> tagValues) {
    List<MetricTagValue> result = Lists.newArrayList();
    for (TagValue tagValue : tagValues) {
        String human = tagNameToHuman.get(tagValue.getName());
        human = human != null ? human : tagValue.getName();
        String value = tagValue.getValue() == null ? ANY_TAG_VALUE : tagValue.getValue();
        result.add(new MetricTagValue(human, value));
    }
    return result;
}
Also used : MetricTagValue(io.cdap.cdap.proto.MetricTagValue) MetricTagValue(io.cdap.cdap.proto.MetricTagValue) TagValue(io.cdap.cdap.api.metrics.TagValue)

Aggregations

MetricTagValue (io.cdap.cdap.proto.MetricTagValue)7 HttpResponse (io.cdap.common.http.HttpResponse)2 URL (java.net.URL)2 ImmutableList (com.google.common.collect.ImmutableList)1 TypeToken (com.google.common.reflect.TypeToken)1 TagValue (io.cdap.cdap.api.metrics.TagValue)1 FakeApp (io.cdap.cdap.client.app.FakeApp)1 DefaultHttpRequestConfig (io.cdap.cdap.common.http.DefaultHttpRequestConfig)1 MetricQueryResult (io.cdap.cdap.proto.MetricQueryResult)1 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)1 ServiceId (io.cdap.cdap.proto.id.ServiceId)1 HttpRequest (io.cdap.common.http.HttpRequest)1 List (java.util.List)1 Test (org.junit.Test)1