Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit 09eebb5

Browse files
authored
Change AD indices to be hidden indices instead of system indices (#398)
This is a forward-port of PR 394, 395. Testing done: 1. Manually verified AD indices are hidden.
1 parent 0515a35 commit 09eebb5

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

.github/workflows/CI.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ on:
44
branches:
55
- main
66
- opendistro-*
7+
- 7.10.2-no-workbench
78
pull_request:
89
branches:
910
- main
1011
- opendistro-*
12+
- 7.10.2-no-workbench
1113

1214
jobs:
1315
Build-ad:

src/main/java/com/amazon/opendistroforelasticsearch/ad/AnomalyDetectorPlugin.java

+1-19
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.time.Clock;
2323
import java.util.Arrays;
2424
import java.util.Collection;
25-
import java.util.Collections;
2625
import java.util.List;
2726
import java.util.Map;
2827
import java.util.function.Supplier;
@@ -51,12 +50,10 @@
5150
import org.elasticsearch.common.xcontent.XContentParserUtils;
5251
import org.elasticsearch.env.Environment;
5352
import org.elasticsearch.env.NodeEnvironment;
54-
import org.elasticsearch.indices.SystemIndexDescriptor;
5553
import org.elasticsearch.monitor.jvm.JvmService;
5654
import org.elasticsearch.plugins.ActionPlugin;
5755
import org.elasticsearch.plugins.Plugin;
5856
import org.elasticsearch.plugins.ScriptPlugin;
59-
import org.elasticsearch.plugins.SystemIndexPlugin;
6057
import org.elasticsearch.repositories.RepositoriesService;
6158
import org.elasticsearch.rest.RestController;
6259
import org.elasticsearch.rest.RestHandler;
@@ -189,7 +186,7 @@
189186
/**
190187
* Entry point of AD plugin.
191188
*/
192-
public class AnomalyDetectorPlugin extends Plugin implements ActionPlugin, ScriptPlugin, JobSchedulerExtension, SystemIndexPlugin {
189+
public class AnomalyDetectorPlugin extends Plugin implements ActionPlugin, ScriptPlugin, JobSchedulerExtension {
193190

194191
private static final Logger LOG = LogManager.getLogger(AnomalyDetectorPlugin.class);
195192

@@ -726,19 +723,4 @@ public ScheduledJobParser getJobParser() {
726723
return AnomalyDetectorJob.parse(parser);
727724
};
728725
}
729-
730-
@Override
731-
public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings settings) {
732-
return Collections
733-
.unmodifiableList(
734-
Arrays
735-
.asList(
736-
new SystemIndexDescriptor(AnomalyDetectionIndices.ALL_AD_RESULTS_INDEX_PATTERN, "anomaly result"),
737-
new SystemIndexDescriptor(AnomalyDetector.ANOMALY_DETECTORS_INDEX, "detector definition"),
738-
new SystemIndexDescriptor(AnomalyDetectorJob.ANOMALY_DETECTOR_JOB_INDEX, "detector job"),
739-
new SystemIndexDescriptor(CommonName.CHECKPOINT_INDEX_NAME, "model checkpoint"),
740-
new SystemIndexDescriptor(CommonName.DETECTION_STATE_INDEX, "detector information like total rcf updates")
741-
)
742-
);
743-
}
744726
}

src/main/java/com/amazon/opendistroforelasticsearch/ad/indices/AnomalyDetectionIndices.java

