use of co.cask.cdap.proto.MetricQueryResult in project cdap by caskdata.
the class MetricsHandlerTestRun 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 co.cask.cdap.proto.MetricQueryResult in project cdap by caskdata.
the class MetricsHandlerTestRun 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(ImmutableMap.copyOf(timeSeries.getGrouping()))) {
assertTimeValues(expectedTs, timeSeries);
timeSeriesMatchFound = true;
}
}
Assert.assertTrue(timeSeriesMatchFound);
}
}
use of co.cask.cdap.proto.MetricQueryResult in project cdap by caskdata.
the class MetricsQueryHelper method executeBatchQueries.
public Map<String, MetricQueryResult> executeBatchQueries(Map<String, QueryRequestFormat> queries) throws Exception {
LOG.trace("Received Queries {}", queries);
Map<String, MetricQueryResult> queryFinalResponse = Maps.newHashMap();
for (Map.Entry<String, QueryRequestFormat> query : queries.entrySet()) {
MetricQueryRequest queryRequest = getQueryRequestFromFormat(query.getValue());
queryFinalResponse.put(query.getKey(), executeQuery(queryRequest));
}
return queryFinalResponse;
}
use of co.cask.cdap.proto.MetricQueryResult in project cdap by caskdata.
the class MetricsClient method getTotalCounter.
private long getTotalCounter(Map<String, String> tags, String metricName) {
try {
MetricQueryResult result = query(tags, metricName);
if (result.getSeries().length == 0) {
return 0;
}
MetricQueryResult.TimeValue[] timeValues = result.getSeries()[0].getData();
if (timeValues.length == 0) {
return 0;
}
// since it is totals, we know there's one value only
return timeValues[0].getValue();
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of co.cask.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);
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);
}
}
Aggregations