Search in sources :

Example 1 with AnomalyFunctionFactory

use of com.linkedin.thirdeye.detector.function.AnomalyFunctionFactory in project pinot by linkedin.

the class ThirdEyeAnomalyApplication method run.

@Override
public void run(final ThirdEyeAnomalyConfiguration config, final Environment environment) throws Exception {
    LOG.info("Starting ThirdeyeAnomalyApplication : Scheduler {} Worker {}", config.isScheduler(), config.isWorker());
    super.initDAOs();
    ThirdEyeCacheRegistry.initializeCaches(config);
    environment.lifecycle().manage(new Managed() {

        @Override
        public void start() throws Exception {
            if (config.isWorker()) {
                anomalyFunctionFactory = new AnomalyFunctionFactory(config.getFunctionConfigPath());
                alertFilterFactory = new AlertFilterFactory(config.getAlertFilterConfigPath());
                taskDriver = new TaskDriver(config, anomalyFunctionFactory, alertFilterFactory);
                taskDriver.start();
            }
            if (config.isScheduler()) {
                detectionJobScheduler = new DetectionJobScheduler();
                alertFilterFactory = new AlertFilterFactory(config.getAlertFilterConfigPath());
                alertFilterAutotuneFactory = new AlertFilterAutotuneFactory(config.getFilterAutotuneConfigPath());
                detectionJobScheduler.start();
                environment.jersey().register(new DetectionJobResource(detectionJobScheduler, alertFilterFactory, alertFilterAutotuneFactory));
                environment.jersey().register(new AnomalyFunctionResource(config.getFunctionConfigPath()));
            }
            if (config.isMonitor()) {
                monitorJobScheduler = new MonitorJobScheduler(config.getMonitorConfiguration());
                monitorJobScheduler.start();
            }
            if (config.isAlert()) {
                alertJobScheduler = new AlertJobScheduler();
                alertJobScheduler.start();
                // start alert scheduler v2
                alertJobSchedulerV2 = new AlertJobSchedulerV2();
                alertJobSchedulerV2.start();
                environment.jersey().register(new AlertJobResource(alertJobScheduler, emailConfigurationDAO));
            }
            if (config.isMerger()) {
                // anomalyFunctionFactory might have initiated if current machine is also a worker
                if (anomalyFunctionFactory == null) {
                    anomalyFunctionFactory = new AnomalyFunctionFactory(config.getFunctionConfigPath());
                }
                ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
                anomalyMergeExecutor = new AnomalyMergeExecutor(executorService, anomalyFunctionFactory);
                anomalyMergeExecutor.start();
            }
            if (config.isAutoload()) {
                autoLoadPinotMetricsService = new AutoLoadPinotMetricsService(config);
                autoLoadPinotMetricsService.start();
            }
            if (config.isDataCompleteness()) {
                dataCompletenessScheduler = new DataCompletenessScheduler();
                dataCompletenessScheduler.start();
            }
        }

        @Override
        public void stop() throws Exception {
            if (config.isWorker()) {
                taskDriver.stop();
            }
            if (config.isScheduler()) {
                detectionJobScheduler.shutdown();
            }
            if (config.isMonitor()) {
                monitorJobScheduler.stop();
            }
            if (config.isAlert()) {
                alertJobScheduler.shutdown();
                alertJobSchedulerV2.shutdown();
            }
            if (config.isMerger()) {
                anomalyMergeExecutor.stop();
            }
            if (config.isAutoload()) {
                autoLoadPinotMetricsService.shutdown();
            }
            if (config.isDataCompleteness()) {
                dataCompletenessScheduler.shutdown();
            }
        }
    });
}
Also used : DataCompletenessScheduler(com.linkedin.thirdeye.completeness.checker.DataCompletenessScheduler) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AlertFilterFactory(com.linkedin.thirdeye.detector.email.filter.AlertFilterFactory) TaskDriver(com.linkedin.thirdeye.anomaly.task.TaskDriver) MonitorJobScheduler(com.linkedin.thirdeye.anomaly.monitor.MonitorJobScheduler) AlertJobScheduler(com.linkedin.thirdeye.anomaly.alert.AlertJobScheduler) AnomalyMergeExecutor(com.linkedin.thirdeye.anomaly.merge.AnomalyMergeExecutor) AnomalyFunctionResource(com.linkedin.thirdeye.dashboard.resources.AnomalyFunctionResource) AlertJobResource(com.linkedin.thirdeye.anomaly.alert.AlertJobResource) DetectionJobResource(com.linkedin.thirdeye.anomaly.detection.DetectionJobResource) DetectionJobScheduler(com.linkedin.thirdeye.anomaly.detection.DetectionJobScheduler) AutoLoadPinotMetricsService(com.linkedin.thirdeye.autoload.pinot.metrics.AutoLoadPinotMetricsService) AnomalyFunctionFactory(com.linkedin.thirdeye.detector.function.AnomalyFunctionFactory) Managed(io.dropwizard.lifecycle.Managed) AlertFilterAutotuneFactory(com.linkedin.thirdeye.anomalydetection.alertFilterAutotune.AlertFilterAutotuneFactory) AlertJobSchedulerV2(com.linkedin.thirdeye.anomaly.alert.v2.AlertJobSchedulerV2)

