Search in sources :

Example 1 with ThirdEyeRequestBuilder

use of com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder in project pinot by linkedin.

the class TimeOnTimeComparisonHandler method handle.

public TimeOnTimeComparisonResponse handle(TimeOnTimeComparisonRequest comparisonRequest) throws Exception {
    ThirdEyeRequestBuilder builder = new ThirdEyeRequestBuilder();
    builder.setCollection(comparisonRequest.getCollectionName());
    List<Range<DateTime>> baselineTimeranges = new ArrayList<>();
    List<Range<DateTime>> currentTimeranges = new ArrayList<>();
    TimeGranularity aggregationTimeGranularity = comparisonRequest.getAggregationTimeGranularity();
    // baseline time ranges
    DateTime baselineStart = comparisonRequest.getBaselineStart();
    DateTime baselineEnd = comparisonRequest.getBaselineEnd();
    // current time ranges
    DateTime currentStart = comparisonRequest.getCurrentStart();
    DateTime currentEnd = comparisonRequest.getCurrentEnd();
    if (comparisonRequest.isEndDateInclusive()) {
        // ThirdEyeRequest is exclusive endpoint, so increment end by one bucket
        currentEnd = TimeRangeUtils.increment(currentEnd, aggregationTimeGranularity);
        baselineEnd = TimeRangeUtils.increment(baselineEnd, aggregationTimeGranularity);
    }
    baselineTimeranges = TimeRangeUtils.computeTimeRanges(aggregationTimeGranularity, baselineStart, baselineEnd);
    currentTimeranges = TimeRangeUtils.computeTimeRanges(aggregationTimeGranularity, currentStart, currentEnd);
    // create baseline request
    ThirdEyeRequest baselineRequest = createThirdEyeRequest(BASELINE, comparisonRequest, baselineStart, baselineEnd);
    // create current request
    ThirdEyeRequest currentRequest = createThirdEyeRequest(CURRENT, comparisonRequest, currentStart, currentEnd);
    List<ThirdEyeRequest> requests = new ArrayList<>();
    requests.add(baselineRequest);
    requests.add(currentRequest);
    Map<ThirdEyeRequest, Future<ThirdEyeResponse>> futureResponseMap;
    futureResponseMap = queryCache.getQueryResultsAsync(requests);
    ThirdEyeResponse baselineResponse = null;
    ThirdEyeResponse currentResponse = null;
    for (Entry<ThirdEyeRequest, Future<ThirdEyeResponse>> entry : futureResponseMap.entrySet()) {
        ThirdEyeRequest request = entry.getKey();
        Future<ThirdEyeResponse> responseFuture = entry.getValue();
        ThirdEyeResponse response = responseFuture.get(60000, TimeUnit.SECONDS);
        if (BASELINE.equals(request.getRequestReference())) {
            baselineResponse = response;
        } else if (CURRENT.equals(request.getRequestReference())) {
            currentResponse = response;
        }
    }
    TimeOnTimeResponseParser timeOnTimeResponseParser = new TimeOnTimeResponseParser(baselineResponse, currentResponse, baselineTimeranges, currentTimeranges, comparisonRequest.getAggregationTimeGranularity(), comparisonRequest.getGroupByDimensions());
    List<Row> rows = timeOnTimeResponseParser.parseResponse();
    // compute the derived metrics
    computeDerivedMetrics(comparisonRequest, rows);
    return new TimeOnTimeComparisonResponse(rows);
}
Also used : ThirdEyeRequestBuilder(com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder) ArrayList(java.util.ArrayList) ThirdEyeResponse(com.linkedin.thirdeye.client.ThirdEyeResponse) Range(com.google.common.collect.Range) DateTime(org.joda.time.DateTime) ThirdEyeRequest(com.linkedin.thirdeye.client.ThirdEyeRequest) TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) Future(java.util.concurrent.Future)

Example 2 with ThirdEyeRequestBuilder

use of com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder in project pinot by linkedin.

the class ResponseParserUtils method getMetricSums.

public static List<Double> getMetricSums(ThirdEyeResponse response) {
    ThirdEyeRequest request = response.getRequest();
    ThirdEyeRequestBuilder requestBuilder = ThirdEyeRequest.newBuilder();
    requestBuilder.setCollection(request.getCollection());
    requestBuilder.setStartTimeInclusive(request.getStartTimeInclusive());
    requestBuilder.setEndTimeExclusive(request.getEndTimeExclusive());
    requestBuilder.setFilterSet(request.getFilterSet());
    requestBuilder.setMetricFunctions(request.getMetricFunctions());
    ThirdEyeRequest metricSumsRequest = requestBuilder.build("metricSums");
    ThirdEyeResponse metricSumsResponse = null;
    try {
        metricSumsResponse = CACHE_REGISTRY_INSTANCE.getQueryCache().getQueryResult(metricSumsRequest);
    } catch (Exception e) {
        LOGGER.error("Caught exception when executing metric sums request", e);
    }
    List<Double> metricSums = metricSumsResponse.getRow(0).getMetrics();
    return metricSums;
}
Also used : ThirdEyeRequestBuilder(com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder)

