use of co.cask.cdap.proto.MetricQueryRequest 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.MetricQueryRequest in project cdap by caskdata.
the class MetricsQueryHelper method getQueryRequestFromFormat.
private MetricQueryRequest getQueryRequestFromFormat(QueryRequestFormat queryRequestFormat) {
Map<String, List<String>> queryParams = Maps.newHashMap();
for (Map.Entry<String, String> entry : queryRequestFormat.getTimeRange().entrySet()) {
queryParams.put(entry.getKey(), ImmutableList.of(entry.getValue()));
}
MetricQueryRequest queryRequest = new MetricQueryRequest(queryRequestFormat.getTags(), queryRequestFormat.getMetrics(), queryRequestFormat.getGroupBy());
setTimeRangeInQueryRequest(queryRequest, queryParams);
return queryRequest;
}
use of co.cask.cdap.proto.MetricQueryRequest 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());
}
use of co.cask.cdap.proto.MetricQueryRequest in project cdap by caskdata.
the class MetricsQueryHelper method executeTagQuery.
public MetricQueryResult executeTagQuery(List<String> tags, List<String> metrics, List<String> groupByTags, Map<String, List<String>> queryTimeParams) throws Exception {
MetricQueryRequest queryRequest = new MetricQueryRequest(parseTagValuesAsMap(tags), metrics, groupByTags);
setTimeRangeInQueryRequest(queryRequest, queryTimeParams);
return executeQuery(queryRequest);
}
Aggregations