Example 2 with AnomalyFunctionFactory

use of com.linkedin.thirdeye.detector.function.AnomalyFunctionFactory in project pinot by linkedin.

the class ThirdEyeDashboardApplication method run.

@Override
public void run(ThirdEyeDashboardConfiguration config, Environment env) throws Exception {
    super.initDAOs();
    try {
        ThirdEyeCacheRegistry.initializeCaches(config);
    } catch (Exception e) {
        LOG.error("Exception while loading caches", e);
    }
    AnomalyFunctionFactory anomalyFunctionFactory = new AnomalyFunctionFactory(config.getFunctionConfigPath());
    AlertFilterFactory alertFilterFactory = new AlertFilterFactory(config.getAlertFilterConfigPath());
    env.jersey().register(new AnomalyFunctionResource(config.getFunctionConfigPath()));
    env.jersey().register(new DashboardResource());
    env.jersey().register(new CacheResource());
    env.jersey().register(new AnomalyResource(anomalyFunctionFactory, alertFilterFactory));
    env.jersey().register(new EmailResource(config));
    env.jersey().register(new EntityManagerResource());
    env.jersey().register(new IngraphMetricConfigResource());
    env.jersey().register(new MetricConfigResource());
    env.jersey().register(new DatasetConfigResource());
    env.jersey().register(new IngraphDashboardConfigResource());
    env.jersey().register(new JobResource());
    env.jersey().register(new AdminResource());
    env.jersey().register(new SummaryResource());
    env.jersey().register(new ThirdEyeResource());
    env.jersey().register(new OverrideConfigResource());
    env.jersey().register(new DataResource(anomalyFunctionFactory, alertFilterFactory));
    env.jersey().register(new AnomaliesResource(anomalyFunctionFactory, alertFilterFactory));
    env.jersey().register(new TimeSeriesResource());
    env.jersey().register(new OnboardResource());
    env.jersey().register(new EventResource(config.getInformedApiUrl()));
}
Also used : EntityManagerResource(com.linkedin.thirdeye.dashboard.resources.EntityManagerResource) AlertFilterFactory(com.linkedin.thirdeye.detector.email.filter.AlertFilterFactory) TimeSeriesResource(com.linkedin.thirdeye.dashboard.resources.v2.TimeSeriesResource) AnomalyResource(com.linkedin.thirdeye.dashboard.resources.AnomalyResource) JobResource(com.linkedin.thirdeye.dashboard.resources.JobResource) AnomalyFunctionResource(com.linkedin.thirdeye.dashboard.resources.AnomalyFunctionResource) EmailResource(com.linkedin.thirdeye.dashboard.resources.EmailResource) IngraphMetricConfigResource(com.linkedin.thirdeye.dashboard.resources.IngraphMetricConfigResource) AdminResource(com.linkedin.thirdeye.dashboard.resources.AdminResource) DataResource(com.linkedin.thirdeye.dashboard.resources.v2.DataResource) EventResource(com.linkedin.thirdeye.dashboard.resources.v2.EventResource) ThirdEyeResource(com.linkedin.thirdeye.dashboard.resources.ThirdEyeResource) AnomaliesResource(com.linkedin.thirdeye.dashboard.resources.v2.AnomaliesResource) MetricConfigResource(com.linkedin.thirdeye.dashboard.resources.MetricConfigResource) IngraphMetricConfigResource(com.linkedin.thirdeye.dashboard.resources.IngraphMetricConfigResource) IngraphDashboardConfigResource(com.linkedin.thirdeye.dashboard.resources.IngraphDashboardConfigResource) CacheResource(com.linkedin.thirdeye.dashboard.resources.CacheResource) OverrideConfigResource(com.linkedin.thirdeye.dashboard.resources.OverrideConfigResource) DashboardResource(com.linkedin.thirdeye.dashboard.resources.DashboardResource) AnomalyFunctionFactory(com.linkedin.thirdeye.detector.function.AnomalyFunctionFactory) OnboardResource(com.linkedin.thirdeye.dashboard.resources.OnboardResource) DatasetConfigResource(com.linkedin.thirdeye.dashboard.resources.DatasetConfigResource) SummaryResource(com.linkedin.thirdeye.dashboard.resources.SummaryResource)

