use of co.cask.cdap.api.metrics.MetricDataQuery in project cdap by caskdata.
the class MetricQueryParserTest method testOverview.
@Test
public void testOverview() throws MetricsPathException {
MetricDataQuery query = MetricQueryParser.parse(URI.create("/system/reads?aggregate=true"));
Assert.assertTrue(query.getSliceByTags().isEmpty());
assertMetricName("system.reads", query);
}
use of co.cask.cdap.api.metrics.MetricDataQuery in project cdap by caskdata.
the class MetricQueryParserTest method testApps.
@Test
public void testApps() throws MetricsPathException {
MetricDataQuery query = MetricQueryParser.parse(URI.create("/system/apps/app1/reads?aggregate=true"));
verifyTags(query.getSliceByTags(), Id.Namespace.DEFAULT.getId(), Tag.APP, "app1");
assertMetricName("system.reads", query);
}
use of co.cask.cdap.api.metrics.MetricDataQuery in project cdap by caskdata.
the class MetricQueryParserTest method testRelativeTimeArgs.
@Test
public void testRelativeTimeArgs() throws MetricsPathException {
long now = TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
MetricDataQuery query = MetricQueryParser.parse(URI.create("/system/apps/app1/reads?count=61&end=now-5s"));
assertTimestamp(now - 5, query.getEndTs());
assertTimestamp(now - 65, query.getStartTs());
now = TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
query = MetricQueryParser.parse(URI.create("/system/apps/app1/reads?count=61&start=now-65s"));
assertTimestamp(now - 5, query.getEndTs());
assertTimestamp(now - 65, query.getStartTs());
now = TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
query = MetricQueryParser.parse(URI.create("/system/apps/app1/reads?count=61&start=now-1m"));
assertTimestamp(now, query.getEndTs());
assertTimestamp(now - 60, query.getStartTs());
now = TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
query = MetricQueryParser.parse(URI.create("/system/apps/app1/reads?count=61&start=now-1h"));
assertTimestamp(now - 3600 + 60, query.getEndTs());
assertTimestamp(now - 3600, query.getStartTs());
now = TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
query = MetricQueryParser.parse(URI.create("/system/apps/app1/reads?count=61&start=now-1d"));
assertTimestamp(now - 86400 + 60, query.getEndTs());
assertTimestamp(now - 86400, query.getStartTs());
now = TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
query = MetricQueryParser.parse(URI.create("/system/apps/app1/reads?count=61&start=now-1m&end=now"));
assertTimestamp(now, query.getEndTs());
assertTimestamp(now - 60, query.getStartTs());
now = TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
query = MetricQueryParser.parse(URI.create("/system/apps/app1/reads?count=61&start=now-2m%2B20s"));
assertTimestamp(now - 40, query.getEndTs());
assertTimestamp(now - 100, query.getStartTs());
}
use of co.cask.cdap.api.metrics.MetricDataQuery in project cdap by caskdata.
the class MetricQueryParser method parseDelete.
static MetricDeleteQuery parseDelete(URI requestURI, String metricPrefix) throws MetricsPathException {
MetricDataQueryBuilder builder = new MetricDataQueryBuilder();
parseContext(requestURI.getPath(), builder);
builder.setStartTs(0);
builder.setEndTs(Integer.MAX_VALUE - 1);
builder.setMetricName(metricPrefix);
MetricDataQuery query = builder.build();
return new MetricDeleteQuery(query.getStartTs(), query.getEndTs(), query.getMetrics().keySet(), query.getSliceByTags());
}
use of co.cask.cdap.api.metrics.MetricDataQuery in project cdap by caskdata.
the class MetricsQueryHelper method executeQuery.
private MetricQueryResult executeQuery(MetricQueryRequest queryRequest) throws Exception {
if (queryRequest.getMetrics().size() == 0) {
throw new IllegalArgumentException("Missing metrics parameter in the query");
}
Map<String, String> tagsSliceBy = humanToTagNames(transformTagMap(queryRequest.getTags()));
MetricQueryRequest.TimeRange timeRange = queryRequest.getTimeRange();
MetricDataQuery query = new MetricDataQuery(timeRange.getStart(), timeRange.getEnd(), timeRange.getResolutionInSeconds(), timeRange.getCount(), toMetrics(queryRequest.getMetrics()), tagsSliceBy, transformGroupByTags(queryRequest.getGroupBy()), timeRange.getInterpolate());
Collection<MetricTimeSeries> queryResult = metricStore.query(query);
long endTime = timeRange.getEnd();
if (timeRange.getResolutionInSeconds() == Integer.MAX_VALUE && endTime == 0) {
// for aggregate query, we set the end time to be query time (current time)
endTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis());
}
return decorate(queryResult, timeRange.getStart(), endTime, timeRange.getResolutionInSeconds());
}
Aggregations