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

change setting name and fix stop AD request #41

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -17,15 +17,15 @@

import com.amazon.opendistroforelasticsearch.ad.model.AnomalyDetector;
import com.amazon.opendistroforelasticsearch.ad.rest.handler.AnomalyDetectorActionHandler;
import com.amazon.opendistroforelasticsearch.ad.transport.DeleteDetectorAction;
import com.amazon.opendistroforelasticsearch.ad.transport.DeleteDetectorRequest;
import com.amazon.opendistroforelasticsearch.ad.transport.StopDetectorAction;
import com.amazon.opendistroforelasticsearch.ad.transport.StopDetectorRequest;
import com.amazon.opendistroforelasticsearch.ad.transport.StopDetectorResponse;
import com.amazon.opendistroforelasticsearch.ad.AnomalyDetectorPlugin;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.Settings;
Expand Down Expand Up @@ -89,8 +89,8 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
return channel -> {
if (channel.request().method() == RestRequest.Method.POST) {
logger.info("Stop anomaly detector {}", detectorId);
DeleteDetectorRequest deleteDetectorRequest = new DeleteDetectorRequest().adID(detectorId);
client.execute(DeleteDetectorAction.INSTANCE, deleteDetectorRequest, stopAdDetectorListener(channel, detectorId));
StopDetectorRequest stopDetectorRequest = new StopDetectorRequest(detectorId);
client.execute(StopDetectorAction.INSTANCE, stopDetectorRequest, stopAdDetectorListener(channel, detectorId));
} else if (channel.request().method() == RestRequest.Method.DELETE) {
logger.info("Delete anomaly detector {}", detectorId);
handler
Expand All @@ -117,11 +117,11 @@ private void deleteAnomalyDetectorDoc(
client.delete(deleteRequest, new RestStatusToXContentListener<>(channel));
}

private ActionListener<AcknowledgedResponse> stopAdDetectorListener(RestChannel channel, String detectorId) {
return new ActionListener<AcknowledgedResponse>() {
private ActionListener<StopDetectorResponse> stopAdDetectorListener(RestChannel channel, String detectorId) {
return new ActionListener<StopDetectorResponse>() {
@Override
public void onResponse(AcknowledgedResponse deleteDetectorResponse) {
if (deleteDetectorResponse.isAcknowledged()) {
public void onResponse(StopDetectorResponse stopDetectorResponse) {
if (stopDetectorResponse.success()) {
logger.info("AD model deleted successfully for detector {}", detectorId);
channel.sendResponse(new BytesRestResponse(RestStatus.OK, "AD model deleted successfully"));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,91 +29,103 @@ public final class AnomalyDetectorSettings {
private AnomalyDetectorSettings() {}

public static final Setting<Integer> MAX_ANOMALY_DETECTORS = Setting
.intSetting("ml.anomaly_detectors.max_anomaly_detectors", 1000, Setting.Property.NodeScope, Setting.Property.Dynamic);
.intSetting("opendistro.anomaly_detection.max_anomaly_detectors", 1000, Setting.Property.NodeScope, Setting.Property.Dynamic);

public static final Setting<Integer> MAX_ANOMALY_FEATURES = Setting
.intSetting("ml.anomaly_detectors.max_anomaly_features", 5, Setting.Property.NodeScope, Setting.Property.Dynamic);
.intSetting("opendistro.anomaly_detection.max_anomaly_features", 5, Setting.Property.NodeScope, Setting.Property.Dynamic);

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

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

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

public static final Setting<TimeValue> AD_RESULT_ROLLOVER_PERIOD = Setting
.positiveTimeSetting(
"ml.anomaly_detectors.ad_result_rollover_period",
"opendistro.anomaly_detection.ad_result_rollover_period",
TimeValue.timeValueHours(12),
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

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

public static final Setting<TimeValue> AD_RESULT_HISTORY_INDEX_MAX_AGE = Setting
.positiveTimeSetting(
"ml.anomaly_detectors.ad_result_history_max_age",
"opendistro.anomaly_detection.ad_result_history_max_age",
TimeValue.timeValueHours(24),
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

public static final Setting<Long> AD_RESULT_HISTORY_MAX_DOCS = Setting
.longSetting("ml.anomaly_detectors.ad_result_history_max_docs", 10000L, 0L, Setting.Property.NodeScope, Setting.Property.Dynamic);
.longSetting(
"opendistro.anomaly_detection.ad_result_history_max_docs",
10000L,
0L,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

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

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

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

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

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

public static final String ANOMALY_DETECTORS_INDEX_MAPPING_FILE = "mappings/anomaly-detectors.json";
public static final String ANOMALY_RESULTS_INDEX_MAPPING_FILE = "mappings/anomaly-results.json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void setUp() throws Exception {

settings = Settings
.builder()
.put("ml.anomaly_detectors.cluster_state_change_cooldown_minutes", TimeValue.timeValueMinutes(5))
.put("opendistro.anomaly_detection.cluster_state_change_cooldown_minutes", TimeValue.timeValueMinutes(5))
.build();
clock = mock(Clock.class);
when(clock.millis()).thenReturn(700000L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public class AnomalyDetectionIndicesTests extends ESIntegTestCase {
public void setup() {
settings = Settings
.builder()
.put("ml.anomaly_detectors.ad_result_history_rollover_period", TimeValue.timeValueHours(12))
.put("ml.anomaly_detectors.ad_result_history_max_age", TimeValue.timeValueHours(24))
.put("ml.anomaly_detectors.ad_result_history_max_docs", 10000L)
.put("ml.anomaly_detectors.request_timeout", TimeValue.timeValueSeconds(10))
.put("opendistro.anomaly_detection.ad_result_history_rollover_period", TimeValue.timeValueHours(12))
.put("opendistro.anomaly_detection.ad_result_history_max_age", TimeValue.timeValueHours(24))
.put("opendistro.anomaly_detection.ad_result_history_max_docs", 10000L)
.put("opendistro.anomaly_detection.request_timeout", TimeValue.timeValueSeconds(10))
.build();

Set<Setting<?>> clusterSettings = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public void setUp() throws Exception {
client = mock(Client.class);
Settings settings = Settings
.builder()
.put("ml.anomaly_detectors.max_retry_for_unresponsive_node", 3)
.put("ml.anomaly_detectors.ad_mute_minutes", TimeValue.timeValueMinutes(10))
.put("opendistro.anomaly_detection.max_retry_for_unresponsive_node", 3)
.put("opendistro.anomaly_detection.ad_mute_minutes", TimeValue.timeValueMinutes(10))
.build();
clock = mock(Clock.class);
duration = Duration.ofHours(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1093,8 +1093,8 @@ public void savingFailureTemplate(boolean throwEsRejectedExecutionException, int

Settings backoffSettings = Settings
.builder()
.put("ml.anomaly_detectors.max_retry_for_backoff", 2)
.put("ml.anomaly_detectors.backoff_initial_delay", TimeValue.timeValueMillis(1))
.put("opendistro.anomaly_detection.max_retry_for_backoff", 2)
.put("opendistro.anomaly_detection.backoff_initial_delay", TimeValue.timeValueMillis(1))
.build();

// These constructors register handler in transport service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void setUp() throws Exception {
threadPool = mock(ThreadPool.class);
indexNameResolver = mock(IndexNameExpressionResolver.class);
actionFilters = mock(ActionFilters.class);
Settings settings = Settings.builder().put("ml.anomaly_detectors.request_timeout", TimeValue.timeValueSeconds(10)).build();
Settings settings = Settings.builder().put("opendistro.anomaly_detection.request_timeout", TimeValue.timeValueSeconds(10)).build();
task = mock(Task.class);
when(task.getId()).thenReturn(1000L);
client = mock(Client.class);
Expand Down