Example 3 with AnomalyFunctionFactory

use of com.linkedin.thirdeye.detector.function.AnomalyFunctionFactory 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);
}
Also used : QueryCache(com.linkedin.thirdeye.client.cache.QueryCache) AlertFilterFactory(com.linkedin.thirdeye.detector.email.filter.AlertFilterFactory) ThirdEyeClient(com.linkedin.thirdeye.client.ThirdEyeClient) ThirdEyeRequest(com.linkedin.thirdeye.client.ThirdEyeRequest) DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) ResultSet(com.linkedin.pinot.client.ResultSet) TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) AnomalyFunctionFactory(com.linkedin.thirdeye.detector.function.AnomalyFunctionFactory) MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) InputStream(java.io.InputStream) MonitorConfiguration(com.linkedin.thirdeye.anomaly.monitor.MonitorConfiguration) ThirdEyeResponse(com.linkedin.thirdeye.client.ThirdEyeResponse) PinotThirdEyeResponse(com.linkedin.thirdeye.client.pinot.PinotThirdEyeResponse) ThirdEyeAnomalyConfiguration(com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration) ResultSetGroup(com.linkedin.pinot.client.ResultSetGroup) MetricDataset(com.linkedin.thirdeye.client.cache.MetricDataset) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PinotQuery(com.linkedin.thirdeye.client.pinot.PinotQuery)

Example 4 with AnomalyFunctionFactory

use of com.linkedin.thirdeye.detector.function.AnomalyFunctionFactory in project pinot by linkedin.

the class TestAnomalyFunctionFactory method setup.

@BeforeClass
public static void setup() {
    String mappingsPath = ClassLoader.getSystemResource("sample-functions.properties").getPath();
    anomalyFunctionFactory = new AnomalyFunctionFactory(mappingsPath);
}
Also used : AnomalyFunctionFactory(com.linkedin.thirdeye.detector.function.AnomalyFunctionFactory) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

AnomalyFunctionFactory (com.linkedin.thirdeye.detector.function.AnomalyFunctionFactory)4 AlertFilterFactory (com.linkedin.thirdeye.detector.email.filter.AlertFilterFactory)3 AnomalyFunctionResource (com.linkedin.thirdeye.dashboard.resources.AnomalyFunctionResource)2 ResultSet (com.linkedin.pinot.client.ResultSet)1 ResultSetGroup (com.linkedin.pinot.client.ResultSetGroup)1 ThirdEyeAnomalyConfiguration (com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration)1 AlertJobResource (com.linkedin.thirdeye.anomaly.alert.AlertJobResource)1 AlertJobScheduler (com.linkedin.thirdeye.anomaly.alert.AlertJobScheduler)1 AlertJobSchedulerV2 (com.linkedin.thirdeye.anomaly.alert.v2.AlertJobSchedulerV2)1 DetectionJobResource (com.linkedin.thirdeye.anomaly.detection.DetectionJobResource)1 DetectionJobScheduler (com.linkedin.thirdeye.anomaly.detection.DetectionJobScheduler)1 AnomalyMergeExecutor (com.linkedin.thirdeye.anomaly.merge.AnomalyMergeExecutor)1 MonitorConfiguration (com.linkedin.thirdeye.anomaly.monitor.MonitorConfiguration)1 MonitorJobScheduler (com.linkedin.thirdeye.anomaly.monitor.MonitorJobScheduler)1 TaskDriver (com.linkedin.thirdeye.anomaly.task.TaskDriver)1 AlertFilterAutotuneFactory (com.linkedin.thirdeye.anomalydetection.alertFilterAutotune.AlertFilterAutotuneFactory)1 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)1 AutoLoadPinotMetricsService (com.linkedin.thirdeye.autoload.pinot.metrics.AutoLoadPinotMetricsService)1 ThirdEyeClient (com.linkedin.thirdeye.client.ThirdEyeClient)1 ThirdEyeRequest (com.linkedin.thirdeye.client.ThirdEyeRequest)1