Example 3 with ThirdEyeRequestBuilder

use of com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder in project pinot by linkedin.

the class ResponseParserUtils method getMetricSumsByTime.

public static Map<Integer, List<Double>> getMetricSumsByTime(ThirdEyeResponse response) {
    ThirdEyeRequest request = response.getRequest();
    Map<Integer, List<Double>> metricSums = new HashMap<>();
    ThirdEyeRequestBuilder requestBuilder = ThirdEyeRequest.newBuilder();
    requestBuilder.setCollection(request.getCollection());
    requestBuilder.setStartTimeInclusive(request.getStartTimeInclusive());
    requestBuilder.setEndTimeExclusive(request.getEndTimeExclusive());
    requestBuilder.setFilterSet(request.getFilterSet());
    requestBuilder.setGroupByTimeGranularity(request.getGroupByTimeGranularity());
    requestBuilder.setMetricFunctions(request.getMetricFunctions());
    ThirdEyeRequest metricSumsRequest = requestBuilder.build("metricSums");
    ThirdEyeResponse metricSumsResponse = null;
    try {
        metricSumsResponse = CACHE_REGISTRY_INSTANCE.getQueryCache().getQueryResult(metricSumsRequest);
    } catch (Exception e) {
        LOGGER.error("Caught exception when executing metric sums request", e);
    }
    for (int i = 0; i < metricSumsResponse.getNumRows(); i++) {
        ThirdEyeResponseRow row = metricSumsResponse.getRow(i);
        metricSums.put(row.getTimeBucketId(), row.getMetrics());
    }
    return metricSums;
}
Also used : ThirdEyeRequestBuilder(com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with ThirdEyeRequestBuilder

use of com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder in project pinot by linkedin.

the class Utils method generateRequests.

public static List<ThirdEyeRequest> generateRequests(String collection, String requestReference, MetricFunction metricFunction, List<String> dimensions, DateTime start, DateTime end) {
    List<ThirdEyeRequest> requests = new ArrayList<>();
    for (String dimension : dimensions) {
        ThirdEyeRequestBuilder requestBuilder = new ThirdEyeRequestBuilder();
        requestBuilder.setCollection(collection);
        List<MetricFunction> metricFunctions = Arrays.asList(metricFunction);
        requestBuilder.setMetricFunctions(metricFunctions);
        requestBuilder.setStartTimeInclusive(start);
        requestBuilder.setEndTimeExclusive(end);
        requestBuilder.setGroupBy(dimension);
        ThirdEyeRequest request = requestBuilder.build(requestReference);
        requests.add(request);
    }
    return requests;
}
Also used : ThirdEyeRequestBuilder(com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder) MetricFunction(com.linkedin.thirdeye.client.MetricFunction) ArrayList(java.util.ArrayList) ThirdEyeRequest(com.linkedin.thirdeye.client.ThirdEyeRequest)

Example 5 with ThirdEyeRequestBuilder

use of com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder in project pinot by linkedin.

the class SeverityComputationUtil method createThirdEyeRequest.

private ThirdEyeRequest createThirdEyeRequest(long currentWindowStart, long currentWindowEnd) throws ExecutionException {
    ThirdEyeRequestBuilder requestBuilder = ThirdEyeRequest.newBuilder();
    requestBuilder.setCollection(collectionName);
    requestBuilder.setStartTimeInclusive(new DateTime(currentWindowStart));
    requestBuilder.setEndTimeExclusive(new DateTime(currentWindowEnd));
    // requestBuilder.setFilterSet(comparisonRequest.getFilterSet());
    // requestBuilder.addGroupBy(comparisonRequest.getGroupByDimensions());
    requestBuilder.setGroupByTimeGranularity(null);
    List<MetricExpression> metricExpressions = Utils.convertToMetricExpressions(metricName, MetricAggFunction.SUM, collectionName);
    requestBuilder.setMetricFunctions(metricExpressions.get(0).computeMetricFunctions());
    ThirdEyeRequest thirdEyeRequest = requestBuilder.build("test-" + System.currentTimeMillis());
    return thirdEyeRequest;
}
Also used : ThirdEyeRequestBuilder(com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder) MetricExpression(com.linkedin.thirdeye.client.MetricExpression) DateTime(org.joda.time.DateTime) ThirdEyeRequest(com.linkedin.thirdeye.client.ThirdEyeRequest)

Aggregations

ThirdEyeRequestBuilder (com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder)9 ThirdEyeRequest (com.linkedin.thirdeye.client.ThirdEyeRequest)5 MetricFunction (com.linkedin.thirdeye.client.MetricFunction)4 ArrayList (java.util.ArrayList)4 MetricExpression (com.linkedin.thirdeye.client.MetricExpression)3 DateTime (org.joda.time.DateTime)2 Range (com.google.common.collect.Range)1 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)1 ThirdEyeResponse (com.linkedin.thirdeye.client.ThirdEyeResponse)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Future (java.util.concurrent.Future)1