Skip to content

Commit

Permalink
Validate Detector Rest Handler
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <widdis@gmail.com>
  • Loading branch information
dbwiddis committed Jan 28, 2023
1 parent c25ab85 commit c1787b5
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 428 deletions.
12 changes: 7 additions & 5 deletions src/main/java/org/opensearch/ad/AnomalyDetectorExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import java.util.stream.Stream;

import org.opensearch.ad.rest.RestGetDetectorAction;
import org.opensearch.ad.rest.RestIndexAnomalyDetectorSDKAction;
import org.opensearch.ad.rest.RestValidateDetectorAction;
import org.opensearch.ad.rest.RestIndexAnomalyDetectorAction;
import org.opensearch.ad.rest.RestValidateAnomalyDetectorAction;
import org.opensearch.ad.settings.AnomalyDetectorSettings;
import org.opensearch.ad.settings.EnabledSetting;
import org.opensearch.client.opensearch.OpenSearchClient;
Expand All @@ -45,11 +45,13 @@ public AnomalyDetectorExtension() {
public List<ExtensionRestHandler> getExtensionRestHandlers() {
return List
.of(
new RestIndexAnomalyDetectorSDKAction(extensionsRunner, this),
new RestIndexAnomalyDetectorAction(extensionsRunner, this),
// FIXME delete this
// new RestCreateDetectorAction(extensionsRunner, this),
new RestGetDetectorAction(),
new RestValidateDetectorAction(extensionsRunner, this)
new RestValidateAnomalyDetectorAction(extensionsRunner, this),
new RestGetDetectorAction()
// FIXME delete this
// new RestValidateDetectorAction(extensionsRunner, this)
);
}

Expand Down
33 changes: 16 additions & 17 deletions src/main/java/org/opensearch/ad/AnomalyDetectorPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.opensearch.ad.ml.HybridThresholdingModel;
import org.opensearch.ad.ml.ModelManager;
import org.opensearch.ad.ratelimit.CheckpointWriteWorker;
import org.opensearch.ad.rest.RestIndexAnomalyDetectorAction;
import org.opensearch.ad.settings.AnomalyDetectorSettings;
import org.opensearch.ad.settings.EnabledSetting;
import org.opensearch.ad.stats.ADStats;
Expand Down Expand Up @@ -165,8 +164,8 @@ public List<RestHandler> getRestHandlers(
jobRunner.setAdTaskManager(adTaskManager);
RestGetAnomalyDetectorAction restGetAnomalyDetectorAction = new RestGetAnomalyDetectorAction();
*/
RestIndexAnomalyDetectorAction restIndexAnomalyDetectorAction = new RestIndexAnomalyDetectorAction(settings, clusterService);
*/
/* @anomaly-detection.create-detector
RestSearchAnomalyDetectorAction searchAnomalyDetectorAction = new RestSearchAnomalyDetectorAction();
RestSearchAnomalyResultAction searchAnomalyResultAction = new RestSearchAnomalyResultAction();
Expand All @@ -184,21 +183,21 @@ public List<RestHandler> getRestHandlers(
return ImmutableList
.of(
// restGetAnomalyDetectorAction,
restIndexAnomalyDetectorAction
/* @anomaly-detection.create-detector
searchAnomalyDetectorAction,
searchAnomalyResultAction,
searchADTasksAction,
deleteAnomalyDetectorAction,
executeAnomalyDetectorAction,
anomalyDetectorJobAction,
statsAnomalyDetectorAction,
searchAnomalyDetectorInfoAction,
previewAnomalyDetectorAction,
deleteAnomalyResultsAction,
searchTopAnomalyResultAction,
validateAnomalyDetectorAction
*/
// restIndexAnomalyDetectorAction
/* @anomaly-detection.create-detector
searchAnomalyDetectorAction,
searchAnomalyResultAction,
searchADTasksAction,
deleteAnomalyDetectorAction,
executeAnomalyDetectorAction,
anomalyDetectorJobAction,
statsAnomalyDetectorAction,
searchAnomalyDetectorInfoAction,
previewAnomalyDetectorAction,
deleteAnomalyResultsAction,
searchTopAnomalyResultAction,
validateAnomalyDetectorAction
*/
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@
import static org.opensearch.ad.settings.AnomalyDetectorSettings.MAX_SINGLE_ENTITY_ANOMALY_DETECTORS;
import static org.opensearch.ad.settings.AnomalyDetectorSettings.REQUEST_TIMEOUT;

import org.opensearch.cluster.service.ClusterService;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.sdk.BaseExtensionRestHandler;
import org.opensearch.sdk.ExtensionsRunner;
import org.opensearch.sdk.SDKClusterService;

public abstract class AbstractAnomalyDetectorAction extends BaseRestHandler {
public abstract class AbstractAnomalyDetectorAction extends BaseExtensionRestHandler {

protected volatile TimeValue requestTimeout;
protected volatile TimeValue detectionInterval;
Expand All @@ -32,24 +38,28 @@ public abstract class AbstractAnomalyDetectorAction extends BaseRestHandler {
protected volatile Integer maxMultiEntityDetectors;
protected volatile Integer maxAnomalyFeatures;

public AbstractAnomalyDetectorAction(Settings settings, ClusterService clusterService) {
this.requestTimeout = REQUEST_TIMEOUT.get(settings);
this.detectionInterval = DETECTION_INTERVAL.get(settings);
this.detectionWindowDelay = DETECTION_WINDOW_DELAY.get(settings);
this.maxSingleEntityDetectors = MAX_SINGLE_ENTITY_ANOMALY_DETECTORS.get(settings);
this.maxMultiEntityDetectors = MAX_MULTI_ENTITY_ANOMALY_DETECTORS.get(settings);
this.maxAnomalyFeatures = MAX_ANOMALY_FEATURES.get(settings);
public AbstractAnomalyDetectorAction(ExtensionsRunner extensionsRunner) {
Settings environmentSettings = extensionsRunner.getEnvironmentSettings();
this.requestTimeout = REQUEST_TIMEOUT.get(environmentSettings);
this.detectionInterval = DETECTION_INTERVAL.get(environmentSettings);
this.detectionWindowDelay = DETECTION_WINDOW_DELAY.get(environmentSettings);
this.maxSingleEntityDetectors = MAX_SINGLE_ENTITY_ANOMALY_DETECTORS.get(environmentSettings);
this.maxMultiEntityDetectors = MAX_MULTI_ENTITY_ANOMALY_DETECTORS.get(environmentSettings);
this.maxAnomalyFeatures = MAX_ANOMALY_FEATURES.get(environmentSettings);
// 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_SINGLE_ENTITY_ANOMALY_DETECTORS, it -> maxSingleEntityDetectors = it);
clusterService
.getClusterSettings()
.addSettingsUpdateConsumer(MAX_MULTI_ENTITY_ANOMALY_DETECTORS, it -> maxMultiEntityDetectors = it);
clusterService.getClusterSettings().addSettingsUpdateConsumer(MAX_ANOMALY_FEATURES, it -> maxAnomalyFeatures = it);
Map<Setting<?>, Consumer<?>> settingToConsumerMap = new HashMap<>();
settingToConsumerMap.put(REQUEST_TIMEOUT, it -> requestTimeout = (TimeValue) it);
settingToConsumerMap.put(DETECTION_INTERVAL, it -> detectionInterval = (TimeValue) it);
settingToConsumerMap.put(DETECTION_WINDOW_DELAY, it -> detectionWindowDelay = (TimeValue) it);
settingToConsumerMap.put(MAX_SINGLE_ENTITY_ANOMALY_DETECTORS, it -> maxSingleEntityDetectors = (Integer) it);
settingToConsumerMap.put(MAX_MULTI_ENTITY_ANOMALY_DETECTORS, it -> maxMultiEntityDetectors = (Integer) it);
settingToConsumerMap.put(MAX_ANOMALY_FEATURES, it -> maxAnomalyFeatures = (Integer) it);
SDKClusterService clusterService = new SDKClusterService(extensionsRunner);
try {
clusterService.addSettingsUpdateConsumer(settingToConsumerMap);
} catch (Exception e) {
// FIXME handle this
}
}
}

This file was deleted.

Loading

0 comments on commit c1787b5

Please sign in to comment.