use of com.linkedin.thirdeye.client.cache.QueryCache in project pinot by linkedin.
the class ThirdEyeCacheRegistry method initCaches.
private static void initCaches(ThirdEyeConfiguration config) {
ThirdEyeCacheRegistry cacheRegistry = ThirdEyeCacheRegistry.getInstance();
RemovalListener<PinotQuery, ResultSetGroup> listener = new RemovalListener<PinotQuery, ResultSetGroup>() {
@Override
public void onRemoval(RemovalNotification<PinotQuery, ResultSetGroup> notification) {
LOGGER.info("Expired {}", notification.getKey().getPql());
}
};
// ResultSetGroup Cache. The size of this cache is limited by the total number of buckets in all ResultSetGroup.
// We estimate that 1 bucket (including overhead) consumes 1KB and this cache is allowed to use up to 50% of max
// heap space.
long maxBucketNumber = getApproximateMaxBucketNumber(DEFAULT_HEAP_PERCENTAGE_FOR_RESULTSETGROUP_CACHE);
LoadingCache<PinotQuery, ResultSetGroup> resultSetGroupCache = CacheBuilder.newBuilder().removalListener(listener).expireAfterAccess(1, TimeUnit.HOURS).maximumWeight(maxBucketNumber).weigher((pinotQuery, resultSetGroup) -> {
int resultSetCount = resultSetGroup.getResultSetCount();
int weight = 0;
for (int idx = 0; idx < resultSetCount; ++idx) {
com.linkedin.pinot.client.ResultSet resultSet = resultSetGroup.getResultSet(idx);
weight += (resultSet.getColumnCount() * resultSet.getRowCount());
}
return weight;
}).build(new ResultSetGroupCacheLoader(pinotThirdeyeClientConfig));
cacheRegistry.registerResultSetGroupCache(resultSetGroupCache);
LOGGER.info("Max bucket number for ResultSetGroup cache is set to {}", maxBucketNumber);
// CollectionMaxDataTime Cache
LoadingCache<String, Long> collectionMaxDataTimeCache = CacheBuilder.newBuilder().refreshAfterWrite(5, TimeUnit.MINUTES).build(new CollectionMaxDataTimeCacheLoader(resultSetGroupCache, datasetConfigDAO));
cacheRegistry.registerCollectionMaxDataTimeCache(collectionMaxDataTimeCache);
// Query Cache
QueryCache queryCache = new QueryCache(thirdEyeClient, Executors.newFixedThreadPool(10));
cacheRegistry.registerQueryCache(queryCache);
// Dimension Filter cache
LoadingCache<String, String> dimensionFiltersCache = CacheBuilder.newBuilder().build(new DimensionFiltersCacheLoader(cacheRegistry.getQueryCache()));
cacheRegistry.registerDimensionFiltersCache(dimensionFiltersCache);
// Dashboards cache
LoadingCache<String, String> dashboardsCache = CacheBuilder.newBuilder().build(new DashboardsCacheLoader(dashboardConfigDAO));
cacheRegistry.registerDashboardsCache(dashboardsCache);
// Collections cache
CollectionsCache collectionsCache = new CollectionsCache(datasetConfigDAO, config);
cacheRegistry.registerCollectionsCache(collectionsCache);
// DatasetConfig cache
LoadingCache<String, DatasetConfigDTO> datasetConfigCache = CacheBuilder.newBuilder().build(new DatasetConfigCacheLoader(datasetConfigDAO));
cacheRegistry.registerDatasetConfigCache(datasetConfigCache);
// MetricConfig cache
LoadingCache<MetricDataset, MetricConfigDTO> metricConfigCache = CacheBuilder.newBuilder().build(new MetricConfigCacheLoader(metricConfigDAO));
cacheRegistry.registerMetricConfigCache(metricConfigCache);
// DashboardConfigs cache
LoadingCache<String, List<DashboardConfigDTO>> dashboardConfigsCache = CacheBuilder.newBuilder().build(new DashboardConfigCacheLoader(dashboardConfigDAO));
cacheRegistry.registerDashboardConfigsCache(dashboardConfigsCache);
}
use of com.linkedin.thirdeye.client.cache.QueryCache in project pinot by linkedin.
the class TimeSeriesTest method main.
public static void main(String[] args) throws Exception {
// = System.class.get.getResource("log4j.properties");
URL resource = null;
if (resource == null) {
resource = TimeSeriesHandler.class.getClassLoader().getResource("logback.x");
}
// TODO
PinotThirdEyeClient pinotThirdEyeClient = PinotThirdEyeClient.getDefaultTestClient();
// make
// this
// configurable
QueryCache queryCache = new QueryCache(pinotThirdEyeClient, Executors.newFixedThreadPool(10));
TimeSeriesRequest[] requests = new TimeSeriesRequest[] { generateGroupByTimeRequest() };
for (TimeSeriesRequest timeSeriesRequest : requests) {
try {
TimeSeriesHandler handler = new TimeSeriesHandler(queryCache);
long start = System.currentTimeMillis();
TimeSeriesResponse response = handler.handle(timeSeriesRequest);
long end = System.currentTimeMillis();
System.out.println("Time taken:" + (end - start));
for (TimeSeriesMetric metric : response.getRow(0).getMetrics()) {
System.out.print(metric.getMetricName() + "\t\t");
}
System.out.println();
for (int i = 0; i < response.getNumRows(); i++) {
System.out.println(response.getRow(i));
}
} catch (Exception e) {
System.out.println("Request failed: " + timeSeriesRequest);
e.printStackTrace();
System.exit(-1);
}
}
System.out.println("No exceptions encountered during testing... but you still need to check for data quality!");
System.exit(0);
}
use of com.linkedin.thirdeye.client.cache.QueryCache in project pinot by linkedin.
the class ContributorTest method main.
public static void main(String[] args) throws Exception {
ContributorViewRequest request = new ContributorViewRequest();
String collection = "thirdeyeAbook";
DateTime baselineStart = new DateTime(2016, 3, 23, 00, 00);
List<MetricExpression> metricExpressions = new ArrayList<>();
metricExpressions.add(new MetricExpression("__COUNT", "__COUNT"));
request.setCollection(collection);
request.setBaselineStart(baselineStart);
request.setBaselineEnd(baselineStart.plusDays(1));
request.setCurrentStart(baselineStart.plusDays(7));
request.setCurrentEnd(baselineStart.plusDays(8));
request.setTimeGranularity(new TimeGranularity(1, TimeUnit.HOURS));
request.setMetricExpressions(metricExpressions);
// TODO
PinotThirdEyeClient pinotThirdEyeClient = PinotThirdEyeClient.getDefaultTestClient();
// make
// this
// configurable;
QueryCache queryCache = new QueryCache(pinotThirdEyeClient, Executors.newFixedThreadPool(10));
ContributorViewHandler handler = new ContributorViewHandler(queryCache);
ContributorViewResponse response = handler.process(request);
ObjectMapper mapper = new ObjectMapper();
String jsonResponse = mapper.writeValueAsString(response);
System.out.println(jsonResponse);
}
use of com.linkedin.thirdeye.client.cache.QueryCache in project pinot by linkedin.
the class HeatMapTest method main.
public static void main(String[] args) throws Exception {
HeatMapViewRequest request = new HeatMapViewRequest();
String collection = "thirdeyeAbook";
DateTime baselineStart = new DateTime(2016, 3, 23, 00, 00);
List<MetricExpression> metricExpressions = new ArrayList<>();
metricExpressions.add(new MetricExpression("__COUNT", "__COUNT"));
request.setCollection(collection);
request.setBaselineStart(baselineStart);
request.setBaselineEnd(baselineStart.plusHours(1));
request.setCurrentStart(baselineStart.plusDays(7));
request.setCurrentEnd(baselineStart.plusDays(7).plusHours(1));
request.setTimeGranularity(new TimeGranularity(1, TimeUnit.HOURS));
request.setMetricExpressions(metricExpressions);
// TODO
PinotThirdEyeClient pinotThirdEyeClient = PinotThirdEyeClient.getDefaultTestClient();
// make
// this
// configurable;
QueryCache queryCache = new QueryCache(pinotThirdEyeClient, Executors.newFixedThreadPool(10));
HeatMapViewHandler handler = new HeatMapViewHandler(queryCache);
HeatMapViewResponse response = handler.process(request);
ObjectMapper mapper = new ObjectMapper();
String jsonResponse = mapper.writeValueAsString(response);
System.out.println(jsonResponse);
}
use of com.linkedin.thirdeye.client.cache.QueryCache 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);
}
Aggregations