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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations