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

fix dynamic setting of max detector/feature limit #130

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

import static com.amazon.opendistroforelasticsearch.ad.settings.AnomalyDetectorSettings.DETECTION_INTERVAL;
import static com.amazon.opendistroforelasticsearch.ad.settings.AnomalyDetectorSettings.DETECTION_WINDOW_DELAY;
import static com.amazon.opendistroforelasticsearch.ad.settings.AnomalyDetectorSettings.MAX_ANOMALY_DETECTORS;
import static com.amazon.opendistroforelasticsearch.ad.settings.AnomalyDetectorSettings.MAX_ANOMALY_FEATURES;
import static com.amazon.opendistroforelasticsearch.ad.settings.AnomalyDetectorSettings.REQUEST_TIMEOUT;
import static com.amazon.opendistroforelasticsearch.ad.util.RestHandlerUtils.DETECTOR_ID;
import static com.amazon.opendistroforelasticsearch.ad.util.RestHandlerUtils.IF_PRIMARY_TERM;
Expand All @@ -62,6 +64,8 @@ public class RestIndexAnomalyDetectorAction extends BaseRestHandler {
private volatile TimeValue requestTimeout;
private volatile TimeValue detectionInterval;
private volatile TimeValue detectionWindowDelay;
private volatile Integer maxAnomalyDetectors;
private volatile Integer maxAnomalyFeatures;

public RestIndexAnomalyDetectorAction(
Settings settings,
Expand All @@ -73,12 +77,16 @@ public RestIndexAnomalyDetectorAction(
this.requestTimeout = REQUEST_TIMEOUT.get(settings);
this.detectionInterval = DETECTION_INTERVAL.get(settings);
this.detectionWindowDelay = DETECTION_WINDOW_DELAY.get(settings);
this.maxAnomalyDetectors = MAX_ANOMALY_DETECTORS.get(settings);
this.maxAnomalyFeatures = MAX_ANOMALY_FEATURES.get(settings);
this.clusterService = clusterService;
// TODO: will add more cluster setting consumer later
// TODO: inject ClusterSettings only if clusterService is only used to get ClusterSettings
clusterService.getClusterSettings().addSettingsUpdateConsumer(REQUEST_TIMEOUT, it -> requestTimeout = it);
clusterService.getClusterSettings().addSettingsUpdateConsumer(DETECTION_INTERVAL, it -> detectionInterval = it);
clusterService.getClusterSettings().addSettingsUpdateConsumer(DETECTION_WINDOW_DELAY, it -> detectionWindowDelay = it);
clusterService.getClusterSettings().addSettingsUpdateConsumer(MAX_ANOMALY_DETECTORS, newVal -> maxAnomalyDetectors = newVal);
ylwu-amzn marked this conversation as resolved.
Show resolved Hide resolved
clusterService.getClusterSettings().addSettingsUpdateConsumer(MAX_ANOMALY_FEATURES, it -> maxAnomalyFeatures = it);
}

@Override
Expand Down Expand Up @@ -117,7 +125,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
primaryTerm,
refreshPolicy,
detector,
requestTimeout
requestTimeout,
maxAnomalyDetectors,
maxAnomalyFeatures
).start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
import java.util.Locale;

import static com.amazon.opendistroforelasticsearch.ad.model.AnomalyDetector.ANOMALY_DETECTORS_INDEX;
import static com.amazon.opendistroforelasticsearch.ad.settings.AnomalyDetectorSettings.MAX_ANOMALY_DETECTORS;
import static com.amazon.opendistroforelasticsearch.ad.settings.AnomalyDetectorSettings.MAX_ANOMALY_FEATURES;
import static com.amazon.opendistroforelasticsearch.ad.util.RestHandlerUtils.XCONTENT_WITH_TYPE;
import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS;

Expand All @@ -74,8 +72,8 @@ public class IndexAnomalyDetectorActionHandler extends AbstractActionHandler {

private final Logger logger = LogManager.getLogger(IndexAnomalyDetectorActionHandler.class);
private final TimeValue requestTimeout;
private volatile Integer maxAnomalyDetectors;
private volatile Integer maxAnomalyFeatures;
private final Integer maxAnomalyDetectors;
private final Integer maxAnomalyFeatures;
private final AnomalyDetectorActionHandler handler = new AnomalyDetectorActionHandler();

/**
Expand Down Expand Up @@ -104,7 +102,9 @@ public IndexAnomalyDetectorActionHandler(
Long primaryTerm,
WriteRequest.RefreshPolicy refreshPolicy,
AnomalyDetector anomalyDetector,
TimeValue requestTimeout
TimeValue requestTimeout,
Integer maxAnomalyDetectors,
Integer maxAnomalyFeatures
) {
super(client, channel);
this.clusterService = clusterService;
Expand All @@ -115,10 +115,8 @@ public IndexAnomalyDetectorActionHandler(
this.refreshPolicy = refreshPolicy;
this.anomalyDetector = anomalyDetector;
this.requestTimeout = requestTimeout;
maxAnomalyDetectors = MAX_ANOMALY_DETECTORS.get(settings);
maxAnomalyFeatures = MAX_ANOMALY_FEATURES.get(settings);
clusterService.getClusterSettings().addSettingsUpdateConsumer(MAX_ANOMALY_DETECTORS, it -> maxAnomalyDetectors = it);
clusterService.getClusterSettings().addSettingsUpdateConsumer(MAX_ANOMALY_FEATURES, it -> maxAnomalyFeatures = it);
this.maxAnomalyDetectors = maxAnomalyDetectors;
this.maxAnomalyFeatures = maxAnomalyFeatures;
}

/**
Expand Down