Search in sources :

Example 11 with NodeStateManager

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

the class CronTransportActionTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    ThreadPool threadPool = mock(ThreadPool.class);
    ClusterService clusterService = mock(ClusterService.class);
    localNodeID = "foo";
    when(clusterService.localNode()).thenReturn(new DiscoveryNode(localNodeID, buildNewFakeTransportAddress(), Version.CURRENT));
    when(clusterService.getClusterName()).thenReturn(new ClusterName("test"));
    TransportService transportService = mock(TransportService.class);
    ActionFilters actionFilters = mock(ActionFilters.class);
    NodeStateManager tarnsportStatemanager = mock(NodeStateManager.class);
    ModelManager modelManager = mock(ModelManager.class);
    FeatureManager featureManager = mock(FeatureManager.class);
    CacheProvider cacheProvider = mock(CacheProvider.class);
    EntityCache entityCache = mock(EntityCache.class);
    EntityColdStarter entityColdStarter = mock(EntityColdStarter.class);
    when(cacheProvider.get()).thenReturn(entityCache);
    ADTaskManager adTaskManager = mock(ADTaskManager.class);
    action = new CronTransportAction(threadPool, clusterService, transportService, actionFilters, tarnsportStatemanager, modelManager, featureManager, cacheProvider, entityColdStarter, adTaskManager);
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) EntityCache(org.opensearch.ad.caching.EntityCache) ThreadPool(org.opensearch.threadpool.ThreadPool) ActionFilters(org.opensearch.action.support.ActionFilters) ModelManager(org.opensearch.ad.ml.ModelManager) CacheProvider(org.opensearch.ad.caching.CacheProvider) NodeStateManager(org.opensearch.ad.NodeStateManager) ClusterService(org.opensearch.cluster.service.ClusterService) EntityColdStarter(org.opensearch.ad.ml.EntityColdStarter) TransportService(org.opensearch.transport.TransportService) ADTaskManager(org.opensearch.ad.task.ADTaskManager) ClusterName(org.opensearch.cluster.ClusterName) FeatureManager(org.opensearch.ad.feature.FeatureManager) Before(org.junit.Before)

Example 12 with NodeStateManager

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

the class ModelManagerTests method getEmptyStateFullSamples.

