Search in sources :

Example 1 with ThirdEyeResponse

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

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

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

use of com.linkedin.thirdeye.client.ThirdEyeResponse 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 5 with ThirdEyeResponse

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

the class Utils method getFilters.

public static Map<String, List<String>> getFilters(QueryCache queryCache, String collection, String requestReference, List<String> dimensions, DateTime start, DateTime end) throws Exception {
    MetricFunction metricFunction = new MetricFunction(MetricAggFunction.COUNT, "*");
    List<ThirdEyeRequest> requests = generateRequests(collection, requestReference, metricFunction, dimensions, start, end);
    Map<ThirdEyeRequest, Future<ThirdEyeResponse>> queryResultMap = queryCache.getQueryResultsAsync(requests);
    Map<String, List<String>> result = new HashMap<>();
    for (Map.Entry<ThirdEyeRequest, Future<ThirdEyeResponse>> entry : queryResultMap.entrySet()) {
        ThirdEyeRequest request = entry.getKey();
        String dimension = request.getGroupBy().get(0);
        ThirdEyeResponse thirdEyeResponse = entry.getValue().get();
        int n = thirdEyeResponse.getNumRowsFor(metricFunction);
        List<String> values = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            Map<String, String> row = thirdEyeResponse.getRow(metricFunction, i);
            String dimensionValue = row.get(dimension);
            values.add(dimensionValue);
        }
        result.put(dimension, values);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ThirdEyeResponse(com.linkedin.thirdeye.client.ThirdEyeResponse) ThirdEyeRequest(com.linkedin.thirdeye.client.ThirdEyeRequest) MetricFunction(com.linkedin.thirdeye.client.MetricFunction) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ThirdEyeResponse (com.linkedin.thirdeye.client.ThirdEyeResponse)9 ThirdEyeRequest (com.linkedin.thirdeye.client.ThirdEyeRequest)7 ArrayList (java.util.ArrayList)5 Future (java.util.concurrent.Future)4 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)3 DateTime (org.joda.time.DateTime)3 Range (com.google.common.collect.Range)2 PinotThirdEyeResponse (com.linkedin.thirdeye.client.pinot.PinotThirdEyeResponse)2 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)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 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)1 MetricFunction (com.linkedin.thirdeye.client.MetricFunction)1 ThirdEyeClient (com.linkedin.thirdeye.client.ThirdEyeClient)1 ThirdEyeRequestBuilder (com.linkedin.thirdeye.client.ThirdEyeRequest.ThirdEyeRequestBuilder)1