+18-9
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public class AnomalyDetectionIndices implements LocalNodeMasterListener {
113113
private boolean allUpdated;
114114
// we only want one update at a time
115115
private final AtomicBoolean updateRunning;
116+
// AD index settings
117+
private final Settings setting;
116118

117119
class IndexState {
118120
// keep track of whether the mapping version is up-to-date
@@ -169,6 +171,8 @@ public AnomalyDetectionIndices(
169171
.addSettingsUpdateConsumer(AD_RESULT_HISTORY_RETENTION_PERIOD, it -> { historyRetentionPeriod = it; });
170172

171173
this.clusterService.getClusterSettings().addSettingsUpdateConsumer(MAX_PRIMARY_SHARDS, it -> maxPrimaryShards = it);
174+
175+
this.setting = Settings.builder().put("index.hidden", true).build();
172176
}
173177

174178
/**
@@ -328,7 +332,8 @@ public void initAnomalyDetectorIndexIfAbsent(ActionListener<CreateIndexResponse>
328332
*/
329333
public void initAnomalyDetectorIndex(ActionListener<CreateIndexResponse> actionListener) throws IOException {
330334
CreateIndexRequest request = new CreateIndexRequest(AnomalyDetector.ANOMALY_DETECTORS_INDEX)
331-
.mapping(AnomalyDetector.TYPE, getAnomalyDetectorMappings(), XContentType.JSON);
335+
.mapping(AnomalyDetector.TYPE, getAnomalyDetectorMappings(), XContentType.JSON)
336+
.settings(setting);
332337
adminClient.indices().create(request, markMappingUpToDate(ADIndex.CONFIG, actionListener));
333338
}
334339

@@ -357,6 +362,7 @@ private void choosePrimaryShards(CreateIndexRequest request) {
357362
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, Math.min(nodeFilter.getNumberOfEligibleDataNodes(), maxPrimaryShards))
358363
// 1 replica for better search performance and fail-over
359364
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1)
365+
.put("index.hidden", true)
360366
);
361367
}
362368

@@ -400,7 +406,8 @@ public void initAnomalyDetectorJobIndex(ActionListener<CreateIndexResponse> acti
400406
public void initDetectionStateIndex(ActionListener<CreateIndexResponse> actionListener) {
401407
try {
402408
CreateIndexRequest request = new CreateIndexRequest(CommonName.DETECTION_STATE_INDEX)
403-
.mapping(AnomalyDetector.TYPE, getDetectionStateMappings(), XContentType.JSON);
409+
.mapping(AnomalyDetector.TYPE, getDetectionStateMappings(), XContentType.JSON)
410+
.settings(setting);
404411
adminClient.indices().create(request, markMappingUpToDate(ADIndex.STATE, actionListener));
405412
} catch (IOException e) {
406413
logger.error("Fail to init AD detection state index", e);
@@ -469,20 +476,22 @@ void rolloverAndDeleteHistoryIndex() {
469476
}
470477

471478
// We have to pass null for newIndexName in order to get Elastic to increment the index count.
472-
RolloverRequest request = new RolloverRequest(CommonName.ANOMALY_RESULT_INDEX_ALIAS, null);
479+
RolloverRequest rollOverRequest = new RolloverRequest(CommonName.ANOMALY_RESULT_INDEX_ALIAS, null);
473480
String adResultMapping = null;
474481
try {
475482
adResultMapping = getAnomalyResultMappings();
476483
} catch (IOException e) {
477484
logger.error("Fail to roll over AD result index, as can't get AD result index mapping");
478485
return;
479486
}
480-
request
481-
.getCreateIndexRequest()
482-
.index(AD_RESULT_HISTORY_INDEX_PATTERN)
483-
.mapping(CommonName.MAPPING_TYPE, adResultMapping, XContentType.JSON);
484-
request.addMaxIndexDocsCondition(historyMaxDocs);
485-
adminClient.indices().rolloverIndex(request, ActionListener.wrap(response -> {
487+
CreateIndexRequest createRequest = rollOverRequest.getCreateIndexRequest();
488+
489+
createRequest.index(AD_RESULT_HISTORY_INDEX_PATTERN).mapping(CommonName.MAPPING_TYPE, adResultMapping, XContentType.JSON);
490+
491+
choosePrimaryShards(createRequest);
492+
493+
rollOverRequest.addMaxIndexDocsCondition(historyMaxDocs);
494+
adminClient.indices().rolloverIndex(rollOverRequest, ActionListener.wrap(response -> {
486495
if (!response.isRolledOver()) {
487496
logger
488497
.warn("{} not rolled over. Conditions were: {}", CommonName.ANOMALY_RESULT_INDEX_ALIAS, response.getConditionStatus());

0 commit comments

Comments
 (0)