use of com.linkedin.thirdeye.client.ThirdEyeRequest 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;
}
use of com.linkedin.thirdeye.client.ThirdEyeRequest 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 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;
}
use of com.linkedin.thirdeye.client.ThirdEyeRequest in project pinot by linkedin.
the class AnomalyApplicationEndToEndTest method setup.
private void setup() throws Exception {
// Mock query cache
ThirdEyeClient mockThirdeyeClient = Mockito.mock(ThirdEyeClient.class);
Mockito.when(mockThirdeyeClient.execute(Matchers.any(ThirdEyeRequest.class))).thenAnswer(new Answer<ThirdEyeResponse>() {
@Override
public ThirdEyeResponse answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
ThirdEyeRequest request = (ThirdEyeRequest) args[0];
ThirdEyeResponse response = getMockResponse(request);
return response;
}
});
QueryCache mockQueryCache = new QueryCache(mockThirdeyeClient, Executors.newFixedThreadPool(10));
cacheRegistry.registerQueryCache(mockQueryCache);
MetricConfigDTO metricConfig = getTestMetricConfig(collection, metric, 1L);
// create metric config in cache
LoadingCache<MetricDataset, MetricConfigDTO> mockMetricConfigCache = Mockito.mock(LoadingCache.class);
Mockito.when(mockMetricConfigCache.get(new MetricDataset(metric, collection))).thenReturn(metricConfig);
cacheRegistry.registerMetricConfigCache(mockMetricConfigCache);
// create dataset config in cache
LoadingCache<String, DatasetConfigDTO> mockDatasetConfigCache = Mockito.mock(LoadingCache.class);
Mockito.when(mockDatasetConfigCache.get(collection)).thenReturn(getTestDatasetConfig(collection));
cacheRegistry.registerDatasetConfigCache(mockDatasetConfigCache);
ResultSet mockResultSet = Mockito.mock(ResultSet.class);
Mockito.when(mockResultSet.getRowCount()).thenReturn(0);
ResultSetGroup mockResultSetGroup = Mockito.mock(ResultSetGroup.class);
Mockito.when(mockResultSetGroup.getResultSet(0)).thenReturn(mockResultSet);
LoadingCache<PinotQuery, ResultSetGroup> mockResultSetGroupCache = Mockito.mock(LoadingCache.class);
Mockito.when(mockResultSetGroupCache.get(Matchers.any(PinotQuery.class))).thenAnswer(new Answer<ResultSetGroup>() {
@Override
public ResultSetGroup answer(InvocationOnMock invocation) throws Throwable {
return mockResultSetGroup;
}
});
cacheRegistry.registerResultSetGroupCache(mockResultSetGroupCache);
// Application config
thirdeyeAnomalyConfig = new ThirdEyeAnomalyConfiguration();
thirdeyeAnomalyConfig.setId(id);
thirdeyeAnomalyConfig.setDashboardHost(dashboardHost);
MonitorConfiguration monitorConfiguration = new MonitorConfiguration();
monitorConfiguration.setMonitorFrequency(new TimeGranularity(30, TimeUnit.SECONDS));
thirdeyeAnomalyConfig.setMonitorConfiguration(monitorConfiguration);
thirdeyeAnomalyConfig.setRootDir(System.getProperty("dw.rootDir", "NOT_SET(dw.rootDir)"));
// create test anomaly function
functionId = anomalyFunctionDAO.save(getTestFunctionSpec(metric, collection));
// create test email configuration
emailConfigurationDAO.save(getTestEmailConfiguration(metric, collection));
// create test alert configuration
alertConfigDAO.save(getTestAlertConfiguration("test alert v2"));
// create test dataset config
datasetConfigDAO.save(getTestDatasetConfig(collection));
// setup function factory for worker and merger
InputStream factoryStream = AnomalyApplicationEndToEndTest.class.getResourceAsStream(functionPropertiesFile);
anomalyFunctionFactory = new AnomalyFunctionFactory(factoryStream);
// setup alertfilter factory for worker
InputStream alertFilterStream = AnomalyApplicationEndToEndTest.class.getResourceAsStream(alertFilterPropertiesFile);
alertFilterFactory = new AlertFilterFactory(alertFilterStream);
}
use of com.linkedin.thirdeye.client.ThirdEyeRequest in project pinot by linkedin.
the class PinotThirdEyeSummaryClient method constructTimeOnTimeBulkRequests.
/**
* Returns the baseline and current requests for the given GroupBy dimensions.
*
* @param groupBy the dimensions to do GroupBy queries
* @return Baseline and Current requests.
*/
private List<ThirdEyeRequest> constructTimeOnTimeBulkRequests(List<String> groupBy) {
List<ThirdEyeRequest> requests = new ArrayList<>();
;
// baseline requests
ThirdEyeRequestBuilder builder = ThirdEyeRequest.newBuilder();
builder.setCollection(collection);
builder.setMetricFunctions(metricFunctions);
builder.setGroupBy(groupBy);
builder.setStartTimeInclusive(baselineStartInclusive);
builder.setEndTimeExclusive(baselineEndExclusive);
ThirdEyeRequest baselineRequest = builder.build("baseline");
requests.add(baselineRequest);
// current requests
builder = ThirdEyeRequest.newBuilder();
builder.setCollection(collection);
builder.setMetricFunctions(metricFunctions);
builder.setGroupBy(groupBy);
builder.setStartTimeInclusive(currentStartInclusive);
builder.setEndTimeExclusive(currentEndExclusive);
ThirdEyeRequest currentRequest = builder.build("current");
requests.add(currentRequest);
return requests;
}
Aggregations