Search in sources :

Example 1 with ThirdEyeAnomalyConfiguration

use of com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration in project pinot by linkedin.

the class EmailResource method generateAndSendAlertForDatasets.

// TODO : add end points for AlertConfig
@GET
@Path("generate/datasets/{startTime}/{endTime}")
public Response generateAndSendAlertForDatasets(@PathParam("startTime") Long startTime, @PathParam("endTime") Long endTime, @QueryParam("datasets") String datasets, @QueryParam("from") String fromAddr, @QueryParam("to") String toAddr, @QueryParam("subject") String subject, @QueryParam("includeSentAnomaliesOnly") boolean includeSentAnomaliesOnly, @QueryParam("teHost") String teHost, @QueryParam("smtpHost") String smtpHost, @QueryParam("smtpPort") int smtpPort) {
    if (Strings.isNullOrEmpty(datasets)) {
        throw new WebApplicationException("datasets null or empty : " + datasets);
    }
    String[] dataSetArr = datasets.split(",");
    if (dataSetArr.length == 0) {
        throw new WebApplicationException("Datasets empty : " + datasets);
    }
    if (Strings.isNullOrEmpty(toAddr)) {
        throw new WebApplicationException("Empty : list of recipients" + toAddr);
    }
    if (Strings.isNullOrEmpty(teHost)) {
        throw new WebApplicationException("Invalid TE host" + teHost);
    }
    if (Strings.isNullOrEmpty(smtpHost)) {
        throw new WebApplicationException("invalid smtp host" + smtpHost);
    }
    AnomalyReportGenerator anomalyReportGenerator = AnomalyReportGenerator.getInstance();
    List<MergedAnomalyResultDTO> anomalies = anomalyReportGenerator.getAnomaliesForDatasets(Arrays.asList(dataSetArr), startTime, endTime);
    ThirdEyeAnomalyConfiguration configuration = new ThirdEyeAnomalyConfiguration();
    SmtpConfiguration smtpConfiguration = new SmtpConfiguration();
    smtpConfiguration.setSmtpHost(smtpHost);
    smtpConfiguration.setSmtpPort(smtpPort);
    configuration.setSmtpConfiguration(smtpConfiguration);
    configuration.setDashboardHost(teHost);
    configuration.setPhantomJsPath(thirdeyeConfiguration.getPhantomJsPath());
    configuration.setRootDir(thirdeyeConfiguration.getRootDir());
    String emailSub = Strings.isNullOrEmpty(subject) ? "Thirdeye Anomaly Report" : subject;
    anomalyReportGenerator.buildReport(startTime, endTime, anomalies, emailSub, configuration, includeSentAnomaliesOnly, toAddr, fromAddr, "Thirdeye Anomaly Report", true);
    return Response.ok().build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) MergedAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO) SmtpConfiguration(com.linkedin.thirdeye.anomaly.SmtpConfiguration) AnomalyReportGenerator(com.linkedin.thirdeye.anomaly.alert.util.AnomalyReportGenerator) ThirdEyeAnomalyConfiguration(com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with ThirdEyeAnomalyConfiguration

use of com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration in project pinot by linkedin.

the class GenerateAnomalyReport method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.out.println("please pass report config directory path\n");
        System.exit(1);
    }
    File configFile = new File(args[0]);
    AnomalyReportConfig config = OBJECT_MAPPER.readValue(configFile, AnomalyReportConfig.class);
    File persistenceFile = new File(config.getThirdEyeConfigDirectoryPath() + "/persistence.yml");
    if (!persistenceFile.exists()) {
        System.err.println("Missing file:" + persistenceFile);
        System.exit(1);
    }
    File detectorConfigFile = new File(config.getThirdEyeConfigDirectoryPath() + "/detector.yml");
    if (!detectorConfigFile.exists()) {
        System.err.println("Missing file:" + detectorConfigFile);
        System.exit(1);
    }
    ConfigurationFactory<ThirdEyeAnomalyConfiguration> factory = new ConfigurationFactory<>(ThirdEyeAnomalyConfiguration.class, Validation.buildDefaultValidatorFactory().getValidator(), Jackson.newObjectMapper(), "");
    ThirdEyeAnomalyConfiguration detectorConfig = factory.build(detectorConfigFile);
    GenerateAnomalyReport reportGenerator = new GenerateAnomalyReport(df.parse(config.getStartTimeIso()), df.parse(config.getEndTimeIso()), persistenceFile, Arrays.asList(config.getDatasets().split(",")), config.getTeBaseUrl(), detectorConfig.getSmtpConfiguration(), config.getEmailRecipients());
    reportGenerator.buildReport();
    //    reportGenerator.updateEmailConfig();
    return;
}
Also used : ConfigurationFactory(io.dropwizard.configuration.ConfigurationFactory) ThirdEyeAnomalyConfiguration(com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration) File(java.io.File)

Example 3 with ThirdEyeAnomalyConfiguration

use of com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration 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 ThirdEyeAnomalyConfiguration

use of com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration in project pinot by linkedin.

the class EmailResource method generateAndSendAlertForMetrics.

