use of co.cask.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;
}
use of co.cask.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 co.cask.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);
ProgramId flow = app.flow(FakeFlow.NAME);
StreamId stream = NamespaceId.DEFAULT.stream(FakeApp.STREAM_NAME);
try {
programClient.start(flow);
streamClient.sendEvent(stream, "hello world");
// TODO: remove arbitrary sleep
TimeUnit.SECONDS.sleep(5);
FlowletId flowletId = flow.flowlet(FakeFlow.FLOWLET_NAME);
MetricQueryResult result = metricsClient.query(MetricsTags.flowlet(flowletId), Constants.Metrics.Name.Flow.FLOWLET_INPUT);
Assert.assertEquals(1, result.getSeries()[0].getData()[0].getValue());
result = metricsClient.query(MetricsTags.flowlet(flowletId), ImmutableList.of(Constants.Metrics.Name.Flow.FLOWLET_INPUT), ImmutableList.<String>of(), ImmutableMap.of("aggregate", "true"));
Assert.assertEquals(1, result.getSeries()[0].getData()[0].getValue());
result = metricsClient.query(MetricsTags.flowlet(flowletId), ImmutableList.of(Constants.Metrics.Name.Flow.FLOWLET_INPUT), ImmutableList.<String>of(), ImmutableMap.of("start", "now-20s", "end", "now"));
Assert.assertEquals(1, result.getSeries()[0].getData()[0].getValue());
List<MetricTagValue> tags = metricsClient.searchTags(MetricsTags.flowlet(flowletId));
Assert.assertEquals(1, tags.size());
Assert.assertEquals("run", tags.get(0).getName());
List<String> metrics = metricsClient.searchMetrics(MetricsTags.flowlet(flowletId));
Assert.assertTrue(metrics.contains(Constants.Metrics.Name.Flow.FLOWLET_INPUT));
} finally {
programClient.stop(flow);
assertProgramRuns(programClient, flow, ProgramRunStatus.KILLED, 1, 10);
appClient.delete(app);
}
}
use of co.cask.cdap.proto.MetricTagValue in project cdap by caskdata.
the class SearchMetricTagsCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
Map<String, String> tags = ArgumentParser.parseMap(arguments.getOptional("tags", ""), "<tags>");
List<MetricTagValue> results = client.searchTags(tags);
for (MetricTagValue result : results) {
output.printf("%s=%s\n", result.getName(), result.getValue());
}
}
use of co.cask.cdap.proto.MetricTagValue in project cdap by caskdata.
the class MetricsClient method searchTags.
/**
* Searches for metrics tags matching the given tags.
*
* @param tags the tags to match
* @return the metrics matching the given tags
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<MetricTagValue> searchTags(Map<String, String> tags) throws IOException, UnauthenticatedException, UnauthorizedException {
List<String> queryParts = Lists.newArrayList();
queryParts.add("target=tag");
addTags(tags, queryParts);
URL url = config.resolveURLV3(String.format("metrics/search?%s", Joiner.on("&").join(queryParts)));
HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken());
ObjectResponse<List<MetricTagValue>> result = ObjectResponse.fromJsonBody(response, new TypeToken<List<MetricTagValue>>() {
}.getType());
return result.getResponseObject();
}
Aggregations