Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the AD settings for opensearch. #47

Merged
merged 11 commits into from
May 21, 2021
26 changes: 26 additions & 0 deletions src/main/java/org/opensearch/ad/AnomalyDetectorPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -637,6 +638,31 @@ public List<Setting<?>> getSettings() {

List<Setting<?>> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ private AnomalyDetectorSettings() {}

public static final Setting<Integer> MAX_SINGLE_ENTITY_ANOMALY_DETECTORS = Setting
.intSetting(
"opendistro.anomaly_detection.max_anomaly_detectors",
1000,
"opensearch.anomaly_detection.max_anomaly_detectors",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know @saratvemulapalli has been saying that we would want these to be plugins. just to avoid renaming again :) Care to comment?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was miss on our side, we haven't updated the guidance. I would prefer to have plugins instead of opensearch.
Can we update the doc: https://github.com/opensearch-project/opensearch-plugins/blob/main/CONVENTIONS.md#settings

Also let folks working on JobScheduler to take care of it as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean we should change "opensearch.anomaly_detection.xxx" to "plugins.anomaly_detection.xxx"?

Sure, I will make that change.
Thank you for the comments!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please. Thanks Alex!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why would we not make this anomaly_detection.max_anomaly_detectors? That's what k-nn is doing, for example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely that works too. But I would love to have consistency across different pieces in the plugins.
And, we have decided to go with that as we have already discussed in the public:
opensearch-project/opensearch-plugins#13
https://discuss.opendistrocommunity.dev/t/thoughts-on-having-opensearch-identifier-in-all-things-plugins/5855

I am not opposed to either way but since we have taken a decision in the public, I would prefer to stick with it unless we see strong contentions to why that doesnt work. What do you think?

Copy link
Member

@dblock dblock May 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A-OK by me to include plugins. opensearch-project/opensearch-plugins#31

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha oncall :/, thanks for the change!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for the input!
I have submitted a commits to update "opensearch" to "plugins"

LegacyOpenDistroAnomalyDetectorSettings.MAX_SINGLE_ENTITY_ANOMALY_DETECTORS,
0,
10_000,
Setting.Property.NodeScope,
Expand All @@ -50,117 +50,135 @@ private AnomalyDetectorSettings() {}

public static final Setting<Integer> MAX_MULTI_ENTITY_ANOMALY_DETECTORS = Setting
.intSetting(
"opendistro.anomaly_detection.max_multi_entity_anomaly_detectors",
10,
"opensearch.anomaly_detection.max_multi_entity_anomaly_detectors",
LegacyOpenDistroAnomalyDetectorSettings.MAX_MULTI_ENTITY_ANOMALY_DETECTORS,
0,
10_000,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

public static final Setting<Integer> MAX_ANOMALY_FEATURES = Setting
.intSetting("opendistro.anomaly_detection.max_anomaly_features", 5, 0, 100, Setting.Property.NodeScope, Setting.Property.Dynamic);
.intSetting(
"opensearch.anomaly_detection.max_anomaly_features",
LegacyOpenDistroAnomalyDetectorSettings.MAX_ANOMALY_FEATURES,
0,
100,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

public static final Setting<TimeValue> REQUEST_TIMEOUT = Setting
.positiveTimeSetting(
"opendistro.anomaly_detection.request_timeout",
TimeValue.timeValueSeconds(10),
"opensearch.anomaly_detection.request_timeout",
LegacyOpenDistroAnomalyDetectorSettings.REQUEST_TIMEOUT,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

public static final Setting<TimeValue> DETECTION_INTERVAL = Setting
.positiveTimeSetting(
"opendistro.anomaly_detection.detection_interval",
TimeValue.timeValueMinutes(10),
"opensearch.anomaly_detection.detection_interval",
LegacyOpenDistroAnomalyDetectorSettings.DETECTION_INTERVAL,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

public static final Setting<TimeValue> DETECTION_WINDOW_DELAY = Setting
.timeSetting(
"opendistro.anomaly_detection.detection_window_delay",
TimeValue.timeValueMinutes(0),
"opensearch.anomaly_detection.detection_window_delay",
LegacyOpenDistroAnomalyDetectorSettings.DETECTION_WINDOW_DELAY,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

public static final Setting<TimeValue> AD_RESULT_HISTORY_ROLLOVER_PERIOD = Setting
.positiveTimeSetting(
"opendistro.anomaly_detection.ad_result_history_rollover_period",
TimeValue.timeValueHours(12),
"opensearch.anomaly_detection.ad_result_history_rollover_period",
LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_ROLLOVER_PERIOD,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

public static final Setting<Long> AD_RESULT_HISTORY_MAX_DOCS = Setting
.longSetting(
"opendistro.anomaly_detection.ad_result_history_max_docs",
"opensearch.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
);

public static final Setting<TimeValue> AD_RESULT_HISTORY_RETENTION_PERIOD = Setting
.positiveTimeSetting(
"opendistro.anomaly_detection.ad_result_history_retention_period",
TimeValue.timeValueDays(30),
"opensearch.anomaly_detection.ad_result_history_retention_period",
LegacyOpenDistroAnomalyDetectorSettings.AD_RESULT_HISTORY_RETENTION_PERIOD,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

public static final Setting<Integer> MAX_RETRY_FOR_UNRESPONSIVE_NODE = Setting
.intSetting(
"opendistro.anomaly_detection.max_retry_for_unresponsive_node",
5,
"opensearch.anomaly_detection.max_retry_for_unresponsive_node",
LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_UNRESPONSIVE_NODE,
0,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

public static final Setting<TimeValue> COOLDOWN_MINUTES = Setting
.positiveTimeSetting(
"opendistro.anomaly_detection.cooldown_minutes",
TimeValue.timeValueMinutes(5),
"opensearch.anomaly_detection.cooldown_minutes",
LegacyOpenDistroAnomalyDetectorSettings.COOLDOWN_MINUTES,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

public static final Setting<TimeValue> BACKOFF_MINUTES = Setting
.positiveTimeSetting(
"opendistro.anomaly_detection.backoff_minutes",
TimeValue.timeValueMinutes(15),
"opensearch.anomaly_detection.backoff_minutes",
LegacyOpenDistroAnomalyDetectorSettings.BACKOFF_MINUTES,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

public static final Setting<TimeValue> BACKOFF_INITIAL_DELAY = Setting
.positiveTimeSetting(
"opendistro.anomaly_detection.backoff_initial_delay",
TimeValue.timeValueMillis(1000),
"opensearch.anomaly_detection.backoff_initial_delay",
LegacyOpenDistroAnomalyDetectorSettings.BACKOFF_INITIAL_DELAY,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

public static final Setting<Integer> MAX_RETRY_FOR_BACKOFF = Setting
.intSetting("opendistro.anomaly_detection.max_retry_for_backoff", 3, 0, Setting.Property.NodeScope, Setting.Property.Dynamic);
.intSetting(
"opensearch.anomaly_detection.max_retry_for_backoff",
LegacyOpenDistroAnomalyDetectorSettings.MAX_RETRY_FOR_BACKOFF,
0,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

public static final Setting<Integer> MAX_RETRY_FOR_END_RUN_EXCEPTION = Setting
.intSetting(
"opendistro.anomaly_detection.max_retry_for_end_run_exception",
6,
"opensearch.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<Boolean> FILTER_BY_BACKEND_ROLES = Setting
.boolSetting("opendistro.anomaly_detection.filter_by_backend_roles", false, Setting.Property.NodeScope, Setting.Property.Dynamic);
.boolSetting(
"opensearch.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";
Expand Down Expand Up @@ -190,8 +208,8 @@ private AnomalyDetectorSettings() {}

public static final Setting<Double> MODEL_MAX_SIZE_PERCENTAGE = Setting
.doubleSetting(
"opendistro.anomaly_detection.model_max_size_percent",
0.1,
"opensearch.anomaly_detection.model_max_size_percent",
LegacyOpenDistroAnomalyDetectorSettings.MODEL_MAX_SIZE_PERCENTAGE,
0,
0.7,
Setting.Property.NodeScope,
Expand Down Expand Up @@ -272,8 +290,8 @@ private AnomalyDetectorSettings() {}
// Increase the value will adding pressure to indexing anomaly results and our feature query
public static final Setting<Integer> MAX_ENTITIES_PER_QUERY = Setting
.intSetting(
"opendistro.anomaly_detection.max_entities_per_query",
1000,
"opensearch.anomaly_detection.max_entities_per_query",
LegacyOpenDistroAnomalyDetectorSettings.MAX_ENTITIES_PER_QUERY,
1,
100_000_000,
Setting.Property.NodeScope,
Expand All @@ -286,8 +304,8 @@ private AnomalyDetectorSettings() {}
// Maximum number of entities retrieved for Preview API
public static final Setting<Integer> MAX_ENTITIES_FOR_PREVIEW = Setting
.intSetting(
"opendistro.anomaly_detection.max_entities_for_preview",
DEFAULT_ENTITIES_FOR_PREVIEW,
"opensearch.anomaly_detection.max_entities_for_preview",
LegacyOpenDistroAnomalyDetectorSettings.MAX_ENTITIES_FOR_PREVIEW,
1,
1000,
Setting.Property.NodeScope,
Expand All @@ -297,16 +315,23 @@ private AnomalyDetectorSettings() {}
// save partial zero-anomaly grade results after indexing pressure reaching the limit
public static final Setting<Float> INDEX_PRESSURE_SOFT_LIMIT = Setting
.floatSetting(
"opendistro.anomaly_detection.index_pressure_soft_limit",
0.8f,
"opensearch.anomaly_detection.index_pressure_soft_limit",
LegacyOpenDistroAnomalyDetectorSettings.INDEX_PRESSURE_SOFT_LIMIT,
0.0f,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

// max number of primary shards of an AD index
public static final Setting<Integer> MAX_PRIMARY_SHARDS = Setting
.intSetting("opendistro.anomaly_detection.max_primary_shards", 10, 0, 200, Setting.Property.NodeScope, Setting.Property.Dynamic);
.intSetting(
"opensearch.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;
Expand All @@ -325,8 +350,8 @@ private AnomalyDetectorSettings() {}
// but for 1 day interval, it will be 30 days.
public static Setting<Integer> MAX_CACHE_MISS_HANDLING_PER_SECOND = Setting
.intSetting(
"opendistro.anomaly_detection.max_cache_miss_handling_per_second",
100,
"opensearch.anomaly_detection.max_cache_miss_handling_per_second",
LegacyOpenDistroAnomalyDetectorSettings.MAX_CACHE_MISS_HANDLING_PER_SECOND,
0,
1000,
Setting.Property.NodeScope,
Expand All @@ -337,8 +362,8 @@ private AnomalyDetectorSettings() {}
// TODO: performance test and tune the setting.
public static final Setting<Integer> MAX_BATCH_TASK_PER_NODE = Setting
.intSetting(
"opendistro.anomaly_detection.max_batch_task_per_node",
2,
"opensearch.anomaly_detection.max_batch_task_per_node",
LegacyOpenDistroAnomalyDetectorSettings.MAX_BATCH_TASK_PER_NODE,
1,
100,
Setting.Property.NodeScope,
Expand All @@ -349,11 +374,11 @@ private AnomalyDetectorSettings() {}

public static final Setting<Integer> MAX_OLD_AD_TASK_DOCS_PER_DETECTOR = Setting
.intSetting(
"opendistro.anomaly_detection.max_old_ad_task_docs_per_detector",
"opensearch.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,
Expand All @@ -362,8 +387,8 @@ private AnomalyDetectorSettings() {}

public static final Setting<Integer> BATCH_TASK_PIECE_SIZE = Setting
.intSetting(
"opendistro.anomaly_detection.batch_task_piece_size",
1000,
"opensearch.anomaly_detection.batch_task_piece_size",
LegacyOpenDistroAnomalyDetectorSettings.BATCH_TASK_PIECE_SIZE,
1,
10_000,
Setting.Property.NodeScope,
Expand All @@ -372,8 +397,8 @@ private AnomalyDetectorSettings() {}

public static final Setting<Integer> BATCH_TASK_PIECE_INTERVAL_SECONDS = Setting
.intSetting(
"opendistro.anomaly_detection.batch_task_piece_interval_seconds",
5,
"opensearch.anomaly_detection.batch_task_piece_interval_seconds",
LegacyOpenDistroAnomalyDetectorSettings.BATCH_TASK_PIECE_INTERVAL_SECONDS,
1,
600,
Setting.Property.NodeScope,
Expand Down
27 changes: 23 additions & 4 deletions src/main/java/org/opensearch/ad/settings/EnabledSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 = "opensearch.anomaly_detection.enabled";

public static final String AD_BREAKER_ENABLED = "opendistro.anomaly_detection.breaker.enabled";
public static final String AD_BREAKER_ENABLED = "opensearch.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<String, Setting<?>> settings = unmodifiableMap(new HashMap<String, Setting<?>>() {
{
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));
}
});

Expand Down
Loading