-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[ML] Auditor reset fix #136363
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
Merged
Merged
[ML] Auditor reset fix #136363
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
.../plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/ResetAuditorAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.ml.action; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.FailedNodeException; | ||
import org.elasticsearch.action.support.nodes.BaseNodeResponse; | ||
import org.elasticsearch.action.support.nodes.BaseNodesRequest; | ||
import org.elasticsearch.action.support.nodes.BaseNodesResponse; | ||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.transport.AbstractTransportRequest; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class ResetAuditorAction extends ActionType<TrainedModelCacheInfoAction.Response> { | ||
|
||
public static final ResetAuditorAction INSTANCE = new ResetAuditorAction(); | ||
public static final String NAME = "cluster:internal/xpack/ml/auditor/reset"; | ||
|
||
private ResetAuditorAction() { | ||
super(NAME); | ||
} | ||
|
||
public static class Request extends BaseNodesRequest { | ||
|
||
public static Request RESET_AUDITOR_REQUEST = new Request(); | ||
|
||
private Request() { | ||
super(new String[] { "ml:true" }); // Only ml nodes. See DiscoveryNodes::resolveNodes | ||
} | ||
} | ||
|
||
public static class NodeRequest extends AbstractTransportRequest { | ||
|
||
public NodeRequest(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
public NodeRequest() {} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(); | ||
} | ||
} | ||
|
||
public static class Response extends BaseNodesResponse<Response.ResetResponse> { | ||
|
||
public Response(ClusterName clusterName, List<ResetResponse> nodes, List<FailedNodeException> failures) { | ||
super(clusterName, nodes, failures); | ||
} | ||
|
||
protected Response(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
public static class ResetResponse extends BaseNodeResponse { | ||
private final boolean acknowledged; | ||
|
||
public ResetResponse(DiscoveryNode node, boolean acknowledged) { | ||
super(node); | ||
this.acknowledged = acknowledged; | ||
} | ||
|
||
public ResetResponse(StreamInput in) throws IOException { | ||
super(in, null); | ||
acknowledged = in.readBoolean(); | ||
} | ||
|
||
public ResetResponse(StreamInput in, DiscoveryNode node) throws IOException { | ||
super(in, node); | ||
acknowledged = in.readBoolean(); | ||
} | ||
|
||
public boolean isAcknowledged() { | ||
return acknowledged; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeBoolean(acknowledged); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ResetResponse that = (ResetResponse) o; | ||
return acknowledged == that.acknowledged; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(acknowledged); | ||
} | ||
} | ||
|
||
@Override | ||
protected List<Response.ResetResponse> readNodesFrom(StreamInput in) throws IOException { | ||
return in.readCollectionAsList(ResetResponse::new); | ||
} | ||
|
||
@Override | ||
protected void writeNodesTo(StreamOutput out, List<Response.ResetResponse> nodes) throws IOException { | ||
out.writeCollection(nodes); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...lugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportResetAuditorAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.ml.action; | ||
|
||
import org.elasticsearch.action.FailedNodeException; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.action.support.nodes.TransportNodesAction; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.injection.guice.Inject; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.elasticsearch.xpack.core.ml.action.ResetAuditorAction; | ||
import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; | ||
import org.elasticsearch.xpack.ml.notifications.DataFrameAnalyticsAuditor; | ||
import org.elasticsearch.xpack.ml.notifications.InferenceAuditor; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class TransportResetAuditorAction extends TransportNodesAction< | ||
ResetAuditorAction.Request, | ||
ResetAuditorAction.Response, | ||
ResetAuditorAction.NodeRequest, | ||
ResetAuditorAction.Response.ResetResponse, | ||
Void> { | ||
|
||
private final AnomalyDetectionAuditor anomalyDetectionAuditor; | ||
private final DataFrameAnalyticsAuditor dfaAuditor; | ||
private final InferenceAuditor inferenceAuditor; | ||
|
||
@Inject | ||
public TransportResetAuditorAction( | ||
ThreadPool threadPool, | ||
ClusterService clusterService, | ||
TransportService transportService, | ||
ActionFilters actionFilters, | ||
AnomalyDetectionAuditor anomalyDetectionAuditor, | ||
DataFrameAnalyticsAuditor dfaAuditor, | ||
InferenceAuditor inferenceAuditor | ||
) { | ||
super( | ||
ResetAuditorAction.NAME, | ||
clusterService, | ||
transportService, | ||
actionFilters, | ||
ResetAuditorAction.NodeRequest::new, | ||
threadPool.executor(ThreadPool.Names.MANAGEMENT) | ||
); | ||
this.anomalyDetectionAuditor = anomalyDetectionAuditor; | ||
this.dfaAuditor = dfaAuditor; | ||
this.inferenceAuditor = inferenceAuditor; | ||
} | ||
|
||
@Override | ||
protected ResetAuditorAction.Response newResponse( | ||
ResetAuditorAction.Request request, | ||
List<ResetAuditorAction.Response.ResetResponse> resetResponses, | ||
List<FailedNodeException> failures | ||
) { | ||
return new ResetAuditorAction.Response(clusterService.getClusterName(), resetResponses, failures); | ||
} | ||
|
||
@Override | ||
protected ResetAuditorAction.NodeRequest newNodeRequest(ResetAuditorAction.Request request) { | ||
return new ResetAuditorAction.NodeRequest(); | ||
} | ||
|
||
@Override | ||
protected ResetAuditorAction.Response.ResetResponse newNodeResponse(StreamInput in, DiscoveryNode node) throws IOException { | ||
return new ResetAuditorAction.Response.ResetResponse(in); | ||
} | ||
|
||
@Override | ||
protected ResetAuditorAction.Response.ResetResponse nodeOperation(ResetAuditorAction.NodeRequest request, Task task) { | ||
anomalyDetectionAuditor.reset(); | ||
dfaAuditor.reset(); | ||
inferenceAuditor.reset(); | ||
return new ResetAuditorAction.Response.ResetResponse(clusterService.localNode(), true); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
isResetMode
logic does not appear to be necessary and is removed it to avoid sending 2 different messages (the first to enable reset mode and the second to disable it). CI may tell a different story.