Search in sources :

Example 1 with AnomalyMergeConfig

use of com.linkedin.thirdeye.anomaly.merge.AnomalyMergeConfig in project pinot by linkedin.

the class TestMergedAnomalyResultManager method testMergedResultCRUD.

@Test
public void testMergedResultCRUD() {
    anomalyFunctionDAO.save(function);
    Assert.assertNotNull(function.getId());
    // create anomaly result
    RawAnomalyResultDTO result = getAnomalyResult();
    result.setFunction(function);
    rawAnomalyResultDAO.save(result);
    RawAnomalyResultDTO resultRet = rawAnomalyResultDAO.findById(result.getId());
    Assert.assertEquals(resultRet.getFunction(), function);
    anomalyResultId = result.getId();
    // Let's create merged result
    List<RawAnomalyResultDTO> rawResults = new ArrayList<>();
    rawResults.add(result);
    AnomalyMergeConfig mergeConfig = new AnomalyMergeConfig();
    List<MergedAnomalyResultDTO> mergedResults = AnomalyTimeBasedSummarizer.mergeAnomalies(rawResults, mergeConfig.getMaxMergeDurationLength(), mergeConfig.getSequentialAllowedGap());
    Assert.assertEquals(mergedResults.get(0).getStartTime(), result.getStartTime());
    Assert.assertEquals(mergedResults.get(0).getEndTime(), result.getEndTime());
    Assert.assertEquals(mergedResults.get(0).getAnomalyResults().get(0), result);
    // Let's persist the merged result
    mergedResults.get(0).setDimensions(result.getDimensions());
    mergedAnomalyResultDAO.save(mergedResults.get(0));
    mergedResult = mergedResults.get(0);
    Assert.assertNotNull(mergedResult.getId());
    // verify the merged result
    MergedAnomalyResultDTO mergedResultById = mergedAnomalyResultDAO.findById(mergedResult.getId());
    Assert.assertEquals(mergedResultById.getAnomalyResults(), rawResults);
    Assert.assertEquals(mergedResultById.getAnomalyResults().get(0).getId(), anomalyResultId);
    List<MergedAnomalyResultDTO> mergedResultsByMetricDimensionsTime = mergedAnomalyResultDAO.findByCollectionMetricDimensionsTime(mergedResult.getCollection(), mergedResult.getMetric(), mergedResult.getDimensions().toString(), 0, System.currentTimeMillis(), true);
    Assert.assertEquals(mergedResultsByMetricDimensionsTime.get(0), mergedResult);
}
Also used : RawAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO) MergedAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO) ArrayList(java.util.ArrayList) AnomalyMergeConfig(com.linkedin.thirdeye.anomaly.merge.AnomalyMergeConfig) Test(org.testng.annotations.Test)

Aggregations

AnomalyMergeConfig (com.linkedin.thirdeye.anomaly.merge.AnomalyMergeConfig)1 MergedAnomalyResultDTO (com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO)1 RawAnomalyResultDTO (com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO)1 ArrayList (java.util.ArrayList)1 Test (org.testng.annotations.Test)1