Search in sources :

Example 1 with HybridThresholdingModel

use of org.opensearch.ad.ml.HybridThresholdingModel in project anomaly-detection by opensearch-project.

the class ADStatsTests method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    // sampleSize * numberOfTrees has to be larger than 1. Otherwise, RCF reports errors.
    rcf = RandomCutForest.builder().dimensions(1).sampleSize(2).numberOfTrees(1).build();
    thresholdingModel = new HybridThresholdingModel(1e-8, 1e-5, 200, 10_000, 2, 5_000_000);
    List<ModelState<?>> modelsInformation = new ArrayList<>(Arrays.asList(new ModelState<>(rcf, "rcf-model-1", "detector-1", ModelManager.ModelType.RCF.getName(), clock, 0f), new ModelState<>(thresholdingModel, "thr-model-1", "detector-1", ModelManager.ModelType.RCF.getName(), clock, 0f), new ModelState<>(rcf, "rcf-model-2", "detector-2", ModelManager.ModelType.THRESHOLD.getName(), clock, 0f), new ModelState<>(thresholdingModel, "thr-model-2", "detector-2", ModelManager.ModelType.THRESHOLD.getName(), clock, 0f)));
    when(modelManager.getAllModels()).thenReturn(modelsInformation);
    ModelState<EntityModel> entityModel1 = MLUtil.randomModelState(new RandomModelStateConfig.Builder().fullModel(true).build());
    ModelState<EntityModel> entityModel2 = MLUtil.randomModelState(new RandomModelStateConfig.Builder().fullModel(true).build());
    List<ModelState<?>> entityModelsInformation = new ArrayList<>(Arrays.asList(entityModel1, entityModel2));
    EntityCache cache = mock(EntityCache.class);
    when(cacheProvider.get()).thenReturn(cache);
    when(cache.getAllModels()).thenReturn(entityModelsInformation);
    IndexUtils indexUtils = mock(IndexUtils.class);
    when(indexUtils.getIndexHealthStatus(anyString())).thenReturn("yellow");
    when(indexUtils.getNumberOfDocumentsInIndex(anyString())).thenReturn(100L);
    clusterStatName1 = "clusterStat1";
    clusterStatName2 = "clusterStat2";
    nodeStatName1 = "nodeStat1";
    nodeStatName2 = "nodeStat2";
    Settings settings = Settings.builder().put(MAX_MODEL_SIZE_PER_NODE.getKey(), 10).build();
    ClusterService clusterService = mock(ClusterService.class);
    ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, Collections.unmodifiableSet(new HashSet<>(Arrays.asList(MAX_MODEL_SIZE_PER_NODE))));
    when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
    statsMap = new HashMap<String, ADStat<?>>() {

        {
            put(nodeStatName1, new ADStat<>(false, new CounterSupplier()));
            put(nodeStatName2, new ADStat<>(false, new ModelsOnNodeSupplier(modelManager, cacheProvider, settings, clusterService)));
            put(clusterStatName1, new ADStat<>(true, new IndexStatusSupplier(indexUtils, "index1")));
            put(clusterStatName2, new ADStat<>(true, new IndexStatusSupplier(indexUtils, "index2")));
        }
    };
    adStats = new ADStats(statsMap);
}
Also used : ModelsOnNodeSupplier(org.opensearch.ad.stats.suppliers.ModelsOnNodeSupplier) ClusterSettings(org.opensearch.common.settings.ClusterSettings) EntityCache(org.opensearch.ad.caching.EntityCache) ArrayList(java.util.ArrayList) EntityModel(org.opensearch.ad.ml.EntityModel) HybridThresholdingModel(org.opensearch.ad.ml.HybridThresholdingModel) ModelState(org.opensearch.ad.ml.ModelState) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RandomModelStateConfig(test.org.opensearch.ad.util.RandomModelStateConfig) CounterSupplier(org.opensearch.ad.stats.suppliers.CounterSupplier) IndexUtils(org.opensearch.ad.util.IndexUtils) ClusterService(org.opensearch.cluster.service.ClusterService) IndexStatusSupplier(org.opensearch.ad.stats.suppliers.IndexStatusSupplier) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 2 with HybridThresholdingModel

use of org.opensearch.ad.ml.HybridThresholdingModel in project anomaly-detection by opensearch-project.

the class ModelsOnNodeSupplierTests method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    clock = Clock.systemUTC();
    rcf = RandomCutForest.builder().dimensions(1).sampleSize(2).numberOfTrees(1).build();
    thresholdingModel = new HybridThresholdingModel(1e-8, 1e-5, 200, 10_000, 2, 5_000_000);
    expectedResults = new ArrayList<>(Arrays.asList(new ModelState<>(rcf, "rcf-model-1", "detector-1", ModelManager.ModelType.RCF.getName(), clock, 0f), new ModelState<>(thresholdingModel, "thr-model-1", "detector-1", ModelManager.ModelType.RCF.getName(), clock, 0f), new ModelState<>(rcf, "rcf-model-2", "detector-2", ModelManager.ModelType.THRESHOLD.getName(), clock, 0f), new ModelState<>(thresholdingModel, "thr-model-2", "detector-2", ModelManager.ModelType.THRESHOLD.getName(), clock, 0f)));
    when(modelManager.getAllModels()).thenReturn(expectedResults);
    ModelState<EntityModel> entityModel1 = MLUtil.randomModelState(new RandomModelStateConfig.Builder().fullModel(true).build());
    ModelState<EntityModel> entityModel2 = MLUtil.randomModelState(new RandomModelStateConfig.Builder().fullModel(true).build());
    entityModelsInformation = new ArrayList<>(Arrays.asList(entityModel1, entityModel2));
    EntityCache cache = mock(EntityCache.class);
    when(cacheProvider.get()).thenReturn(cache);
    when(cache.getAllModels()).thenReturn(entityModelsInformation);
}
Also used : RandomModelStateConfig(test.org.opensearch.ad.util.RandomModelStateConfig) EntityCache(org.opensearch.ad.caching.EntityCache) EntityModel(org.opensearch.ad.ml.EntityModel) HybridThresholdingModel(org.opensearch.ad.ml.HybridThresholdingModel) Before(org.junit.Before)

Aggregations

Before (org.junit.Before)2 EntityCache (org.opensearch.ad.caching.EntityCache)2 EntityModel (org.opensearch.ad.ml.EntityModel)2 HybridThresholdingModel (org.opensearch.ad.ml.HybridThresholdingModel)2 RandomModelStateConfig (test.org.opensearch.ad.util.RandomModelStateConfig)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 ModelState (org.opensearch.ad.ml.ModelState)1 CounterSupplier (org.opensearch.ad.stats.suppliers.CounterSupplier)1 IndexStatusSupplier (org.opensearch.ad.stats.suppliers.IndexStatusSupplier)1 ModelsOnNodeSupplier (org.opensearch.ad.stats.suppliers.ModelsOnNodeSupplier)1 IndexUtils (org.opensearch.ad.util.IndexUtils)1 ClusterService (org.opensearch.cluster.service.ClusterService)1 ClusterSettings (org.opensearch.common.settings.ClusterSettings)1 Settings (org.opensearch.common.settings.Settings)1