use of org.opensearch.common.settings.Settings in project anomaly-detection by opensearch-project.
the class NoPowermockSearchFeatureDaoTests method testGetHighestCountEntitiesExhaustedPages.
@SuppressWarnings("unchecked")
public void testGetHighestCountEntitiesExhaustedPages() throws InterruptedException {
SearchResponse response1 = createPageResponse(attrs1);
CompositeAggregation emptyComposite = mock(CompositeAggregation.class);
when(emptyComposite.getName()).thenReturn(SearchFeatureDao.AGG_NAME_TOP);
when(emptyComposite.afterKey()).thenReturn(null);
// empty bucket
when(emptyComposite.getBuckets()).thenAnswer((Answer<List<CompositeAggregation.Bucket>>) invocation -> {
return new ArrayList<CompositeAggregation.Bucket>();
});
Aggregations emptyAggs = new Aggregations(Collections.singletonList(emptyComposite));
SearchResponseSections emptySections = new SearchResponseSections(SearchHits.empty(), emptyAggs, null, false, null, null, 1);
SearchResponse emptyResponse = new SearchResponse(emptySections, null, 1, 1, 0, 0, ShardSearchFailure.EMPTY_ARRAY, Clusters.EMPTY);
CountDownLatch inProgress = new CountDownLatch(2);
doAnswer(invocation -> {
ActionListener<SearchResponse> listener = invocation.getArgument(1);
inProgress.countDown();
if (inProgress.getCount() == 1) {
listener.onResponse(response1);
} else {
listener.onResponse(emptyResponse);
}
return null;
}).when(client).search(any(), any());
ActionListener<List<Entity>> listener = mock(ActionListener.class);
searchFeatureDao = new SearchFeatureDao(client, xContentRegistry(), interpolator, clientUtil, settings, clusterService, AnomalyDetectorSettings.NUM_SAMPLES_PER_TREE, clock, 2, 1, 60_000L);
searchFeatureDao.getHighestCountEntities(detector, 10L, 20L, listener);
ArgumentCaptor<List<Entity>> captor = ArgumentCaptor.forClass(List.class);
verify(listener).onResponse(captor.capture());
List<Entity> result = captor.getValue();
assertEquals(1, result.size());
assertEquals(Entity.createEntityByReordering(attrs1), result.get(0));
// both counts are used in client.search
assertTrue(inProgress.await(10000L, TimeUnit.MILLISECONDS));
}
use of org.opensearch.common.settings.Settings in project anomaly-detection by opensearch-project.
the class RolloverTests method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
Client client = mock(Client.class);
indicesClient = mock(IndicesAdminClient.class);
AdminClient adminClient = mock(AdminClient.class);
clusterService = mock(ClusterService.class);
ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, Collections.unmodifiableSet(new HashSet<>(Arrays.asList(AnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS_PER_SHARD, AnomalyDetectorSettings.AD_RESULT_HISTORY_ROLLOVER_PERIOD, AnomalyDetectorSettings.AD_RESULT_HISTORY_RETENTION_PERIOD, AnomalyDetectorSettings.MAX_PRIMARY_SHARDS))));
clusterName = new ClusterName("test");
when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
ThreadPool threadPool = mock(ThreadPool.class);
Settings settings = Settings.EMPTY;
when(client.admin()).thenReturn(adminClient);
when(adminClient.indices()).thenReturn(indicesClient);
DiscoveryNodeFilterer nodeFilter = mock(DiscoveryNodeFilterer.class);
numberOfNodes = 2;
when(nodeFilter.getNumberOfEligibleDataNodes()).thenReturn(numberOfNodes);
adIndices = new AnomalyDetectionIndices(client, clusterService, threadPool, settings, nodeFilter, AnomalyDetectorSettings.MAX_UPDATE_RETRY_TIMES);
clusterAdminClient = mock(ClusterAdminClient.class);
when(adminClient.cluster()).thenReturn(clusterAdminClient);
doAnswer(invocation -> {
ClusterStateRequest clusterStateRequest = invocation.getArgument(0);
assertEquals(AnomalyDetectionIndices.ALL_AD_RESULTS_INDEX_PATTERN, clusterStateRequest.indices()[0]);
@SuppressWarnings("unchecked") ActionListener<ClusterStateResponse> listener = (ActionListener<ClusterStateResponse>) invocation.getArgument(1);
listener.onResponse(new ClusterStateResponse(clusterName, clusterState, true));
return null;
}).when(clusterAdminClient).state(any(), any());
defaultMaxDocs = AnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS_PER_SHARD.getDefault(Settings.EMPTY);
}
use of org.opensearch.common.settings.Settings in project anomaly-detection by opensearch-project.
the class UpdateMappingTests method testMissingPrimaryJobShards.
// since SETTING_NUMBER_OF_SHARDS is not there, we skip updating
@SuppressWarnings("unchecked")
public void testMissingPrimaryJobShards() {
ImmutableOpenMap.Builder<String, Settings> indexToSettings = ImmutableOpenMap.builder();
Settings jobSettings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).build();
indexToSettings.put(ADIndex.JOB.getIndexName(), jobSettings);
GetSettingsResponse getSettingsResponse = new GetSettingsResponse(indexToSettings.build(), ImmutableOpenMap.of());
doAnswer(invocation -> {
ActionListener<GetSettingsResponse> listener = (ActionListener<GetSettingsResponse>) invocation.getArgument(2);
listener.onResponse(getSettingsResponse);
return null;
}).when(client).execute(any(), any(), any());
adIndices.update();
verify(indicesAdminClient, never()).updateSettings(any(), any());
}
use of org.opensearch.common.settings.Settings in project anomaly-detection by opensearch-project.
the class NodeStateManagerTests method testSettingUpdateBackOffMin.
public void testSettingUpdateBackOffMin() {
when(clock.millis()).thenReturn(1000L);
// In setUp method, we mute after 3 tries
for (int i = 0; i < 4; i++) {
stateManager.addPressure(nodeId, adId);
}
assertTrue(stateManager.isMuted(nodeId, adId));
Settings newSettings = Settings.builder().put(AnomalyDetectorSettings.BACKOFF_MINUTES.getKey(), "1m").build();
Settings.Builder target = Settings.builder();
clusterSettings.updateDynamicSettings(newSettings, target, Settings.builder(), "test");
clusterSettings.applySettings(target.build());
stateManager.addPressure(nodeId, adId);
// move the clobk by 1000 milliseconds
// when evaluating isMuted, 62000 - 1000 (last mute time) > 60000, which
// make isMuted true
when(clock.millis()).thenReturn(62000L);
assertTrue(!stateManager.isMuted(nodeId, adId));
}
use of org.opensearch.common.settings.Settings in project anomaly-detection by opensearch-project.
the class NodeStateManagerTests method testSettingUpdateMaxRetry.
public void testSettingUpdateMaxRetry() {
when(clock.millis()).thenReturn(System.currentTimeMillis());
stateManager.addPressure(nodeId, adId);
// In setUp method, we mute after 3 tries
assertTrue(!stateManager.isMuted(nodeId, adId));
Settings newSettings = Settings.builder().put(AnomalyDetectorSettings.MAX_RETRY_FOR_UNRESPONSIVE_NODE.getKey(), "1").build();
Settings.Builder target = Settings.builder();
clusterSettings.updateDynamicSettings(newSettings, target, Settings.builder(), "test");
clusterSettings.applySettings(target.build());
stateManager.addPressure(nodeId, adId);
// since we have one violation and the max is 1, this is flagged as muted
assertTrue(stateManager.isMuted(nodeId, adId));
}
Aggregations