use of io.cdap.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);
}
use of io.cdap.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");
}
MetricQueryRequest.TimeRange timeRange = queryRequest.getTimeRange();
AggregationOption aggregation = timeRange.getAggregation();
if (timeRange.getCount() <= 0) {
throw new IllegalArgumentException("Invalid metrics aggregation request, the limit must be greater than 0");
}
Map<String, String> tagsSliceBy = humanToTagNames(transformTagMap(queryRequest.getTags()));
MetricDataQuery query = new MetricDataQuery(timeRange.getStart(), timeRange.getEnd(), timeRange.getResolutionInSeconds(), timeRange.getCount(), toMetrics(queryRequest.getMetrics()), tagsSliceBy, transformGroupByTags(queryRequest.getGroupBy()), aggregation, 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 io.cdap.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 io.cdap.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;
}
Aggregations