Search in sources :

Example 1 with MetricQueryRequest

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);
}
Also used : MetricQueryRequest(io.cdap.cdap.proto.MetricQueryRequest)

Example 2 with MetricQueryRequest

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());
}
Also used : MetricTimeSeries(io.cdap.cdap.api.metrics.MetricTimeSeries) MetricDataQuery(io.cdap.cdap.api.metrics.MetricDataQuery) MetricQueryRequest(io.cdap.cdap.proto.MetricQueryRequest) AggregationOption(io.cdap.cdap.api.dataset.lib.cube.AggregationOption)

Example 3 with MetricQueryRequest

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;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) MetricQueryRequest(io.cdap.cdap.proto.MetricQueryRequest)

Example 4 with MetricQueryRequest

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;
}
Also used : MetricQueryResult(io.cdap.cdap.proto.MetricQueryResult) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) MetricQueryRequest(io.cdap.cdap.proto.MetricQueryRequest)

Aggregations

MetricQueryRequest (io.cdap.cdap.proto.MetricQueryRequest)4 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 ImmutableList (com.google.common.collect.ImmutableList)1 AggregationOption (io.cdap.cdap.api.dataset.lib.cube.AggregationOption)1 MetricDataQuery (io.cdap.cdap.api.metrics.MetricDataQuery)1 MetricTimeSeries (io.cdap.cdap.api.metrics.MetricTimeSeries)1 MetricQueryResult (io.cdap.cdap.proto.MetricQueryResult)1 List (java.util.List)1