diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7a9f7a1c6..0aaeea720 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -33,37 +33,37 @@ jobs: with: repository: 'opensearch-project/OpenSearch' path: OpenSearch - ref: 'main' + ref: '1.x' - name: Build OpenSearch working-directory: ./OpenSearch - run: ./gradlew publishToMavenLocal -Dbuild.version_qualifier=beta1 -Dbuild.snapshot=false + run: ./gradlew publishToMavenLocal -Dbuild.version_qualifier=rc1 -Dbuild.snapshot=false # dependencies: common-utils - name: Checkout common-utils uses: actions/checkout@v2 with: - ref: '1.0.0-beta1' + ref: 'main' # TODO: update to the right branch name once it's ready. e.g. 1.x repository: 'opensearch-project/common-utils' path: common-utils - name: Build common-utils working-directory: ./common-utils - run: ./gradlew publishToMavenLocal -Dopensearch.version=1.0.0-beta1 + run: ./gradlew publishToMavenLocal -Dopensearch.version=1.0.0-rc1 # dependencies: job-scheduler - name: Checkout job-scheduler uses: actions/checkout@v2 with: - ref: '1.0.0-beta1' + ref: 'main' # TODO: update to the right branch name once it's ready. e.g. 1.x repository: 'opensearch-project/job-scheduler' path: job-scheduler - name: Build job-scheduler working-directory: ./job-scheduler - run: ./gradlew publishToMavenLocal -Dopensearch.version=1.0.0-beta1 -Dbuild.snapshot=false + run: ./gradlew publishToMavenLocal -Dopensearch.version=1.0.0-rc1 -Dbuild.snapshot=false - name: Assemble job-scheduler working-directory: ./job-scheduler run: | - ./gradlew assemble -Dopensearch.version=1.0.0-beta1 -Dbuild.snapshot=false + ./gradlew assemble -Dopensearch.version=1.0.0-rc1 -Dbuild.snapshot=false echo "Creating ../src/test/resources/job-scheduler ..." mkdir -p ../src/test/resources/job-scheduler pwd @@ -75,11 +75,11 @@ jobs: - name: Build and Run Tests run: | - ./gradlew build -Dopensearch.version=1.0.0-beta1 + ./gradlew build -Dopensearch.version=1.0.0-rc1 - name: Publish to Maven Local run: | - ./gradlew publishToMavenLocal -Dopensearch.version=1.0.0-beta1 + ./gradlew publishToMavenLocal -Dopensearch.version=1.0.0-rc1 - name: Upload Coverage Report uses: codecov/codecov-action@v1 diff --git a/build.gradle b/build.gradle index 2b2eb2bc5..03a0325c8 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ import org.opensearch.gradle.test.RestIntegTestTask buildscript { ext { opensearch_group = "org.opensearch" - opensearch_version = System.getProperty("opensearch.version", "1.0.0-beta1") + opensearch_version = System.getProperty("opensearch.version", "1.0.0-rc1") common_utils_version = '1.0.0.0-beta1' job_scheduler_version = '1.0.0.0-beta1' } @@ -368,8 +368,8 @@ checkstyle { dependencies { compile "org.opensearch:opensearch:${opensearch_version}" compileOnly "org.opensearch.plugin:opensearch-scripting-painless-spi:${opensearch_version}" - compileOnly "com.amazon.opendistroforelasticsearch:opensearch-job-scheduler-spi:${job_scheduler_version}" - compile "com.amazon.opendistroforelasticsearch:common-utils:${common_utils_version}" + compileOnly "org.opensearch:opensearch-job-scheduler-spi:${job_scheduler_version}" + compile "org.opensearch:common-utils:${common_utils_version}" compile group: 'com.google.guava', name: 'guava', version:'29.0-jre' compile group: 'org.apache.commons', name: 'commons-math3', version: '3.6.1' compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6' diff --git a/src/main/java/org/opensearch/ad/AnomalyDetectorJobRunner.java b/src/main/java/org/opensearch/ad/AnomalyDetectorJobRunner.java index 03aa3f917..b99dddbb1 100644 --- a/src/main/java/org/opensearch/ad/AnomalyDetectorJobRunner.java +++ b/src/main/java/org/opensearch/ad/AnomalyDetectorJobRunner.java @@ -71,16 +71,16 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; +import org.opensearch.commons.InjectSecurity; +import org.opensearch.commons.authuser.User; +import org.opensearch.jobscheduler.spi.JobExecutionContext; +import org.opensearch.jobscheduler.spi.LockModel; +import org.opensearch.jobscheduler.spi.ScheduledJobParameter; +import org.opensearch.jobscheduler.spi.ScheduledJobRunner; +import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule; +import org.opensearch.jobscheduler.spi.utils.LockService; import org.opensearch.threadpool.ThreadPool; -import com.amazon.opendistroforelasticsearch.commons.InjectSecurity; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.JobExecutionContext; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.LockModel; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.ScheduledJobParameter; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.ScheduledJobRunner; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.IntervalSchedule; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.utils.LockService; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; diff --git a/src/main/java/org/opensearch/ad/AnomalyDetectorPlugin.java b/src/main/java/org/opensearch/ad/AnomalyDetectorPlugin.java index 7ec8521ef..ebf6ee9a5 100644 --- a/src/main/java/org/opensearch/ad/AnomalyDetectorPlugin.java +++ b/src/main/java/org/opensearch/ad/AnomalyDetectorPlugin.java @@ -81,6 +81,7 @@ import org.opensearch.ad.rest.RestStatsAnomalyDetectorAction; import org.opensearch.ad.settings.AnomalyDetectorSettings; import org.opensearch.ad.settings.EnabledSetting; +import org.opensearch.ad.settings.LegacyOpenDistroAnomalyDetectorSettings; import org.opensearch.ad.stats.ADStat; import org.opensearch.ad.stats.ADStats; import org.opensearch.ad.stats.StatNames; @@ -172,6 +173,9 @@ import org.opensearch.common.xcontent.XContentParserUtils; import org.opensearch.env.Environment; import org.opensearch.env.NodeEnvironment; +import org.opensearch.jobscheduler.spi.JobSchedulerExtension; +import org.opensearch.jobscheduler.spi.ScheduledJobParser; +import org.opensearch.jobscheduler.spi.ScheduledJobRunner; import org.opensearch.monitor.jvm.JvmService; import org.opensearch.plugins.ActionPlugin; import org.opensearch.plugins.Plugin; @@ -185,9 +189,6 @@ import org.opensearch.threadpool.ThreadPool; import org.opensearch.watcher.ResourceWatcherService; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.JobSchedulerExtension; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.ScheduledJobParser; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.ScheduledJobRunner; import com.amazon.randomcutforest.serialize.RandomCutForestSerDe; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -637,6 +638,31 @@ public List> getSettings() { List> systemSetting = ImmutableList .of( + LegacyOpenDistroAnomalyDetectorSettings.MAX_SINGLE_ENTITY_ANOMALY_DETECTORS, + LegacyOpenDistroAnomalyDetectorSettings.MAX_MULTI_ENTITY_ANOMALY_DETECTORS, + LegacyOpenDistroAnomalyDetectorSettings.MAX_ANOMALY_FEATURES, + LegacyOpenDistroAnomalyDetectorSettings.REQUEST_TIMEOUT, + LegacyOpenDistroAnomalyDetectorSettings.DETECTION_INTERVAL, + LegacyOpenDistroAnomalyDetectorSettings.DETECTION_WINDOW_DELAY, + LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_ROLLOVER_PERIOD, + LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS, + LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_UNRESPONSIVE_NODE, + LegacyOpenDistroAnomalyDetectorSettings.COOLDOWN_MINUTES, + LegacyOpenDistroAnomalyDetectorSettings.BACKOFF_MINUTES, + LegacyOpenDistroAnomalyDetectorSettings.BACKOFF_INITIAL_DELAY, + LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_BACKOFF, + LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_RETENTION_PERIOD, + LegacyOpenDistroAnomalyDetectorSettings.MODEL_MAX_SIZE_PERCENTAGE, + LegacyOpenDistroAnomalyDetectorSettings.MAX_ENTITIES_PER_QUERY, + LegacyOpenDistroAnomalyDetectorSettings.MAX_ENTITIES_FOR_PREVIEW, + LegacyOpenDistroAnomalyDetectorSettings.INDEX_PRESSURE_SOFT_LIMIT, + LegacyOpenDistroAnomalyDetectorSettings.MAX_PRIMARY_SHARDS, + LegacyOpenDistroAnomalyDetectorSettings.FILTER_BY_BACKEND_ROLES, + LegacyOpenDistroAnomalyDetectorSettings.MAX_CACHE_MISS_HANDLING_PER_SECOND, + LegacyOpenDistroAnomalyDetectorSettings.MAX_BATCH_TASK_PER_NODE, + LegacyOpenDistroAnomalyDetectorSettings.BATCH_TASK_PIECE_INTERVAL_SECONDS, + LegacyOpenDistroAnomalyDetectorSettings.MAX_OLD_AD_TASK_DOCS_PER_DETECTOR, + LegacyOpenDistroAnomalyDetectorSettings.BATCH_TASK_PIECE_SIZE, AnomalyDetectorSettings.MAX_SINGLE_ENTITY_ANOMALY_DETECTORS, AnomalyDetectorSettings.MAX_MULTI_ENTITY_ANOMALY_DETECTORS, AnomalyDetectorSettings.MAX_ANOMALY_FEATURES, diff --git a/src/main/java/org/opensearch/ad/model/ADTask.java b/src/main/java/org/opensearch/ad/model/ADTask.java index d9f4b48fd..854d3d1fe 100644 --- a/src/main/java/org/opensearch/ad/model/ADTask.java +++ b/src/main/java/org/opensearch/ad/model/ADTask.java @@ -39,8 +39,8 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.commons.authuser.User; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; import com.google.common.base.Objects; /** diff --git a/src/main/java/org/opensearch/ad/model/AnomalyDetector.java b/src/main/java/org/opensearch/ad/model/AnomalyDetector.java index ee429e1f6..773b45883 100644 --- a/src/main/java/org/opensearch/ad/model/AnomalyDetector.java +++ b/src/main/java/org/opensearch/ad/model/AnomalyDetector.java @@ -57,10 +57,10 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.commons.authuser.User; import org.opensearch.index.query.QueryBuilder; import org.opensearch.index.query.QueryBuilders; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; diff --git a/src/main/java/org/opensearch/ad/model/AnomalyDetectorJob.java b/src/main/java/org/opensearch/ad/model/AnomalyDetectorJob.java index fc5f28dea..c2c9a25a9 100644 --- a/src/main/java/org/opensearch/ad/model/AnomalyDetectorJob.java +++ b/src/main/java/org/opensearch/ad/model/AnomalyDetectorJob.java @@ -41,13 +41,13 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.commons.authuser.User; +import org.opensearch.jobscheduler.spi.ScheduledJobParameter; +import org.opensearch.jobscheduler.spi.schedule.CronSchedule; +import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule; +import org.opensearch.jobscheduler.spi.schedule.Schedule; +import org.opensearch.jobscheduler.spi.schedule.ScheduleParser; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.ScheduledJobParameter; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.CronSchedule; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.IntervalSchedule; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.Schedule; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.ScheduleParser; import com.google.common.base.Objects; /** diff --git a/src/main/java/org/opensearch/ad/model/AnomalyResult.java b/src/main/java/org/opensearch/ad/model/AnomalyResult.java index 76577d27d..d49c701a3 100644 --- a/src/main/java/org/opensearch/ad/model/AnomalyResult.java +++ b/src/main/java/org/opensearch/ad/model/AnomalyResult.java @@ -46,8 +46,8 @@ import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.commons.authuser.User; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; import com.google.common.base.Objects; /** diff --git a/src/main/java/org/opensearch/ad/rest/handler/IndexAnomalyDetectorActionHandler.java b/src/main/java/org/opensearch/ad/rest/handler/IndexAnomalyDetectorActionHandler.java index 8c477e418..39170d138 100644 --- a/src/main/java/org/opensearch/ad/rest/handler/IndexAnomalyDetectorActionHandler.java +++ b/src/main/java/org/opensearch/ad/rest/handler/IndexAnomalyDetectorActionHandler.java @@ -69,6 +69,7 @@ import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.commons.authuser.User; import org.opensearch.index.query.BoolQueryBuilder; import org.opensearch.index.query.QueryBuilder; import org.opensearch.index.query.QueryBuilders; @@ -77,8 +78,6 @@ import org.opensearch.search.builder.SearchSourceBuilder; import org.opensearch.transport.TransportService; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; - /** * Anomaly detector REST action handler to process POST/PUT request. * POST request is for creating anomaly detector. diff --git a/src/main/java/org/opensearch/ad/rest/handler/IndexAnomalyDetectorJobActionHandler.java b/src/main/java/org/opensearch/ad/rest/handler/IndexAnomalyDetectorJobActionHandler.java index 0d6d61b0f..8e44c2570 100644 --- a/src/main/java/org/opensearch/ad/rest/handler/IndexAnomalyDetectorJobActionHandler.java +++ b/src/main/java/org/opensearch/ad/rest/handler/IndexAnomalyDetectorJobActionHandler.java @@ -59,11 +59,10 @@ import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule; +import org.opensearch.jobscheduler.spi.schedule.Schedule; import org.opensearch.rest.RestStatus; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.IntervalSchedule; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.Schedule; - /** * Anomaly detector job REST action handler to process POST/PUT request. */ diff --git a/src/main/java/org/opensearch/ad/settings/AnomalyDetectorSettings.java b/src/main/java/org/opensearch/ad/settings/AnomalyDetectorSettings.java index 3b572c4d6..1c5fbff31 100644 --- a/src/main/java/org/opensearch/ad/settings/AnomalyDetectorSettings.java +++ b/src/main/java/org/opensearch/ad/settings/AnomalyDetectorSettings.java @@ -40,8 +40,8 @@ private AnomalyDetectorSettings() {} public static final Setting MAX_SINGLE_ENTITY_ANOMALY_DETECTORS = Setting .intSetting( - "opendistro.anomaly_detection.max_anomaly_detectors", - 1000, + "plugins.anomaly_detection.max_anomaly_detectors", + LegacyOpenDistroAnomalyDetectorSettings.MAX_SINGLE_ENTITY_ANOMALY_DETECTORS, 0, 10_000, Setting.Property.NodeScope, @@ -50,8 +50,8 @@ private AnomalyDetectorSettings() {} public static final Setting MAX_MULTI_ENTITY_ANOMALY_DETECTORS = Setting .intSetting( - "opendistro.anomaly_detection.max_multi_entity_anomaly_detectors", - 10, + "plugins.anomaly_detection.max_multi_entity_anomaly_detectors", + LegacyOpenDistroAnomalyDetectorSettings.MAX_MULTI_ENTITY_ANOMALY_DETECTORS, 0, 10_000, Setting.Property.NodeScope, @@ -59,48 +59,55 @@ private AnomalyDetectorSettings() {} ); public static final Setting MAX_ANOMALY_FEATURES = Setting - .intSetting("opendistro.anomaly_detection.max_anomaly_features", 5, 0, 100, Setting.Property.NodeScope, Setting.Property.Dynamic); + .intSetting( + "plugins.anomaly_detection.max_anomaly_features", + LegacyOpenDistroAnomalyDetectorSettings.MAX_ANOMALY_FEATURES, + 0, + 100, + Setting.Property.NodeScope, + Setting.Property.Dynamic + ); public static final Setting REQUEST_TIMEOUT = Setting .positiveTimeSetting( - "opendistro.anomaly_detection.request_timeout", - TimeValue.timeValueSeconds(10), + "plugins.anomaly_detection.request_timeout", + LegacyOpenDistroAnomalyDetectorSettings.REQUEST_TIMEOUT, Setting.Property.NodeScope, Setting.Property.Dynamic ); public static final Setting DETECTION_INTERVAL = Setting .positiveTimeSetting( - "opendistro.anomaly_detection.detection_interval", - TimeValue.timeValueMinutes(10), + "plugins.anomaly_detection.detection_interval", + LegacyOpenDistroAnomalyDetectorSettings.DETECTION_INTERVAL, Setting.Property.NodeScope, Setting.Property.Dynamic ); public static final Setting DETECTION_WINDOW_DELAY = Setting .timeSetting( - "opendistro.anomaly_detection.detection_window_delay", - TimeValue.timeValueMinutes(0), + "plugins.anomaly_detection.detection_window_delay", + LegacyOpenDistroAnomalyDetectorSettings.DETECTION_WINDOW_DELAY, Setting.Property.NodeScope, Setting.Property.Dynamic ); public static final Setting AD_RESULT_HISTORY_ROLLOVER_PERIOD = Setting .positiveTimeSetting( - "opendistro.anomaly_detection.ad_result_history_rollover_period", - TimeValue.timeValueHours(12), + "plugins.anomaly_detection.ad_result_history_rollover_period", + LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_ROLLOVER_PERIOD, Setting.Property.NodeScope, Setting.Property.Dynamic ); public static final Setting AD_RESULT_HISTORY_MAX_DOCS = Setting .longSetting( - "opendistro.anomaly_detection.ad_result_history_max_docs", + "plugins.anomaly_detection.ad_result_history_max_docs", // Total documents in primary replica. // A single feature result is roughly 150 bytes. Suppose a doc is // of 200 bytes, 250 million docs is of 50 GB. We choose 50 GB // because we have 1 shard at least. One shard can have at most 50 GB. - 250_000_000L, + LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS, 0L, Setting.Property.NodeScope, Setting.Property.Dynamic @@ -108,16 +115,16 @@ private AnomalyDetectorSettings() {} public static final Setting AD_RESULT_HISTORY_RETENTION_PERIOD = Setting .positiveTimeSetting( - "opendistro.anomaly_detection.ad_result_history_retention_period", - TimeValue.timeValueDays(30), + "plugins.anomaly_detection.ad_result_history_retention_period", + LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_RETENTION_PERIOD, Setting.Property.NodeScope, Setting.Property.Dynamic ); public static final Setting MAX_RETRY_FOR_UNRESPONSIVE_NODE = Setting .intSetting( - "opendistro.anomaly_detection.max_retry_for_unresponsive_node", - 5, + "plugins.anomaly_detection.max_retry_for_unresponsive_node", + LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_UNRESPONSIVE_NODE, 0, Setting.Property.NodeScope, Setting.Property.Dynamic @@ -125,42 +132,53 @@ private AnomalyDetectorSettings() {} public static final Setting COOLDOWN_MINUTES = Setting .positiveTimeSetting( - "opendistro.anomaly_detection.cooldown_minutes", - TimeValue.timeValueMinutes(5), + "plugins.anomaly_detection.cooldown_minutes", + LegacyOpenDistroAnomalyDetectorSettings.COOLDOWN_MINUTES, Setting.Property.NodeScope, Setting.Property.Dynamic ); public static final Setting BACKOFF_MINUTES = Setting .positiveTimeSetting( - "opendistro.anomaly_detection.backoff_minutes", - TimeValue.timeValueMinutes(15), + "plugins.anomaly_detection.backoff_minutes", + LegacyOpenDistroAnomalyDetectorSettings.BACKOFF_MINUTES, Setting.Property.NodeScope, Setting.Property.Dynamic ); public static final Setting BACKOFF_INITIAL_DELAY = Setting .positiveTimeSetting( - "opendistro.anomaly_detection.backoff_initial_delay", - TimeValue.timeValueMillis(1000), + "plugins.anomaly_detection.backoff_initial_delay", + LegacyOpenDistroAnomalyDetectorSettings.BACKOFF_INITIAL_DELAY, Setting.Property.NodeScope, Setting.Property.Dynamic ); public static final Setting MAX_RETRY_FOR_BACKOFF = Setting - .intSetting("opendistro.anomaly_detection.max_retry_for_backoff", 3, 0, Setting.Property.NodeScope, Setting.Property.Dynamic); + .intSetting( + "plugins.anomaly_detection.max_retry_for_backoff", + LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_BACKOFF, + 0, + Setting.Property.NodeScope, + Setting.Property.Dynamic + ); public static final Setting MAX_RETRY_FOR_END_RUN_EXCEPTION = Setting .intSetting( - "opendistro.anomaly_detection.max_retry_for_end_run_exception", - 6, + "plugins.anomaly_detection.max_retry_for_end_run_exception", + LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_END_RUN_EXCEPTION, 0, Setting.Property.NodeScope, Setting.Property.Dynamic ); public static final Setting FILTER_BY_BACKEND_ROLES = Setting - .boolSetting("opendistro.anomaly_detection.filter_by_backend_roles", false, Setting.Property.NodeScope, Setting.Property.Dynamic); + .boolSetting( + "plugins.anomaly_detection.filter_by_backend_roles", + LegacyOpenDistroAnomalyDetectorSettings.FILTER_BY_BACKEND_ROLES, + Setting.Property.NodeScope, + Setting.Property.Dynamic + ); public static final String ANOMALY_DETECTORS_INDEX_MAPPING_FILE = "mappings/anomaly-detectors.json"; public static final String ANOMALY_DETECTOR_JOBS_INDEX_MAPPING_FILE = "mappings/anomaly-detector-jobs.json"; @@ -190,8 +208,8 @@ private AnomalyDetectorSettings() {} public static final Setting MODEL_MAX_SIZE_PERCENTAGE = Setting .doubleSetting( - "opendistro.anomaly_detection.model_max_size_percent", - 0.1, + "plugins.anomaly_detection.model_max_size_percent", + LegacyOpenDistroAnomalyDetectorSettings.MODEL_MAX_SIZE_PERCENTAGE, 0, 0.7, Setting.Property.NodeScope, @@ -272,8 +290,8 @@ private AnomalyDetectorSettings() {} // Increase the value will adding pressure to indexing anomaly results and our feature query public static final Setting MAX_ENTITIES_PER_QUERY = Setting .intSetting( - "opendistro.anomaly_detection.max_entities_per_query", - 1000, + "plugins.anomaly_detection.max_entities_per_query", + LegacyOpenDistroAnomalyDetectorSettings.MAX_ENTITIES_PER_QUERY, 1, 100_000_000, Setting.Property.NodeScope, @@ -286,8 +304,8 @@ private AnomalyDetectorSettings() {} // Maximum number of entities retrieved for Preview API public static final Setting MAX_ENTITIES_FOR_PREVIEW = Setting .intSetting( - "opendistro.anomaly_detection.max_entities_for_preview", - DEFAULT_ENTITIES_FOR_PREVIEW, + "plugins.anomaly_detection.max_entities_for_preview", + LegacyOpenDistroAnomalyDetectorSettings.MAX_ENTITIES_FOR_PREVIEW, 1, 1000, Setting.Property.NodeScope, @@ -297,8 +315,8 @@ private AnomalyDetectorSettings() {} // save partial zero-anomaly grade results after indexing pressure reaching the limit public static final Setting INDEX_PRESSURE_SOFT_LIMIT = Setting .floatSetting( - "opendistro.anomaly_detection.index_pressure_soft_limit", - 0.8f, + "plugins.anomaly_detection.index_pressure_soft_limit", + LegacyOpenDistroAnomalyDetectorSettings.INDEX_PRESSURE_SOFT_LIMIT, 0.0f, Setting.Property.NodeScope, Setting.Property.Dynamic @@ -306,7 +324,14 @@ private AnomalyDetectorSettings() {} // max number of primary shards of an AD index public static final Setting MAX_PRIMARY_SHARDS = Setting - .intSetting("opendistro.anomaly_detection.max_primary_shards", 10, 0, 200, Setting.Property.NodeScope, Setting.Property.Dynamic); + .intSetting( + "plugins.anomaly_detection.max_primary_shards", + LegacyOpenDistroAnomalyDetectorSettings.MAX_PRIMARY_SHARDS, + 0, + 200, + Setting.Property.NodeScope, + Setting.Property.Dynamic + ); // max entity value's length public static int MAX_ENTITY_LENGTH = 256; @@ -325,8 +350,8 @@ private AnomalyDetectorSettings() {} // but for 1 day interval, it will be 30 days. public static Setting MAX_CACHE_MISS_HANDLING_PER_SECOND = Setting .intSetting( - "opendistro.anomaly_detection.max_cache_miss_handling_per_second", - 100, + "plugins.anomaly_detection.max_cache_miss_handling_per_second", + LegacyOpenDistroAnomalyDetectorSettings.MAX_CACHE_MISS_HANDLING_PER_SECOND, 0, 1000, Setting.Property.NodeScope, @@ -337,8 +362,8 @@ private AnomalyDetectorSettings() {} // TODO: performance test and tune the setting. public static final Setting MAX_BATCH_TASK_PER_NODE = Setting .intSetting( - "opendistro.anomaly_detection.max_batch_task_per_node", - 2, + "plugins.anomaly_detection.max_batch_task_per_node", + LegacyOpenDistroAnomalyDetectorSettings.MAX_BATCH_TASK_PER_NODE, 1, 100, Setting.Property.NodeScope, @@ -349,11 +374,11 @@ private AnomalyDetectorSettings() {} public static final Setting MAX_OLD_AD_TASK_DOCS_PER_DETECTOR = Setting .intSetting( - "opendistro.anomaly_detection.max_old_ad_task_docs_per_detector", + "plugins.anomaly_detection.max_old_ad_task_docs_per_detector", // One AD task is roughly 1.5KB for normal case. Suppose task's size // is 2KB conservatively. If we store 1000 AD tasks for one detector, // that will be 2GB. - 10, + LegacyOpenDistroAnomalyDetectorSettings.MAX_OLD_AD_TASK_DOCS_PER_DETECTOR, 1, // keep at least 1 old AD task per detector 1000, Setting.Property.NodeScope, @@ -362,8 +387,8 @@ private AnomalyDetectorSettings() {} public static final Setting BATCH_TASK_PIECE_SIZE = Setting .intSetting( - "opendistro.anomaly_detection.batch_task_piece_size", - 1000, + "plugins.anomaly_detection.batch_task_piece_size", + LegacyOpenDistroAnomalyDetectorSettings.BATCH_TASK_PIECE_SIZE, 1, 10_000, Setting.Property.NodeScope, @@ -372,8 +397,8 @@ private AnomalyDetectorSettings() {} public static final Setting BATCH_TASK_PIECE_INTERVAL_SECONDS = Setting .intSetting( - "opendistro.anomaly_detection.batch_task_piece_interval_seconds", - 5, + "plugins.anomaly_detection.batch_task_piece_interval_seconds", + LegacyOpenDistroAnomalyDetectorSettings.BATCH_TASK_PIECE_INTERVAL_SECONDS, 1, 600, Setting.Property.NodeScope, diff --git a/src/main/java/org/opensearch/ad/settings/EnabledSetting.java b/src/main/java/org/opensearch/ad/settings/EnabledSetting.java index ac65c1b1a..7ff395d2a 100644 --- a/src/main/java/org/opensearch/ad/settings/EnabledSetting.java +++ b/src/main/java/org/opensearch/ad/settings/EnabledSetting.java @@ -27,6 +27,7 @@ package org.opensearch.ad.settings; import static java.util.Collections.unmodifiableMap; +import static org.opensearch.common.settings.Setting.Property.Deprecated; import static org.opensearch.common.settings.Setting.Property.Dynamic; import static org.opensearch.common.settings.Setting.Property.NodeScope; @@ -54,21 +55,39 @@ public class EnabledSetting { /** * Settings name */ - public static final String AD_PLUGIN_ENABLED = "opendistro.anomaly_detection.enabled"; + public static final String AD_PLUGIN_ENABLED = "plugins.anomaly_detection.enabled"; - public static final String AD_BREAKER_ENABLED = "opendistro.anomaly_detection.breaker.enabled"; + public static final String AD_BREAKER_ENABLED = "plugins.anomaly_detection.breaker.enabled"; + + public static final String LEGACY_OPENDISTRO_AD_PLUGIN_ENABLED = "opendistro.anomaly_detection.enabled"; + + public static final String LEGACY_OPENDISTRO_AD_BREAKER_ENABLED = "opendistro.anomaly_detection.breaker.enabled"; private final Map> settings = unmodifiableMap(new HashMap>() { { + Setting LegacyADPluginEnabledSetting = Setting + .boolSetting(LEGACY_OPENDISTRO_AD_PLUGIN_ENABLED, true, NodeScope, Dynamic, Deprecated); + /** + * Legacy OpenDistro AD plugin enable/disable setting + */ + put(LEGACY_OPENDISTRO_AD_PLUGIN_ENABLED, LegacyADPluginEnabledSetting); + + Setting LegacyADBreakerEnabledSetting = Setting + .boolSetting(LEGACY_OPENDISTRO_AD_BREAKER_ENABLED, true, NodeScope, Dynamic, Deprecated); + /** + * Legacy OpenDistro AD breaker enable/disable setting + */ + put(LEGACY_OPENDISTRO_AD_BREAKER_ENABLED, LegacyADBreakerEnabledSetting); + /** * AD plugin enable/disable setting */ - put(AD_PLUGIN_ENABLED, Setting.boolSetting(AD_PLUGIN_ENABLED, true, NodeScope, Dynamic)); + put(AD_PLUGIN_ENABLED, Setting.boolSetting(AD_PLUGIN_ENABLED, LegacyADPluginEnabledSetting, NodeScope, Dynamic)); /** * AD breaker enable/disable setting */ - put(AD_BREAKER_ENABLED, Setting.boolSetting(AD_BREAKER_ENABLED, true, NodeScope, Dynamic)); + put(AD_BREAKER_ENABLED, Setting.boolSetting(AD_BREAKER_ENABLED, LegacyADBreakerEnabledSetting, NodeScope, Dynamic)); } }); diff --git a/src/main/java/org/opensearch/ad/settings/LegacyOpenDistroAnomalyDetectorSettings.java b/src/main/java/org/opensearch/ad/settings/LegacyOpenDistroAnomalyDetectorSettings.java new file mode 100644 index 000000000..955c23fd7 --- /dev/null +++ b/src/main/java/org/opensearch/ad/settings/LegacyOpenDistroAnomalyDetectorSettings.java @@ -0,0 +1,327 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.opensearch.ad.settings; + +import org.opensearch.common.settings.Setting; +import org.opensearch.common.unit.TimeValue; + +/** + * Legacy OpenDistro AD plugin settings. + */ +public class LegacyOpenDistroAnomalyDetectorSettings { + + private LegacyOpenDistroAnomalyDetectorSettings() {} + + public static final Setting MAX_SINGLE_ENTITY_ANOMALY_DETECTORS = Setting + .intSetting( + "opendistro.anomaly_detection.max_anomaly_detectors", + 1000, + 0, + 10_000, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting MAX_MULTI_ENTITY_ANOMALY_DETECTORS = Setting + .intSetting( + "opendistro.anomaly_detection.max_multi_entity_anomaly_detectors", + 10, + 0, + 10_000, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting MAX_ANOMALY_FEATURES = Setting + .intSetting( + "opendistro.anomaly_detection.max_anomaly_features", + 5, + 0, + 100, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting REQUEST_TIMEOUT = Setting + .positiveTimeSetting( + "opendistro.anomaly_detection.request_timeout", + TimeValue.timeValueSeconds(10), + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting DETECTION_INTERVAL = Setting + .positiveTimeSetting( + "opendistro.anomaly_detection.detection_interval", + TimeValue.timeValueMinutes(10), + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting DETECTION_WINDOW_DELAY = Setting + .timeSetting( + "opendistro.anomaly_detection.detection_window_delay", + TimeValue.timeValueMinutes(0), + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting AD_RESULT_HISTORY_ROLLOVER_PERIOD = Setting + .positiveTimeSetting( + "opendistro.anomaly_detection.ad_result_history_rollover_period", + TimeValue.timeValueHours(12), + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting AD_RESULT_HISTORY_MAX_DOCS = Setting + .longSetting( + "opendistro.anomaly_detection.ad_result_history_max_docs", + // Total documents in primary replica. + // A single feature result is roughly 150 bytes. Suppose a doc is + // of 200 bytes, 250 million docs is of 50 GB. We choose 50 GB + // because we have 1 shard at least. One shard can have at most 50 GB. + 250_000_000L, + 0L, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting AD_RESULT_HISTORY_RETENTION_PERIOD = Setting + .positiveTimeSetting( + "opendistro.anomaly_detection.ad_result_history_retention_period", + TimeValue.timeValueDays(30), + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting MAX_RETRY_FOR_UNRESPONSIVE_NODE = Setting + .intSetting( + "opendistro.anomaly_detection.max_retry_for_unresponsive_node", + 5, + 0, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting COOLDOWN_MINUTES = Setting + .positiveTimeSetting( + "opendistro.anomaly_detection.cooldown_minutes", + TimeValue.timeValueMinutes(5), + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting BACKOFF_MINUTES = Setting + .positiveTimeSetting( + "opendistro.anomaly_detection.backoff_minutes", + TimeValue.timeValueMinutes(15), + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting BACKOFF_INITIAL_DELAY = Setting + .positiveTimeSetting( + "opendistro.anomaly_detection.backoff_initial_delay", + TimeValue.timeValueMillis(1000), + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting MAX_RETRY_FOR_BACKOFF = Setting + .intSetting( + "opendistro.anomaly_detection.max_retry_for_backoff", + 3, + 0, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting MAX_RETRY_FOR_END_RUN_EXCEPTION = Setting + .intSetting( + "opendistro.anomaly_detection.max_retry_for_end_run_exception", + 6, + 0, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting FILTER_BY_BACKEND_ROLES = Setting + .boolSetting( + "opendistro.anomaly_detection.filter_by_backend_roles", + false, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + // ====================================== + // ML parameters + // ====================================== + // RCF + public static final Setting MODEL_MAX_SIZE_PERCENTAGE = Setting + .doubleSetting( + "opendistro.anomaly_detection.model_max_size_percent", + 0.1, + 0, + 0.7, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + // Increase the value will adding pressure to indexing anomaly results and our feature query + public static final Setting MAX_ENTITIES_PER_QUERY = Setting + .intSetting( + "opendistro.anomaly_detection.max_entities_per_query", + 1000, + 1, + 100_000_000, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + // Default number of entities retrieved for Preview API + public static final int DEFAULT_ENTITIES_FOR_PREVIEW = 30; + + // Maximum number of entities retrieved for Preview API + public static final Setting MAX_ENTITIES_FOR_PREVIEW = Setting + .intSetting( + "opendistro.anomaly_detection.max_entities_for_preview", + DEFAULT_ENTITIES_FOR_PREVIEW, + 1, + 1000, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + // save partial zero-anomaly grade results after indexing pressure reaching the limit + public static final Setting INDEX_PRESSURE_SOFT_LIMIT = Setting + .floatSetting( + "opendistro.anomaly_detection.index_pressure_soft_limit", + 0.8f, + 0.0f, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + // max number of primary shards of an AD index + public static final Setting MAX_PRIMARY_SHARDS = Setting + .intSetting( + "opendistro.anomaly_detection.max_primary_shards", + 10, + 0, + 200, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + // responding to 100 cache misses per second allowed. + // 100 because the get threadpool (the one we need to get checkpoint) queue szie is 1000 + // and we may have 10 concurrent multi-entity detectors. So each detector can use: 1000 / 10 = 100 + // for 1m interval. if the max entity number is 3000 per node, it will need around 30m to get all of them cached + // Thus, for 5m internval, it will need 2.5 hours to cache all of them. for 1hour interval, it will be 30hours. + // but for 1 day interval, it will be 30 days. + public static Setting MAX_CACHE_MISS_HANDLING_PER_SECOND = Setting + .intSetting( + "opendistro.anomaly_detection.max_cache_miss_handling_per_second", + 100, + 0, + 1000, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + // Maximum number of batch tasks running on one node. + // TODO: performance test and tune the setting. + public static final Setting MAX_BATCH_TASK_PER_NODE = Setting + .intSetting( + "opendistro.anomaly_detection.max_batch_task_per_node", + 2, + 1, + 100, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting MAX_OLD_AD_TASK_DOCS_PER_DETECTOR = Setting + .intSetting( + "opendistro.anomaly_detection.max_old_ad_task_docs_per_detector", + // One AD task is roughly 1.5KB for normal case. Suppose task's size + // is 2KB conservatively. If we store 1000 AD tasks for one detector, + // that will be 2GB. + 10, + 1, // keep at least 1 old AD task per detector + 1000, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting BATCH_TASK_PIECE_SIZE = Setting + .intSetting( + "opendistro.anomaly_detection.batch_task_piece_size", + 1000, + 1, + 10_000, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); + + public static final Setting BATCH_TASK_PIECE_INTERVAL_SECONDS = Setting + .intSetting( + "opendistro.anomaly_detection.batch_task_piece_interval_seconds", + 5, + 1, + 600, + Setting.Property.NodeScope, + Setting.Property.Dynamic, + Setting.Property.Deprecated + ); +} diff --git a/src/main/java/org/opensearch/ad/task/ADTaskManager.java b/src/main/java/org/opensearch/ad/task/ADTaskManager.java index af1488e05..86b909b4f 100644 --- a/src/main/java/org/opensearch/ad/task/ADTaskManager.java +++ b/src/main/java/org/opensearch/ad/task/ADTaskManager.java @@ -109,6 +109,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.commons.authuser.User; import org.opensearch.index.IndexNotFoundException; import org.opensearch.index.query.BoolQueryBuilder; import org.opensearch.index.query.RangeQueryBuilder; @@ -125,8 +126,6 @@ import org.opensearch.transport.TransportRequestOptions; import org.opensearch.transport.TransportService; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; - /** * Manage AD task. */ diff --git a/src/main/java/org/opensearch/ad/transport/AnomalyDetectorJobTransportAction.java b/src/main/java/org/opensearch/ad/transport/AnomalyDetectorJobTransportAction.java index 5cc1d54dc..05fbb7806 100644 --- a/src/main/java/org/opensearch/ad/transport/AnomalyDetectorJobTransportAction.java +++ b/src/main/java/org/opensearch/ad/transport/AnomalyDetectorJobTransportAction.java @@ -47,11 +47,10 @@ import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.NamedXContentRegistry; +import org.opensearch.commons.authuser.User; import org.opensearch.tasks.Task; import org.opensearch.transport.TransportService; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; - public class AnomalyDetectorJobTransportAction extends HandledTransportAction { private final Logger logger = LogManager.getLogger(AnomalyDetectorJobTransportAction.class); diff --git a/src/main/java/org/opensearch/ad/transport/DeleteAnomalyDetectorTransportAction.java b/src/main/java/org/opensearch/ad/transport/DeleteAnomalyDetectorTransportAction.java index 09a4cea6a..23528ae25 100644 --- a/src/main/java/org/opensearch/ad/transport/DeleteAnomalyDetectorTransportAction.java +++ b/src/main/java/org/opensearch/ad/transport/DeleteAnomalyDetectorTransportAction.java @@ -60,13 +60,12 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.commons.authuser.User; import org.opensearch.index.IndexNotFoundException; import org.opensearch.rest.RestStatus; import org.opensearch.tasks.Task; import org.opensearch.transport.TransportService; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; - public class DeleteAnomalyDetectorTransportAction extends HandledTransportAction { private static final Logger LOG = LogManager.getLogger(DeleteAnomalyDetectorTransportAction.class); diff --git a/src/main/java/org/opensearch/ad/transport/ForwardADTaskRequest.java b/src/main/java/org/opensearch/ad/transport/ForwardADTaskRequest.java index 748761bf1..d3eec2e60 100644 --- a/src/main/java/org/opensearch/ad/transport/ForwardADTaskRequest.java +++ b/src/main/java/org/opensearch/ad/transport/ForwardADTaskRequest.java @@ -37,8 +37,7 @@ import org.opensearch.ad.model.AnomalyDetector; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; - -import com.amazon.opendistroforelasticsearch.commons.authuser.User; +import org.opensearch.commons.authuser.User; public class ForwardADTaskRequest extends ActionRequest { private AnomalyDetector detector; diff --git a/src/main/java/org/opensearch/ad/transport/GetAnomalyDetectorTransportAction.java b/src/main/java/org/opensearch/ad/transport/GetAnomalyDetectorTransportAction.java index 49dbdc3f0..0507fbe5c 100644 --- a/src/main/java/org/opensearch/ad/transport/GetAnomalyDetectorTransportAction.java +++ b/src/main/java/org/opensearch/ad/transport/GetAnomalyDetectorTransportAction.java @@ -73,11 +73,11 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.commons.authuser.User; import org.opensearch.rest.RestStatus; import org.opensearch.tasks.Task; import org.opensearch.transport.TransportService; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; import com.google.common.collect.Sets; public class GetAnomalyDetectorTransportAction extends HandledTransportAction { diff --git a/src/main/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportAction.java b/src/main/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportAction.java index 43337a81e..8fafba19d 100644 --- a/src/main/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportAction.java +++ b/src/main/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportAction.java @@ -54,14 +54,13 @@ import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.NamedXContentRegistry; +import org.opensearch.commons.authuser.User; import org.opensearch.index.query.QueryBuilders; import org.opensearch.rest.RestRequest; import org.opensearch.search.builder.SearchSourceBuilder; import org.opensearch.tasks.Task; import org.opensearch.transport.TransportService; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; - public class IndexAnomalyDetectorTransportAction extends HandledTransportAction { private static final Logger LOG = LogManager.getLogger(IndexAnomalyDetectorTransportAction.class); private final Client client; diff --git a/src/main/java/org/opensearch/ad/transport/PreviewAnomalyDetectorTransportAction.java b/src/main/java/org/opensearch/ad/transport/PreviewAnomalyDetectorTransportAction.java index 719d5d034..4aa62efcb 100644 --- a/src/main/java/org/opensearch/ad/transport/PreviewAnomalyDetectorTransportAction.java +++ b/src/main/java/org/opensearch/ad/transport/PreviewAnomalyDetectorTransportAction.java @@ -58,12 +58,11 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.commons.authuser.User; import org.opensearch.rest.RestStatus; import org.opensearch.tasks.Task; import org.opensearch.transport.TransportService; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; - public class PreviewAnomalyDetectorTransportAction extends HandledTransportAction { private final Logger logger = LogManager.getLogger(PreviewAnomalyDetectorTransportAction.class); diff --git a/src/main/java/org/opensearch/ad/transport/handler/ADSearchHandler.java b/src/main/java/org/opensearch/ad/transport/handler/ADSearchHandler.java index 2e6e308a5..6bb15006c 100644 --- a/src/main/java/org/opensearch/ad/transport/handler/ADSearchHandler.java +++ b/src/main/java/org/opensearch/ad/transport/handler/ADSearchHandler.java @@ -40,8 +40,7 @@ import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext; - -import com.amazon.opendistroforelasticsearch.commons.authuser.User; +import org.opensearch.commons.authuser.User; /** * Handle general search request, check user role and return search response. diff --git a/src/main/java/org/opensearch/ad/util/ParseUtils.java b/src/main/java/org/opensearch/ad/util/ParseUtils.java index 0e5d9cc35..ab3454f0b 100644 --- a/src/main/java/org/opensearch/ad/util/ParseUtils.java +++ b/src/main/java/org/opensearch/ad/util/ParseUtils.java @@ -68,6 +68,8 @@ import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; +import org.opensearch.commons.ConfigConstants; +import org.opensearch.commons.authuser.User; import org.opensearch.index.query.BoolQueryBuilder; import org.opensearch.index.query.NestedQueryBuilder; import org.opensearch.index.query.QueryBuilder; @@ -87,8 +89,6 @@ import org.opensearch.search.aggregations.metrics.Max; import org.opensearch.search.builder.SearchSourceBuilder; -import com.amazon.opendistroforelasticsearch.commons.ConfigConstants; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; import com.google.common.collect.ImmutableList; /** @@ -459,7 +459,7 @@ public static SearchSourceBuilder addUserBackendRolesFilter(User user, SearchSou } public static User getUserContext(Client client) { - String userStr = client.threadPool().getThreadContext().getTransient(ConfigConstants.OPENDISTRO_SECURITY_USER_INFO_THREAD_CONTEXT); + String userStr = client.threadPool().getThreadContext().getTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT); logger.debug("Filtering result by " + userStr); return User.parse(userStr); } diff --git a/src/test/java/org/opensearch/ad/AnomalyDetectorJobRunnerTests.java b/src/test/java/org/opensearch/ad/AnomalyDetectorJobRunnerTests.java index de8ebc5e9..d6642fed5 100644 --- a/src/test/java/org/opensearch/ad/AnomalyDetectorJobRunnerTests.java +++ b/src/test/java/org/opensearch/ad/AnomalyDetectorJobRunnerTests.java @@ -83,15 +83,14 @@ import org.opensearch.index.get.GetResult; import org.opensearch.index.mapper.MapperService; import org.opensearch.index.shard.ShardId; +import org.opensearch.jobscheduler.spi.JobExecutionContext; +import org.opensearch.jobscheduler.spi.LockModel; +import org.opensearch.jobscheduler.spi.ScheduledJobParameter; +import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule; +import org.opensearch.jobscheduler.spi.schedule.Schedule; +import org.opensearch.jobscheduler.spi.utils.LockService; import org.opensearch.threadpool.ThreadPool; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.JobExecutionContext; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.LockModel; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.ScheduledJobParameter; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.IntervalSchedule; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.Schedule; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.utils.LockService; - public class AnomalyDetectorJobRunnerTests extends AbstractADTest { @Mock @@ -157,9 +156,9 @@ public void setup() throws Exception { Settings settings = Settings .builder() - .put("opendistro.anomaly_detection.max_retry_for_backoff", 2) - .put("opendistro.anomaly_detection.backoff_initial_delay", TimeValue.timeValueMillis(1)) - .put("opendistro.anomaly_detection.max_retry_for_end_run_exception", 3) + .put("plugins.anomaly_detection.max_retry_for_backoff", 2) + .put("plugins.anomaly_detection.backoff_initial_delay", TimeValue.timeValueMillis(1)) + .put("plugins.anomaly_detection.max_retry_for_end_run_exception", 3) .build(); setUpJobParameter(); diff --git a/src/test/java/org/opensearch/ad/NodeStateManagerTests.java b/src/test/java/org/opensearch/ad/NodeStateManagerTests.java index 8d26b87e1..41c71c565 100644 --- a/src/test/java/org/opensearch/ad/NodeStateManagerTests.java +++ b/src/test/java/org/opensearch/ad/NodeStateManagerTests.java @@ -95,8 +95,8 @@ public void setUp() throws Exception { client = mock(Client.class); settings = Settings .builder() - .put("opendistro.anomaly_detection.max_retry_for_unresponsive_node", 3) - .put("opendistro.anomaly_detection.ad_mute_minutes", TimeValue.timeValueMinutes(10)) + .put("plugins.anomaly_detection.max_retry_for_unresponsive_node", 3) + .put("plugins.anomaly_detection.ad_mute_minutes", TimeValue.timeValueMinutes(10)) .build(); clock = mock(Clock.class); duration = Duration.ofHours(1); diff --git a/src/test/java/org/opensearch/ad/ODFERestTestCase.java b/src/test/java/org/opensearch/ad/ODFERestTestCase.java index edda5359a..52ff8860b 100644 --- a/src/test/java/org/opensearch/ad/ODFERestTestCase.java +++ b/src/test/java/org/opensearch/ad/ODFERestTestCase.java @@ -26,11 +26,11 @@ package org.opensearch.ad; -import static com.amazon.opendistroforelasticsearch.commons.ConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_ENABLED; -import static com.amazon.opendistroforelasticsearch.commons.ConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH; -import static com.amazon.opendistroforelasticsearch.commons.ConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD; -import static com.amazon.opendistroforelasticsearch.commons.ConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_KEYSTORE_PASSWORD; -import static com.amazon.opendistroforelasticsearch.commons.ConfigConstants.OPENDISTRO_SECURITY_SSL_HTTP_PEMCERT_FILEPATH; +import static org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_ENABLED; +import static org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH; +import static org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD; +import static org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_PASSWORD; +import static org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_PEMCERT_FILEPATH; import java.io.IOException; import java.net.URI; @@ -65,10 +65,9 @@ import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; +import org.opensearch.commons.rest.SecureRestClientBuilder; import org.opensearch.test.rest.OpenSearchRestTestCase; -import com.amazon.opendistroforelasticsearch.commons.rest.SecureRestClientBuilder; - /** * ODFE integration test base class to support both security disabled and enabled ODFE cluster. */ @@ -98,11 +97,11 @@ protected Settings restAdminSettings() { // disable the warning exception for admin client since it's only used for cleanup. .put("strictDeprecationMode", false) .put("http.port", 9200) - .put(OPENDISTRO_SECURITY_SSL_HTTP_ENABLED, isHttps()) - .put(OPENDISTRO_SECURITY_SSL_HTTP_PEMCERT_FILEPATH, "sample.pem") - .put(OPENDISTRO_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH, "test-kirk.jks") - .put(OPENDISTRO_SECURITY_SSL_HTTP_KEYSTORE_PASSWORD, "changeit") - .put(OPENDISTRO_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD, "changeit") + .put(OPENSEARCH_SECURITY_SSL_HTTP_ENABLED, isHttps()) + .put(OPENSEARCH_SECURITY_SSL_HTTP_PEMCERT_FILEPATH, "sample.pem") + .put(OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH, "test-kirk.jks") + .put(OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_PASSWORD, "changeit") + .put(OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD, "changeit") .build(); } @@ -116,7 +115,7 @@ protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOE boolean strictDeprecationMode = settings.getAsBoolean("strictDeprecationMode", true); RestClientBuilder builder = RestClient.builder(hosts); if (isHttps()) { - String keystore = settings.get(OPENDISTRO_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH); + String keystore = settings.get(OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH); if (Objects.nonNull(keystore)) { URI uri = null; try { diff --git a/src/test/java/org/opensearch/ad/TestHelpers.java b/src/test/java/org/opensearch/ad/TestHelpers.java index 3ee749871..c1bb33590 100644 --- a/src/test/java/org/opensearch/ad/TestHelpers.java +++ b/src/test/java/org/opensearch/ad/TestHelpers.java @@ -127,11 +127,13 @@ import org.opensearch.common.xcontent.XContentHelper; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; +import org.opensearch.commons.authuser.User; import org.opensearch.index.get.GetResult; import org.opensearch.index.mapper.MapperService; import org.opensearch.index.query.BoolQueryBuilder; import org.opensearch.index.query.MatchAllQueryBuilder; import org.opensearch.index.query.QueryBuilder; +import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule; import org.opensearch.search.SearchHit; import org.opensearch.search.SearchHits; import org.opensearch.search.SearchModule; @@ -147,8 +149,6 @@ import org.opensearch.test.rest.OpenSearchRestTestCase; import org.opensearch.threadpool.ThreadPool; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; -import com.amazon.opendistroforelasticsearch.jobscheduler.spi.schedule.IntervalSchedule; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; diff --git a/src/test/java/org/opensearch/ad/mock/transport/MockAnomalyDetectorJobTransportActionWithUser.java b/src/test/java/org/opensearch/ad/mock/transport/MockAnomalyDetectorJobTransportActionWithUser.java index 867f3f00f..a00106d50 100644 --- a/src/test/java/org/opensearch/ad/mock/transport/MockAnomalyDetectorJobTransportActionWithUser.java +++ b/src/test/java/org/opensearch/ad/mock/transport/MockAnomalyDetectorJobTransportActionWithUser.java @@ -49,11 +49,10 @@ import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.NamedXContentRegistry; +import org.opensearch.commons.authuser.User; import org.opensearch.tasks.Task; import org.opensearch.transport.TransportService; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; - public class MockAnomalyDetectorJobTransportActionWithUser extends HandledTransportAction { private final Logger logger = LogManager.getLogger(AnomalyDetectorJobTransportAction.class); diff --git a/src/test/java/org/opensearch/ad/rest/SecureADRestIT.java b/src/test/java/org/opensearch/ad/rest/SecureADRestIT.java index 0b0b57da6..d15353945 100644 --- a/src/test/java/org/opensearch/ad/rest/SecureADRestIT.java +++ b/src/test/java/org/opensearch/ad/rest/SecureADRestIT.java @@ -40,10 +40,9 @@ import org.opensearch.ad.model.AnomalyDetectorExecutionInput; import org.opensearch.client.Response; import org.opensearch.client.RestClient; +import org.opensearch.commons.rest.SecureRestClientBuilder; import org.opensearch.rest.RestStatus; -import com.amazon.opendistroforelasticsearch.commons.rest.SecureRestClientBuilder; - public class SecureADRestIT extends AnomalyDetectorRestTestCase { String aliceUser = "alice"; RestClient aliceClient; diff --git a/src/test/java/org/opensearch/ad/settings/AnomalyDetectorSettingsTests.java b/src/test/java/org/opensearch/ad/settings/AnomalyDetectorSettingsTests.java new file mode 100644 index 000000000..3b51722db --- /dev/null +++ b/src/test/java/org/opensearch/ad/settings/AnomalyDetectorSettingsTests.java @@ -0,0 +1,427 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package org.opensearch.ad.settings; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Before; +import org.opensearch.ad.AnomalyDetectorPlugin; +import org.opensearch.common.settings.Setting; +import org.opensearch.common.settings.Settings; +import org.opensearch.common.unit.TimeValue; +import org.opensearch.test.OpenSearchTestCase; + +@SuppressWarnings({ "rawtypes" }) +public class AnomalyDetectorSettingsTests extends OpenSearchTestCase { + AnomalyDetectorPlugin plugin; + + @Before + public void setup() { + this.plugin = new AnomalyDetectorPlugin(); + } + + public void testAllLegacyOpenDistroSettingsReturned() { + List> settings = plugin.getSettings(); + assertTrue( + "legacy setting must be returned from settings", + settings + .containsAll( + Arrays + .asList( + LegacyOpenDistroAnomalyDetectorSettings.MAX_SINGLE_ENTITY_ANOMALY_DETECTORS, + LegacyOpenDistroAnomalyDetectorSettings.MAX_MULTI_ENTITY_ANOMALY_DETECTORS, + LegacyOpenDistroAnomalyDetectorSettings.MAX_ANOMALY_FEATURES, + LegacyOpenDistroAnomalyDetectorSettings.REQUEST_TIMEOUT, + LegacyOpenDistroAnomalyDetectorSettings.DETECTION_INTERVAL, + LegacyOpenDistroAnomalyDetectorSettings.DETECTION_WINDOW_DELAY, + LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_ROLLOVER_PERIOD, + LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS, + LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_UNRESPONSIVE_NODE, + LegacyOpenDistroAnomalyDetectorSettings.COOLDOWN_MINUTES, + LegacyOpenDistroAnomalyDetectorSettings.BACKOFF_MINUTES, + LegacyOpenDistroAnomalyDetectorSettings.BACKOFF_INITIAL_DELAY, + LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_BACKOFF, + LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_RETENTION_PERIOD, + LegacyOpenDistroAnomalyDetectorSettings.MODEL_MAX_SIZE_PERCENTAGE, + LegacyOpenDistroAnomalyDetectorSettings.MAX_ENTITIES_PER_QUERY, + LegacyOpenDistroAnomalyDetectorSettings.MAX_ENTITIES_FOR_PREVIEW, + LegacyOpenDistroAnomalyDetectorSettings.INDEX_PRESSURE_SOFT_LIMIT, + LegacyOpenDistroAnomalyDetectorSettings.MAX_PRIMARY_SHARDS, + LegacyOpenDistroAnomalyDetectorSettings.FILTER_BY_BACKEND_ROLES, + LegacyOpenDistroAnomalyDetectorSettings.MAX_CACHE_MISS_HANDLING_PER_SECOND, + LegacyOpenDistroAnomalyDetectorSettings.MAX_BATCH_TASK_PER_NODE, + LegacyOpenDistroAnomalyDetectorSettings.BATCH_TASK_PIECE_INTERVAL_SECONDS, + LegacyOpenDistroAnomalyDetectorSettings.MAX_OLD_AD_TASK_DOCS_PER_DETECTOR, + LegacyOpenDistroAnomalyDetectorSettings.BATCH_TASK_PIECE_SIZE + ) + ) + ); + } + + public void testAllOpenSearchSettingsReturned() { + List> settings = plugin.getSettings(); + assertTrue( + "legacy setting must be returned from settings", + settings + .containsAll( + Arrays + .asList( + AnomalyDetectorSettings.MAX_SINGLE_ENTITY_ANOMALY_DETECTORS, + AnomalyDetectorSettings.MAX_MULTI_ENTITY_ANOMALY_DETECTORS, + AnomalyDetectorSettings.MAX_ANOMALY_FEATURES, + AnomalyDetectorSettings.REQUEST_TIMEOUT, + AnomalyDetectorSettings.DETECTION_INTERVAL, + AnomalyDetectorSettings.DETECTION_WINDOW_DELAY, + AnomalyDetectorSettings.AD_RESULT_HISTORY_ROLLOVER_PERIOD, + AnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS, + AnomalyDetectorSettings.MAX_RETRY_FOR_UNRESPONSIVE_NODE, + AnomalyDetectorSettings.COOLDOWN_MINUTES, + AnomalyDetectorSettings.BACKOFF_MINUTES, + AnomalyDetectorSettings.BACKOFF_INITIAL_DELAY, + AnomalyDetectorSettings.MAX_RETRY_FOR_BACKOFF, + AnomalyDetectorSettings.AD_RESULT_HISTORY_RETENTION_PERIOD, + AnomalyDetectorSettings.MODEL_MAX_SIZE_PERCENTAGE, + AnomalyDetectorSettings.MAX_ENTITIES_PER_QUERY, + AnomalyDetectorSettings.MAX_ENTITIES_FOR_PREVIEW, + AnomalyDetectorSettings.INDEX_PRESSURE_SOFT_LIMIT, + AnomalyDetectorSettings.MAX_PRIMARY_SHARDS, + AnomalyDetectorSettings.FILTER_BY_BACKEND_ROLES, + AnomalyDetectorSettings.MAX_CACHE_MISS_HANDLING_PER_SECOND, + AnomalyDetectorSettings.MAX_BATCH_TASK_PER_NODE, + AnomalyDetectorSettings.BATCH_TASK_PIECE_INTERVAL_SECONDS, + AnomalyDetectorSettings.MAX_OLD_AD_TASK_DOCS_PER_DETECTOR, + AnomalyDetectorSettings.BATCH_TASK_PIECE_SIZE + ) + ) + ); + } + + public void testAllLegacyOpenDistroSettingsFallback() { + assertEquals( + AnomalyDetectorSettings.MAX_SINGLE_ENTITY_ANOMALY_DETECTORS.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.MAX_SINGLE_ENTITY_ANOMALY_DETECTORS.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.MAX_MULTI_ENTITY_ANOMALY_DETECTORS.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.MAX_MULTI_ENTITY_ANOMALY_DETECTORS.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.MAX_ANOMALY_FEATURES.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.MAX_ANOMALY_FEATURES.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.REQUEST_TIMEOUT.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.REQUEST_TIMEOUT.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.DETECTION_INTERVAL.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.DETECTION_INTERVAL.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.DETECTION_WINDOW_DELAY.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.DETECTION_WINDOW_DELAY.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.AD_RESULT_HISTORY_ROLLOVER_PERIOD.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_ROLLOVER_PERIOD.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.MAX_RETRY_FOR_UNRESPONSIVE_NODE.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_UNRESPONSIVE_NODE.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.COOLDOWN_MINUTES.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.COOLDOWN_MINUTES.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.BACKOFF_MINUTES.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.BACKOFF_MINUTES.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.BACKOFF_INITIAL_DELAY.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.BACKOFF_INITIAL_DELAY.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.MAX_RETRY_FOR_BACKOFF.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_BACKOFF.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.AD_RESULT_HISTORY_RETENTION_PERIOD.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_RETENTION_PERIOD.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.MODEL_MAX_SIZE_PERCENTAGE.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.MODEL_MAX_SIZE_PERCENTAGE.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.MAX_ENTITIES_PER_QUERY.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.MAX_ENTITIES_PER_QUERY.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.MAX_ENTITIES_FOR_PREVIEW.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.MAX_ENTITIES_FOR_PREVIEW.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.INDEX_PRESSURE_SOFT_LIMIT.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.INDEX_PRESSURE_SOFT_LIMIT.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.MAX_PRIMARY_SHARDS.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.MAX_PRIMARY_SHARDS.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.FILTER_BY_BACKEND_ROLES.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.FILTER_BY_BACKEND_ROLES.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.MAX_CACHE_MISS_HANDLING_PER_SECOND.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.MAX_CACHE_MISS_HANDLING_PER_SECOND.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.MAX_BATCH_TASK_PER_NODE.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.MAX_BATCH_TASK_PER_NODE.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.BATCH_TASK_PIECE_INTERVAL_SECONDS.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.BATCH_TASK_PIECE_INTERVAL_SECONDS.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.MAX_OLD_AD_TASK_DOCS_PER_DETECTOR.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.MAX_OLD_AD_TASK_DOCS_PER_DETECTOR.get(Settings.EMPTY) + ); + assertEquals( + AnomalyDetectorSettings.BATCH_TASK_PIECE_SIZE.get(Settings.EMPTY), + LegacyOpenDistroAnomalyDetectorSettings.BATCH_TASK_PIECE_SIZE.get(Settings.EMPTY) + ); + } + + public void testSettingsGetValue() { + Settings settings = Settings.builder().put("plugins.anomaly_detection.request_timeout", "42s").build(); + assertEquals(AnomalyDetectorSettings.REQUEST_TIMEOUT.get(settings), TimeValue.timeValueSeconds(42)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.REQUEST_TIMEOUT.get(settings), TimeValue.timeValueSeconds(10)); + + settings = Settings.builder().put("plugins.anomaly_detection.max_anomaly_detectors", 99).build(); + assertEquals(AnomalyDetectorSettings.MAX_SINGLE_ENTITY_ANOMALY_DETECTORS.get(settings), Integer.valueOf(99)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.MAX_SINGLE_ENTITY_ANOMALY_DETECTORS.get(settings), Integer.valueOf(1000)); + + settings = Settings.builder().put("plugins.anomaly_detection.max_multi_entity_anomaly_detectors", 98).build(); + assertEquals(AnomalyDetectorSettings.MAX_MULTI_ENTITY_ANOMALY_DETECTORS.get(settings), Integer.valueOf(98)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.MAX_MULTI_ENTITY_ANOMALY_DETECTORS.get(settings), Integer.valueOf(10)); + + settings = Settings.builder().put("plugins.anomaly_detection.max_anomaly_features", 97).build(); + assertEquals(AnomalyDetectorSettings.MAX_ANOMALY_FEATURES.get(settings), Integer.valueOf(97)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.MAX_ANOMALY_FEATURES.get(settings), Integer.valueOf(5)); + + settings = Settings.builder().put("plugins.anomaly_detection.detection_interval", TimeValue.timeValueMinutes(96)).build(); + assertEquals(AnomalyDetectorSettings.DETECTION_INTERVAL.get(settings), TimeValue.timeValueMinutes(96)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.DETECTION_INTERVAL.get(settings), TimeValue.timeValueMinutes(10)); + + settings = Settings.builder().put("plugins.anomaly_detection.detection_window_delay", TimeValue.timeValueMinutes(95)).build(); + assertEquals(AnomalyDetectorSettings.DETECTION_WINDOW_DELAY.get(settings), TimeValue.timeValueMinutes(95)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.DETECTION_WINDOW_DELAY.get(settings), TimeValue.timeValueMinutes(0)); + + settings = Settings + .builder() + .put("plugins.anomaly_detection.ad_result_history_rollover_period", TimeValue.timeValueHours(94)) + .build(); + assertEquals(AnomalyDetectorSettings.AD_RESULT_HISTORY_ROLLOVER_PERIOD.get(settings), TimeValue.timeValueHours(94)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_ROLLOVER_PERIOD.get(settings), TimeValue.timeValueHours(12)); + + settings = Settings.builder().put("plugins.anomaly_detection.ad_result_history_max_docs", 93).build(); + assertEquals(AnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS.get(settings), Long.valueOf(93)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS.get(settings), Long.valueOf(250000000)); + + settings = Settings + .builder() + .put("plugins.anomaly_detection.ad_result_history_retention_period", TimeValue.timeValueDays(92)) + .build(); + assertEquals(AnomalyDetectorSettings.AD_RESULT_HISTORY_RETENTION_PERIOD.get(settings), TimeValue.timeValueDays(92)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_RETENTION_PERIOD.get(settings), TimeValue.timeValueDays(30)); + + settings = Settings.builder().put("plugins.anomaly_detection.max_retry_for_unresponsive_node", 91).build(); + assertEquals(AnomalyDetectorSettings.MAX_RETRY_FOR_UNRESPONSIVE_NODE.get(settings), Integer.valueOf(91)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_UNRESPONSIVE_NODE.get(settings), Integer.valueOf(5)); + + settings = Settings.builder().put("plugins.anomaly_detection.cooldown_minutes", TimeValue.timeValueMinutes(90)).build(); + assertEquals(AnomalyDetectorSettings.COOLDOWN_MINUTES.get(settings), TimeValue.timeValueMinutes(90)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.COOLDOWN_MINUTES.get(settings), TimeValue.timeValueMinutes(5)); + + settings = Settings.builder().put("plugins.anomaly_detection.backoff_minutes", TimeValue.timeValueMinutes(89)).build(); + assertEquals(AnomalyDetectorSettings.BACKOFF_MINUTES.get(settings), TimeValue.timeValueMinutes(89)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.BACKOFF_MINUTES.get(settings), TimeValue.timeValueMinutes(15)); + + settings = Settings.builder().put("plugins.anomaly_detection.backoff_initial_delay", TimeValue.timeValueMillis(88)).build(); + assertEquals(AnomalyDetectorSettings.BACKOFF_INITIAL_DELAY.get(settings), TimeValue.timeValueMillis(88)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.BACKOFF_INITIAL_DELAY.get(settings), TimeValue.timeValueMillis(1000)); + + settings = Settings.builder().put("plugins.anomaly_detection.max_retry_for_backoff", 87).build(); + assertEquals(AnomalyDetectorSettings.MAX_RETRY_FOR_BACKOFF.get(settings), Integer.valueOf(87)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_BACKOFF.get(settings), Integer.valueOf(3)); + + settings = Settings.builder().put("plugins.anomaly_detection.max_retry_for_end_run_exception", 86).build(); + assertEquals(AnomalyDetectorSettings.MAX_RETRY_FOR_END_RUN_EXCEPTION.get(settings), Integer.valueOf(86)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_END_RUN_EXCEPTION.get(settings), Integer.valueOf(6)); + + settings = Settings.builder().put("plugins.anomaly_detection.filter_by_backend_roles", true).build(); + assertEquals(AnomalyDetectorSettings.FILTER_BY_BACKEND_ROLES.get(settings), Boolean.valueOf(true)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.FILTER_BY_BACKEND_ROLES.get(settings), Boolean.valueOf(false)); + + settings = Settings.builder().put("plugins.anomaly_detection.model_max_size_percent", 0.3).build(); + assertEquals(AnomalyDetectorSettings.MODEL_MAX_SIZE_PERCENTAGE.get(settings), Double.valueOf(0.3)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.MODEL_MAX_SIZE_PERCENTAGE.get(settings), Double.valueOf(0.1)); + + settings = Settings.builder().put("plugins.anomaly_detection.max_entities_per_query", 83).build(); + assertEquals(AnomalyDetectorSettings.MAX_ENTITIES_PER_QUERY.get(settings), Integer.valueOf(83)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.MAX_ENTITIES_PER_QUERY.get(settings), Integer.valueOf(1000)); + + settings = Settings.builder().put("plugins.anomaly_detection.max_entities_for_preview", 82).build(); + assertEquals(AnomalyDetectorSettings.MAX_ENTITIES_FOR_PREVIEW.get(settings), Integer.valueOf(82)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.MAX_ENTITIES_FOR_PREVIEW.get(settings), Integer.valueOf(30)); + + settings = Settings.builder().put("plugins.anomaly_detection.index_pressure_soft_limit", 81f).build(); + assertEquals(AnomalyDetectorSettings.INDEX_PRESSURE_SOFT_LIMIT.get(settings), Float.valueOf(81f)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.INDEX_PRESSURE_SOFT_LIMIT.get(settings), Float.valueOf(0.8f)); + + settings = Settings.builder().put("plugins.anomaly_detection.max_primary_shards", 80).build(); + assertEquals(AnomalyDetectorSettings.MAX_PRIMARY_SHARDS.get(settings), Integer.valueOf(80)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.MAX_PRIMARY_SHARDS.get(settings), Integer.valueOf(10)); + + settings = Settings.builder().put("plugins.anomaly_detection.max_cache_miss_handling_per_second", 79).build(); + assertEquals(AnomalyDetectorSettings.MAX_CACHE_MISS_HANDLING_PER_SECOND.get(settings), Integer.valueOf(79)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.MAX_CACHE_MISS_HANDLING_PER_SECOND.get(settings), Integer.valueOf(100)); + + settings = Settings.builder().put("plugins.anomaly_detection.max_batch_task_per_node", 78).build(); + assertEquals(AnomalyDetectorSettings.MAX_BATCH_TASK_PER_NODE.get(settings), Integer.valueOf(78)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.MAX_BATCH_TASK_PER_NODE.get(settings), Integer.valueOf(2)); + + settings = Settings.builder().put("plugins.anomaly_detection.max_old_ad_task_docs_per_detector", 77).build(); + assertEquals(AnomalyDetectorSettings.MAX_OLD_AD_TASK_DOCS_PER_DETECTOR.get(settings), Integer.valueOf(77)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.MAX_OLD_AD_TASK_DOCS_PER_DETECTOR.get(settings), Integer.valueOf(10)); + + settings = Settings.builder().put("plugins.anomaly_detection.batch_task_piece_size", 76).build(); + assertEquals(AnomalyDetectorSettings.BATCH_TASK_PIECE_SIZE.get(settings), Integer.valueOf(76)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.BATCH_TASK_PIECE_SIZE.get(settings), Integer.valueOf(1000)); + + settings = Settings.builder().put("plugins.anomaly_detection.batch_task_piece_interval_seconds", 76).build(); + assertEquals(AnomalyDetectorSettings.BATCH_TASK_PIECE_INTERVAL_SECONDS.get(settings), Integer.valueOf(76)); + assertEquals(LegacyOpenDistroAnomalyDetectorSettings.BATCH_TASK_PIECE_INTERVAL_SECONDS.get(settings), Integer.valueOf(5)); + } + + public void testSettingsGetValueWithLegacyFallback() { + Settings settings = Settings + .builder() + .put("opendistro.anomaly_detection.max_anomaly_detectors", 1) + .put("opendistro.anomaly_detection.max_multi_entity_anomaly_detectors", 2) + .put("opendistro.anomaly_detection.max_anomaly_features", 3) + .put("opendistro.anomaly_detection.request_timeout", "4s") + .put("opendistro.anomaly_detection.detection_interval", "5m") + .put("opendistro.anomaly_detection.detection_window_delay", "6m") + .put("opendistro.anomaly_detection.ad_result_history_rollover_period", "7h") + .put("opendistro.anomaly_detection.ad_result_history_max_docs", 8L) + .put("opendistro.anomaly_detection.ad_result_history_retention_period", "9d") + .put("opendistro.anomaly_detection.max_retry_for_unresponsive_node", 10) + .put("opendistro.anomaly_detection.cooldown_minutes", "11m") + .put("opendistro.anomaly_detection.backoff_minutes", "12m") + .put("opendistro.anomaly_detection.backoff_initial_delay", "13ms") // + .put("opendistro.anomaly_detection.max_retry_for_backoff", 14) + .put("opendistro.anomaly_detection.max_retry_for_end_run_exception", 15) + .put("opendistro.anomaly_detection.filter_by_backend_roles", true) + .put("opendistro.anomaly_detection.model_max_size_percent", 0.6D) + .put("opendistro.anomaly_detection.max_entities_per_query", 18) + .put("opendistro.anomaly_detection.max_entities_for_preview", 19) + .put("opendistro.anomaly_detection.index_pressure_soft_limit", 20F) + .put("opendistro.anomaly_detection.max_primary_shards", 21) + .put("opendistro.anomaly_detection.max_cache_miss_handling_per_second", 22) + .put("opendistro.anomaly_detection.max_batch_task_per_node", 23) + .put("opendistro.anomaly_detection.max_old_ad_task_docs_per_detector", 24) + .put("opendistro.anomaly_detection.batch_task_piece_size", 25) + .put("opendistro.anomaly_detection.batch_task_piece_interval_seconds", 26) + .build(); + + assertEquals(AnomalyDetectorSettings.MAX_SINGLE_ENTITY_ANOMALY_DETECTORS.get(settings), Integer.valueOf(1)); + assertEquals(AnomalyDetectorSettings.MAX_MULTI_ENTITY_ANOMALY_DETECTORS.get(settings), Integer.valueOf(2)); + assertEquals(AnomalyDetectorSettings.MAX_ANOMALY_FEATURES.get(settings), Integer.valueOf(3)); + assertEquals(AnomalyDetectorSettings.REQUEST_TIMEOUT.get(settings), TimeValue.timeValueSeconds(4)); + assertEquals(AnomalyDetectorSettings.DETECTION_INTERVAL.get(settings), TimeValue.timeValueMinutes(5)); + assertEquals(AnomalyDetectorSettings.DETECTION_WINDOW_DELAY.get(settings), TimeValue.timeValueMinutes(6)); + assertEquals(AnomalyDetectorSettings.AD_RESULT_HISTORY_ROLLOVER_PERIOD.get(settings), TimeValue.timeValueHours(7)); + assertEquals(AnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS.get(settings), Long.valueOf(8L)); + assertEquals(AnomalyDetectorSettings.AD_RESULT_HISTORY_RETENTION_PERIOD.get(settings), TimeValue.timeValueDays(9)); + assertEquals(AnomalyDetectorSettings.MAX_RETRY_FOR_UNRESPONSIVE_NODE.get(settings), Integer.valueOf(10)); + assertEquals(AnomalyDetectorSettings.COOLDOWN_MINUTES.get(settings), TimeValue.timeValueMinutes(11)); + assertEquals(AnomalyDetectorSettings.BACKOFF_MINUTES.get(settings), TimeValue.timeValueMinutes(12)); + assertEquals(AnomalyDetectorSettings.BACKOFF_INITIAL_DELAY.get(settings), TimeValue.timeValueMillis(13)); + assertEquals(AnomalyDetectorSettings.MAX_RETRY_FOR_BACKOFF.get(settings), Integer.valueOf(14)); + assertEquals(AnomalyDetectorSettings.MAX_RETRY_FOR_END_RUN_EXCEPTION.get(settings), Integer.valueOf(15)); + assertEquals(AnomalyDetectorSettings.FILTER_BY_BACKEND_ROLES.get(settings), Boolean.valueOf(true)); + assertEquals(AnomalyDetectorSettings.MODEL_MAX_SIZE_PERCENTAGE.get(settings), Double.valueOf(0.6D)); + assertEquals(AnomalyDetectorSettings.MAX_ENTITIES_PER_QUERY.get(settings), Integer.valueOf(18)); + assertEquals(AnomalyDetectorSettings.MAX_ENTITIES_FOR_PREVIEW.get(settings), Integer.valueOf(19)); + assertEquals(AnomalyDetectorSettings.INDEX_PRESSURE_SOFT_LIMIT.get(settings), Float.valueOf(20F)); + assertEquals(AnomalyDetectorSettings.MAX_PRIMARY_SHARDS.get(settings), Integer.valueOf(21)); + assertEquals(AnomalyDetectorSettings.MAX_CACHE_MISS_HANDLING_PER_SECOND.get(settings), Integer.valueOf(22)); + assertEquals(AnomalyDetectorSettings.MAX_BATCH_TASK_PER_NODE.get(settings), Integer.valueOf(23)); + assertEquals(AnomalyDetectorSettings.MAX_OLD_AD_TASK_DOCS_PER_DETECTOR.get(settings), Integer.valueOf(24)); + assertEquals(AnomalyDetectorSettings.BATCH_TASK_PIECE_SIZE.get(settings), Integer.valueOf(25)); + assertEquals(AnomalyDetectorSettings.BATCH_TASK_PIECE_INTERVAL_SECONDS.get(settings), Integer.valueOf(26)); + + assertSettingDeprecationsAndWarnings( + new Setting[] { + LegacyOpenDistroAnomalyDetectorSettings.MAX_SINGLE_ENTITY_ANOMALY_DETECTORS, + LegacyOpenDistroAnomalyDetectorSettings.MAX_MULTI_ENTITY_ANOMALY_DETECTORS, + LegacyOpenDistroAnomalyDetectorSettings.MAX_ANOMALY_FEATURES, + LegacyOpenDistroAnomalyDetectorSettings.REQUEST_TIMEOUT, + LegacyOpenDistroAnomalyDetectorSettings.DETECTION_INTERVAL, + LegacyOpenDistroAnomalyDetectorSettings.DETECTION_WINDOW_DELAY, + LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_ROLLOVER_PERIOD, + LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_MAX_DOCS, + LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_UNRESPONSIVE_NODE, + LegacyOpenDistroAnomalyDetectorSettings.COOLDOWN_MINUTES, + LegacyOpenDistroAnomalyDetectorSettings.BACKOFF_MINUTES, + LegacyOpenDistroAnomalyDetectorSettings.BACKOFF_INITIAL_DELAY, + LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_BACKOFF, + LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_END_RUN_EXCEPTION, + LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_RETENTION_PERIOD, + LegacyOpenDistroAnomalyDetectorSettings.MODEL_MAX_SIZE_PERCENTAGE, + LegacyOpenDistroAnomalyDetectorSettings.MAX_ENTITIES_PER_QUERY, + LegacyOpenDistroAnomalyDetectorSettings.MAX_ENTITIES_FOR_PREVIEW, + LegacyOpenDistroAnomalyDetectorSettings.INDEX_PRESSURE_SOFT_LIMIT, + LegacyOpenDistroAnomalyDetectorSettings.MAX_PRIMARY_SHARDS, + LegacyOpenDistroAnomalyDetectorSettings.FILTER_BY_BACKEND_ROLES, + LegacyOpenDistroAnomalyDetectorSettings.MAX_CACHE_MISS_HANDLING_PER_SECOND, + LegacyOpenDistroAnomalyDetectorSettings.MAX_BATCH_TASK_PER_NODE, + LegacyOpenDistroAnomalyDetectorSettings.BATCH_TASK_PIECE_INTERVAL_SECONDS, + LegacyOpenDistroAnomalyDetectorSettings.MAX_OLD_AD_TASK_DOCS_PER_DETECTOR, + LegacyOpenDistroAnomalyDetectorSettings.BATCH_TASK_PIECE_SIZE } + ); + } +} diff --git a/src/test/java/org/opensearch/ad/transport/ADBatchAnomalyResultTransportActionTests.java b/src/test/java/org/opensearch/ad/transport/ADBatchAnomalyResultTransportActionTests.java index 384be9cfd..df160cde9 100644 --- a/src/test/java/org/opensearch/ad/transport/ADBatchAnomalyResultTransportActionTests.java +++ b/src/test/java/org/opensearch/ad/transport/ADBatchAnomalyResultTransportActionTests.java @@ -137,7 +137,7 @@ public void testHistoricalDetectorWithValidDateRange() throws IOException, Inter DetectionDateRange dateRange = new DetectionDateRange(startTime, endTime); ADBatchAnomalyResultRequest request = adBatchAnomalyResultRequest(dateRange); client().execute(ADBatchAnomalyResultAction.INSTANCE, request).actionGet(5000); - Thread.sleep(10000); + Thread.sleep(20000); GetResponse doc = getDoc(CommonName.DETECTION_STATE_INDEX, request.getAdTask().getTaskId()); assertEquals(ADTaskState.FINISHED.name(), doc.getSourceAsMap().get(ADTask.STATE_FIELD)); } @@ -196,7 +196,7 @@ public void testMultipleTasks() throws IOException, InterruptedException { new DetectionDateRange(startTime, startTime.plus(2000, ChronoUnit.MINUTES)) ); client().execute(ADBatchAnomalyResultAction.INSTANCE, request).actionGet(5000); - Thread.sleep(20000); + Thread.sleep(25000); GetResponse doc = getDoc(CommonName.DETECTION_STATE_INDEX, request.getAdTask().getTaskId()); assertEquals(ADTaskState.FINISHED.name(), doc.getSourceAsMap().get(ADTask.STATE_FIELD)); updateTransientSettings(ImmutableMap.of(MAX_BATCH_TASK_PER_NODE.getKey(), 1)); diff --git a/src/test/java/org/opensearch/ad/transport/AnomalyDetectorJobActionTests.java b/src/test/java/org/opensearch/ad/transport/AnomalyDetectorJobActionTests.java index cafcc6e6e..97c02fd6f 100644 --- a/src/test/java/org/opensearch/ad/transport/AnomalyDetectorJobActionTests.java +++ b/src/test/java/org/opensearch/ad/transport/AnomalyDetectorJobActionTests.java @@ -49,14 +49,13 @@ import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext; +import org.opensearch.commons.ConfigConstants; import org.opensearch.rest.RestStatus; import org.opensearch.tasks.Task; import org.opensearch.test.OpenSearchIntegTestCase; import org.opensearch.threadpool.ThreadPool; import org.opensearch.transport.TransportService; -import com.amazon.opendistroforelasticsearch.commons.ConfigConstants; - public class AnomalyDetectorJobActionTests extends OpenSearchIntegTestCase { private AnomalyDetectorJobTransportAction action; private Task task; @@ -75,7 +74,7 @@ public void setUp() throws Exception { Settings build = Settings.builder().build(); ThreadContext threadContext = new ThreadContext(build); - threadContext.putTransient(ConfigConstants.OPENDISTRO_SECURITY_USER_INFO_THREAD_CONTEXT, "alice|odfe,aes|engineering,operations"); + threadContext.putTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, "alice|odfe,aes|engineering,operations"); when(clusterService.getClusterSettings()).thenReturn(clusterSettings); Client client = mock(Client.class); org.opensearch.threadpool.ThreadPool mockThreadPool = mock(ThreadPool.class); diff --git a/src/test/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportActionTests.java b/src/test/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportActionTests.java index 0d8962a98..b8794c231 100644 --- a/src/test/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportActionTests.java +++ b/src/test/java/org/opensearch/ad/transport/IndexAnomalyDetectorTransportActionTests.java @@ -49,14 +49,13 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.concurrent.ThreadContext; +import org.opensearch.commons.ConfigConstants; import org.opensearch.rest.RestRequest; import org.opensearch.tasks.Task; import org.opensearch.test.OpenSearchIntegTestCase; import org.opensearch.threadpool.ThreadPool; import org.opensearch.transport.TransportService; -import com.amazon.opendistroforelasticsearch.commons.ConfigConstants; - public class IndexAnomalyDetectorTransportActionTests extends OpenSearchIntegTestCase { private IndexAnomalyDetectorTransportAction action; private Task task; @@ -124,7 +123,7 @@ public void testIndexTransportAction() { public void testIndexTransportActionWithUserAndFilterOn() { Settings settings = Settings.builder().put(AnomalyDetectorSettings.FILTER_BY_BACKEND_ROLES.getKey(), true).build(); ThreadContext threadContext = new ThreadContext(settings); - threadContext.putTransient(ConfigConstants.OPENDISTRO_SECURITY_USER_INFO_THREAD_CONTEXT, "alice|odfe,aes|engineering,operations"); + threadContext.putTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, "alice|odfe,aes|engineering,operations"); when(clusterService.getClusterSettings()).thenReturn(clusterSettings); Client client = mock(Client.class); org.opensearch.threadpool.ThreadPool mockThreadPool = mock(ThreadPool.class); @@ -148,7 +147,7 @@ public void testIndexTransportActionWithUserAndFilterOn() { public void testIndexTransportActionWithUserAndFilterOff() { Settings settings = Settings.builder().build(); ThreadContext threadContext = new ThreadContext(settings); - threadContext.putTransient(ConfigConstants.OPENDISTRO_SECURITY_USER_INFO_THREAD_CONTEXT, "alice|odfe,aes|engineering,operations"); + threadContext.putTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, "alice|odfe,aes|engineering,operations"); when(clusterService.getClusterSettings()).thenReturn(clusterSettings); Client client = mock(Client.class); org.opensearch.threadpool.ThreadPool mockThreadPool = mock(ThreadPool.class); diff --git a/src/test/java/org/opensearch/ad/transport/PreviewAnomalyDetectorTransportActionTests.java b/src/test/java/org/opensearch/ad/transport/PreviewAnomalyDetectorTransportActionTests.java index 82dae2618..0b5d7f0ad 100644 --- a/src/test/java/org/opensearch/ad/transport/PreviewAnomalyDetectorTransportActionTests.java +++ b/src/test/java/org/opensearch/ad/transport/PreviewAnomalyDetectorTransportActionTests.java @@ -72,13 +72,13 @@ import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; +import org.opensearch.commons.ConfigConstants; import org.opensearch.rest.RestStatus; import org.opensearch.tasks.Task; import org.opensearch.test.OpenSearchSingleNodeTestCase; import org.opensearch.threadpool.ThreadPool; import org.opensearch.transport.TransportService; -import com.amazon.opendistroforelasticsearch.commons.ConfigConstants; import com.google.common.collect.ImmutableMap; public class PreviewAnomalyDetectorTransportActionTests extends OpenSearchSingleNodeTestCase { @@ -266,7 +266,7 @@ public void testPreviewTransportActionNoContext() throws IOException, Interrupte Settings settings = Settings.builder().put(AnomalyDetectorSettings.FILTER_BY_BACKEND_ROLES.getKey(), true).build(); Client client = mock(Client.class); ThreadContext threadContext = new ThreadContext(settings); - threadContext.putTransient(ConfigConstants.OPENDISTRO_SECURITY_USER_INFO_THREAD_CONTEXT, "alice|odfe,aes|engineering,operations"); + threadContext.putTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, "alice|odfe,aes|engineering,operations"); org.opensearch.threadpool.ThreadPool mockThreadPool = mock(ThreadPool.class); when(client.threadPool()).thenReturn(mockThreadPool); when(mockThreadPool.getThreadContext()).thenReturn(threadContext); diff --git a/src/test/java/org/opensearch/ad/transport/handler/ADSearchHandlerTests.java b/src/test/java/org/opensearch/ad/transport/handler/ADSearchHandlerTests.java index 4c3395f21..6d990691f 100644 --- a/src/test/java/org/opensearch/ad/transport/handler/ADSearchHandlerTests.java +++ b/src/test/java/org/opensearch/ad/transport/handler/ADSearchHandlerTests.java @@ -45,10 +45,9 @@ import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext; +import org.opensearch.commons.ConfigConstants; import org.opensearch.threadpool.ThreadPool; -import com.amazon.opendistroforelasticsearch.commons.ConfigConstants; - public class ADSearchHandlerTests extends ADUnitTestCase { private Client client; @@ -73,7 +72,7 @@ public void setUp() throws Exception { searchHandler = new ADSearchHandler(settings, clusterService, client); ThreadContext threadContext = new ThreadContext(settings); - threadContext.putTransient(ConfigConstants.OPENDISTRO_SECURITY_USER_INFO_THREAD_CONTEXT, "alice|odfe,aes|engineering,operations"); + threadContext.putTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT, "alice|odfe,aes|engineering,operations"); org.opensearch.threadpool.ThreadPool mockThreadPool = mock(ThreadPool.class); when(client.threadPool()).thenReturn(mockThreadPool); when(client.threadPool().getThreadContext()).thenReturn(threadContext); diff --git a/src/test/java/org/opensearch/ad/transport/handler/AnomalyResultHandlerTests.java b/src/test/java/org/opensearch/ad/transport/handler/AnomalyResultHandlerTests.java index d3da2d95f..a2a83a6f4 100644 --- a/src/test/java/org/opensearch/ad/transport/handler/AnomalyResultHandlerTests.java +++ b/src/test/java/org/opensearch/ad/transport/handler/AnomalyResultHandlerTests.java @@ -304,8 +304,8 @@ private void savingFailureTemplate(boolean throwOpenSearchRejectedExecutionExcep Settings backoffSettings = Settings .builder() - .put("opendistro.anomaly_detection.max_retry_for_backoff", 2) - .put("opendistro.anomaly_detection.backoff_initial_delay", TimeValue.timeValueMillis(1)) + .put("plugins.anomaly_detection.max_retry_for_backoff", 2) + .put("plugins.anomaly_detection.backoff_initial_delay", TimeValue.timeValueMillis(1)) .build(); AnomalyIndexHandler handler = new AnomalyIndexHandler( diff --git a/src/test/java/org/opensearch/ad/util/ParseUtilsTests.java b/src/test/java/org/opensearch/ad/util/ParseUtilsTests.java index 4906c996c..fa4ba4ed2 100644 --- a/src/test/java/org/opensearch/ad/util/ParseUtilsTests.java +++ b/src/test/java/org/opensearch/ad/util/ParseUtilsTests.java @@ -40,12 +40,12 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.commons.authuser.User; import org.opensearch.search.aggregations.AggregationBuilder; import org.opensearch.search.aggregations.AggregatorFactories; import org.opensearch.search.builder.SearchSourceBuilder; import org.opensearch.test.OpenSearchTestCase; -import com.amazon.opendistroforelasticsearch.commons.authuser.User; import com.google.common.collect.ImmutableList; public class ParseUtilsTests extends OpenSearchTestCase {