@Test
public void getEmptyStateFullSamples() {
    SearchFeatureDao searchFeatureDao = mock(SearchFeatureDao.class);
    SingleFeatureLinearUniformInterpolator singleFeatureLinearUniformInterpolator = new IntegerSensitiveSingleFeatureLinearUniformInterpolator();
    LinearUniformInterpolator interpolator = new LinearUniformInterpolator(singleFeatureLinearUniformInterpolator);
    NodeStateManager stateManager = mock(NodeStateManager.class);
    featureManager = new FeatureManager(searchFeatureDao, interpolator, clock, AnomalyDetectorSettings.MAX_TRAIN_SAMPLE, AnomalyDetectorSettings.MAX_SAMPLE_STRIDE, AnomalyDetectorSettings.TRAIN_SAMPLE_TIME_RANGE_IN_HOURS, AnomalyDetectorSettings.MIN_TRAIN_SAMPLES, AnomalyDetectorSettings.MAX_SHINGLE_PROPORTION_MISSING, AnomalyDetectorSettings.MAX_IMPUTATION_NEIGHBOR_DISTANCE, AnomalyDetectorSettings.PREVIEW_SAMPLE_RATE, AnomalyDetectorSettings.MAX_PREVIEW_SAMPLES, AnomalyDetectorSettings.HOURLY_MAINTENANCE, threadPool, AnomalyDetectorPlugin.AD_THREAD_POOL_NAME);
    CheckpointWriteWorker checkpointWriteQueue = mock(CheckpointWriteWorker.class);
    entityColdStarter = new EntityColdStarter(clock, threadPool, stateManager, AnomalyDetectorSettings.NUM_SAMPLES_PER_TREE, AnomalyDetectorSettings.NUM_TREES, AnomalyDetectorSettings.TIME_DECAY, numMinSamples, AnomalyDetectorSettings.MAX_SAMPLE_STRIDE, AnomalyDetectorSettings.MAX_TRAIN_SAMPLE, interpolator, searchFeatureDao, AnomalyDetectorSettings.THRESHOLD_MIN_PVALUE, featureManager, settings, AnomalyDetectorSettings.HOURLY_MAINTENANCE, checkpointWriteQueue, AnomalyDetectorSettings.MAX_COLD_START_ROUNDS);
    modelManager = spy(new ModelManager(checkpointDao, clock, numTrees, numSamples, rcfTimeDecay, numMinSamples, thresholdMinPvalue, minPreviewSize, modelTtl, checkpointInterval, entityColdStarter, featureManager, memoryTracker));
    ModelState<EntityModel> state = MLUtil.randomModelState(new RandomModelStateConfig.Builder().fullModel(false).sampleSize(numMinSamples).build());
    EntityModel model = state.getModel();
    assertTrue(!model.getTrcf().isPresent());
    ThresholdingResult result = modelManager.getAnomalyResultForEntity(new double[] { -1 }, state, "", null, shingleSize);
    // model outputs scores
    assertTrue(result.getRcfScore() != 0);
    // added the sample to score since our model is empty
    assertEquals(0, model.getSamples().size());
}
Also used : SearchFeatureDao(org.opensearch.ad.feature.SearchFeatureDao) NodeStateManager(org.opensearch.ad.NodeStateManager) SingleFeatureLinearUniformInterpolator(org.opensearch.ad.dataprocessor.SingleFeatureLinearUniformInterpolator) IntegerSensitiveSingleFeatureLinearUniformInterpolator(org.opensearch.ad.dataprocessor.IntegerSensitiveSingleFeatureLinearUniformInterpolator) CheckpointWriteWorker(org.opensearch.ad.ratelimit.CheckpointWriteWorker) IntegerSensitiveSingleFeatureLinearUniformInterpolator(org.opensearch.ad.dataprocessor.IntegerSensitiveSingleFeatureLinearUniformInterpolator) SingleFeatureLinearUniformInterpolator(org.opensearch.ad.dataprocessor.SingleFeatureLinearUniformInterpolator) IntegerSensitiveSingleFeatureLinearUniformInterpolator(org.opensearch.ad.dataprocessor.IntegerSensitiveSingleFeatureLinearUniformInterpolator) LinearUniformInterpolator(org.opensearch.ad.dataprocessor.LinearUniformInterpolator) FeatureManager(org.opensearch.ad.feature.FeatureManager) Test(org.junit.Test)

Aggregations

NodeStateManager (org.opensearch.ad.NodeStateManager)12 CountDownLatch (java.util.concurrent.CountDownLatch)7 PlainActionFuture (org.opensearch.action.support.PlainActionFuture)6 ActionListener (org.opensearch.action.ActionListener)5 ActionFilters (org.opensearch.action.support.ActionFilters)5 NoSuchElementException (java.util.NoSuchElementException)4 EndRunException (org.opensearch.ad.common.exception.EndRunException)4 FeatureManager (org.opensearch.ad.feature.FeatureManager)4 IOException (java.io.IOException)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 OpenSearchTimeoutException (org.opensearch.OpenSearchTimeoutException)3 GetRequest (org.opensearch.action.get.GetRequest)3 GetResponse (org.opensearch.action.get.GetResponse)3 SearchPhaseExecutionException (org.opensearch.action.search.SearchPhaseExecutionException)3 LimitExceededException (org.opensearch.ad.common.exception.LimitExceededException)3 ClientUtil (org.opensearch.ad.util.ClientUtil)3 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)3 ClusterService (org.opensearch.cluster.service.ClusterService)3 IndexNotFoundException (org.opensearch.index.IndexNotFoundException)3