Search in sources :

Example 1 with MetricQueryRequest

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

Example 2 with MetricQueryRequest

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;
}
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(co.cask.cdap.proto.MetricQueryRequest)

Example 3 with MetricQueryRequest

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());
}
Also used : MetricTimeSeries(co.cask.cdap.api.metrics.MetricTimeSeries) MetricDataQuery(co.cask.cdap.api.metrics.MetricDataQuery) MetricQueryRequest(co.cask.cdap.proto.MetricQueryRequest)

Example 4 with MetricQueryRequest

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

Aggregations

MetricQueryRequest (co.cask.cdap.proto.MetricQueryRequest)4 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 MetricDataQuery (co.cask.cdap.api.metrics.MetricDataQuery)1 MetricTimeSeries (co.cask.cdap.api.metrics.MetricTimeSeries)1 MetricQueryResult (co.cask.cdap.proto.MetricQueryResult)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1