@GET
@Path("generate/metrics/{startTime}/{endTime}")
public Response generateAndSendAlertForMetrics(@PathParam("startTime") Long startTime, @PathParam("endTime") Long endTime, @QueryParam("metrics") String metrics, @QueryParam("from") String fromAddr, @QueryParam("to") String toAddr, @QueryParam("subject") String subject, @QueryParam("includeSentAnomaliesOnly") boolean includeSentAnomaliesOnly, @QueryParam("teHost") String teHost, @QueryParam("smtpHost") String smtpHost, @QueryParam("smtpPort") int smtpPort, @QueryParam("phantomJsPath") String phantomJsPath) {
    if (Strings.isNullOrEmpty(metrics)) {
        throw new WebApplicationException("metrics null or empty: " + metrics);
    }
    String[] metricsArr = metrics.split(",");
    if (metricsArr.length == 0) {
        throw new WebApplicationException("metrics empty : " + metricsArr);
    }
    if (Strings.isNullOrEmpty(toAddr)) {
        throw new WebApplicationException("Empty : list of recipients" + toAddr);
    }
    if (Strings.isNullOrEmpty(teHost)) {
        throw new WebApplicationException("Invalid TE host" + teHost);
    }
    if (Strings.isNullOrEmpty(smtpHost)) {
        throw new WebApplicationException("invalid smtp host" + smtpHost);
    }
    AnomalyReportGenerator anomalyReportGenerator = AnomalyReportGenerator.getInstance();
    List<MergedAnomalyResultDTO> anomalies = anomalyReportGenerator.getAnomaliesForMetrics(Arrays.asList(metricsArr), startTime, endTime);
    ThirdEyeAnomalyConfiguration configuration = new ThirdEyeAnomalyConfiguration();
    SmtpConfiguration smtpConfiguration = new SmtpConfiguration();
    smtpConfiguration.setSmtpHost(smtpHost);
    smtpConfiguration.setSmtpPort(smtpPort);
    configuration.setSmtpConfiguration(smtpConfiguration);
    configuration.setDashboardHost(teHost);
    configuration.setPhantomJsPath(phantomJsPath);
    String emailSub = Strings.isNullOrEmpty(subject) ? "Thirdeye Anomaly Report" : subject;
    anomalyReportGenerator.buildReport(startTime, endTime, anomalies, emailSub, configuration, includeSentAnomaliesOnly, toAddr, fromAddr, "Thirdeye Anomaly Report", true);
    return Response.ok().build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) MergedAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO) SmtpConfiguration(com.linkedin.thirdeye.anomaly.SmtpConfiguration) AnomalyReportGenerator(com.linkedin.thirdeye.anomaly.alert.util.AnomalyReportGenerator) ThirdEyeAnomalyConfiguration(com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 5 with ThirdEyeAnomalyConfiguration

use of com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration in project pinot by linkedin.

the class AnomalyReportDriver method runReportGenerator.

static void runReportGenerator() throws Exception {
    File configFile = new File("/opt/Code/pinot2_0/thirdeye/thirdeye-pinot/src/test/resources/custom-anomaly-report-config.yml");
    AnomalyReportConfig config = OBJECT_MAPPER.readValue(configFile, AnomalyReportConfig.class);
    File persistenceFile = new File(config.getThirdEyeConfigDirectoryPath() + "/persistence.yml");
    if (!persistenceFile.exists()) {
        System.err.println("Missing file:" + persistenceFile);
        System.exit(1);
    }
    File detectorConfigFile = new File(config.getThirdEyeConfigDirectoryPath() + "/detector.yml");
    if (!detectorConfigFile.exists()) {
        System.err.println("Missing file:" + detectorConfigFile);
        System.exit(1);
    }
    ConfigurationFactory<ThirdEyeAnomalyConfiguration> factory = new ConfigurationFactory<>(ThirdEyeAnomalyConfiguration.class, Validation.buildDefaultValidatorFactory().getValidator(), Jackson.newObjectMapper(), "");
    ThirdEyeAnomalyConfiguration detectorConfig = factory.build(detectorConfigFile);
    long current = System.currentTimeMillis();
    Date endDate = new Date(current - (current % 36_00_000));
    Date startDate = new Date(endDate.getTime() - TimeUnit.HOURS.toMillis(24));
    GenerateAnomalyReport reportGenerator = new GenerateAnomalyReport(startDate, endDate, persistenceFile, Arrays.asList(config.getDatasets().split(",")), config.getTeBaseUrl(), detectorConfig.getSmtpConfiguration(), config.getEmailRecipients());
    reportGenerator.buildReport();
}
Also used : ConfigurationFactory(io.dropwizard.configuration.ConfigurationFactory) ThirdEyeAnomalyConfiguration(com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration) File(java.io.File) Date(java.util.Date)

Aggregations

ThirdEyeAnomalyConfiguration (com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration)5 SmtpConfiguration (com.linkedin.thirdeye.anomaly.SmtpConfiguration)2 AnomalyReportGenerator (com.linkedin.thirdeye.anomaly.alert.util.AnomalyReportGenerator)2 MergedAnomalyResultDTO (com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO)2 ConfigurationFactory (io.dropwizard.configuration.ConfigurationFactory)2 File (java.io.File)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 ResultSet (com.linkedin.pinot.client.ResultSet)1 ResultSetGroup (com.linkedin.pinot.client.ResultSetGroup)1 MonitorConfiguration (com.linkedin.thirdeye.anomaly.monitor.MonitorConfiguration)1 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)1 ThirdEyeClient (com.linkedin.thirdeye.client.ThirdEyeClient)1 ThirdEyeRequest (com.linkedin.thirdeye.client.ThirdEyeRequest)1 ThirdEyeResponse (com.linkedin.thirdeye.client.ThirdEyeResponse)1 MetricDataset (com.linkedin.thirdeye.client.cache.MetricDataset)1 QueryCache (com.linkedin.thirdeye.client.cache.QueryCache)1 PinotQuery (com.linkedin.thirdeye.client.pinot.PinotQuery)1 PinotThirdEyeResponse (com.linkedin.thirdeye.client.pinot.PinotThirdEyeResponse)1