Search in sources :

Example 1 with ThirdEyeRequest

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

the class PinotThirdEyeSummaryClient method constructAggregatedValues.

/**
   * @throws Exception Throws exceptions when no useful data is retrieved, i.e., time out, failed to connect
   * to the backend database, no non-zero data returned from the database, etc.
   */
private List<List<Row>> constructAggregatedValues(Dimensions dimensions, List<ThirdEyeRequest> bulkRequests) throws Exception {
    Map<ThirdEyeRequest, Future<ThirdEyeResponse>> queryResponses = queryCache.getQueryResultsAsync(bulkRequests);
    List<List<Row>> res = new ArrayList<>();
    for (int i = 0; i < bulkRequests.size(); ) {
        ThirdEyeRequest baselineRequest = bulkRequests.get(i++);
        ThirdEyeRequest currentRequest = bulkRequests.get(i++);
        ThirdEyeResponse baselineResponses = queryResponses.get(baselineRequest).get(TIME_OUT_VALUE, TIME_OUT_UNIT);
        ThirdEyeResponse currentResponses = queryResponses.get(currentRequest).get(TIME_OUT_VALUE, TIME_OUT_UNIT);
        if (baselineResponses.getNumRows() == 0 || currentResponses.getNumRows() == 0) {
            throw new Exception("Failed to retrieve results with this request: " + (baselineResponses.getNumRows() == 0 ? baselineRequest : currentRequest));
        }
        Map<List<String>, Row> rowTable = new HashMap<>();
        buildMetricFunctionOrExpressionsRows(dimensions, baselineResponses, rowTable, true);
        buildMetricFunctionOrExpressionsRows(dimensions, currentResponses, rowTable, false);
        if (rowTable.size() == 0) {
            throw new Exception("Failed to retrieve non-zero results with these requests: " + baselineRequest + ", " + currentRequest);
        }
        List<Row> rows = new ArrayList<>(rowTable.values());
        res.add(rows);
    }
    return res;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ThirdEyeResponse(com.linkedin.thirdeye.client.ThirdEyeResponse) IOException(java.io.IOException) ThirdEyeRequest(com.linkedin.thirdeye.client.ThirdEyeRequest) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with ThirdEyeRequest

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

the class QueryCache method getQueryResultsAsyncAndWait.

public Map<ThirdEyeRequest, ThirdEyeResponse> getQueryResultsAsyncAndWait(final List<ThirdEyeRequest> requests, int timeoutSeconds) throws Exception {
    Map<ThirdEyeRequest, ThirdEyeResponse> responseMap = new LinkedHashMap<>();
    for (final ThirdEyeRequest request : requests) {
        Future<ThirdEyeResponse> responseFuture = executorService.submit(new Callable<ThirdEyeResponse>() {

            @Override
            public ThirdEyeResponse call() throws Exception {
                return getQueryResult(request);
            }
        });
        responseMap.put(request, responseFuture.get(timeoutSeconds, TimeUnit.SECONDS));
    }
    return responseMap;
}
Also used : ThirdEyeResponse(com.linkedin.thirdeye.client.ThirdEyeResponse) LinkedHashMap(java.util.LinkedHashMap) ThirdEyeRequest(com.linkedin.thirdeye.client.ThirdEyeRequest)

Example 3 with ThirdEyeRequest

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

the class QueryCache method getQueryResultsAsync.

public Map<ThirdEyeRequest, Future<ThirdEyeResponse>> getQueryResultsAsync(final List<ThirdEyeRequest> requests) throws Exception {
    Map<ThirdEyeRequest, Future<ThirdEyeResponse>> responseFuturesMap = new LinkedHashMap<>();
    for (final ThirdEyeRequest request : requests) {
        Future<ThirdEyeResponse> responseFuture = executorService.submit(new Callable<ThirdEyeResponse>() {

            @Override
            public ThirdEyeResponse call() throws Exception {
                return getQueryResult(request);
            }
        });
        responseFuturesMap.put(request, responseFuture);
    }
    return responseFuturesMap;
}
Also used : Future(java.util.concurrent.Future) ThirdEyeResponse(com.linkedin.thirdeye.client.ThirdEyeResponse) LinkedHashMap(java.util.LinkedHashMap) ThirdEyeRequest(com.linkedin.thirdeye.client.ThirdEyeRequest)

Example 4 with ThirdEyeRequest

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

the class ThirdEyeRequestGenerator method generateRequestsForGroupByDimensions.

public static List<ThirdEyeRequest> generateRequestsForGroupByDimensions(TimeOnTimeComparisonRequest comparisonRequest) {
    List<ThirdEyeRequest> requests = new ArrayList<>();
    ThirdEyeRequest baselineALLRequest = generateRequest(ALL_BASELINE, comparisonRequest, comparisonRequest.getBaselineStart(), comparisonRequest.getBaselineEnd(), null, null);
    requests.add(baselineALLRequest);
    ThirdEyeRequest currentALLRequest = generateRequest(ALL_CURRENT, comparisonRequest, comparisonRequest.getCurrentStart(), comparisonRequest.getCurrentEnd(), null, null);
    requests.add(currentALLRequest);
    for (String dimension : comparisonRequest.getGroupByDimensions()) {
        ThirdEyeRequest baselineDimensionRequest = generateRequest(DIMENSION_BASELINE + dimension, comparisonRequest, comparisonRequest.getBaselineStart(), comparisonRequest.getBaselineEnd(), dimension, null);
        requests.add(baselineDimensionRequest);
        ThirdEyeRequest currentDimensionRequest = generateRequest(DIMENSION_CURRENT + dimension, comparisonRequest, comparisonRequest.getCurrentStart(), comparisonRequest.getCurrentEnd(), dimension, null);
        requests.add(currentDimensionRequest);
    }
    return requests;
}
Also used : ArrayList(java.util.ArrayList) ThirdEyeRequest(com.linkedin.thirdeye.client.ThirdEyeRequest)

Example 5 with ThirdEyeRequest

use of com.linkedin.thirdeye.client.ThirdEyeRequest 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)

Aggregations

ThirdEyeRequest (com.linkedin.thirdeye.client.ThirdEyeRequest)14 ArrayList (java.util.ArrayList)8 ThirdEyeResponse (com.linkedin.thirdeye.client.ThirdEyeResponse)7 ThirdEyeRequestBuilder (com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder)5 Future (java.util.concurrent.Future)4 DateTime (org.joda.time.DateTime)4 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)3 MetricFunction (com.linkedin.thirdeye.client.MetricFunction)3 Range (com.google.common.collect.Range)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 ResultSet (com.linkedin.pinot.client.ResultSet)1 ResultSetGroup (com.linkedin.pinot.client.ResultSetGroup)1 ThirdEyeAnomalyConfiguration (com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration)1 MonitorConfiguration (com.linkedin.thirdeye.anomaly.monitor.MonitorConfiguration)1 MetricExpression (com.linkedin.thirdeye.client.MetricExpression)1 ThirdEyeClient (com.linkedin.thirdeye.client.ThirdEyeClient)1 MetricDataset (com.linkedin.thirdeye.client.cache.MetricDataset)1 QueryCache (com.linkedin.thirdeye.client.cache.QueryCache)1