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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations