-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[ML] Add "close_job" parameter to the stop datafeed API #138634
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
Open
edsavage
wants to merge
7
commits into
elastic:main
Choose a base branch
from
edsavage:stop_datafeed_close_job_param
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
95b7158
[ML] Add "close_job" parameter to the stop datafeed API
edsavage 9db3b44
Update docs/changelog/138634.yaml
edsavage 42a855e
Slight tweak to DatafeedJobsIT
edsavage edd88b1
Merge branch 'main' of github.com:elasticsearch/elasticsearch into st…
edsavage ee9f237
Merge remote-tracking branch 'origin/stop_datafeed_close_job_param' i…
edsavage aaeb811
Update rest-api-spec documentation
edsavage 53e76ff
Merge branch 'main' of github.com:elasticsearch/elasticsearch into st…
edsavage 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
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,6 @@ | ||
| pr: 138634 | ||
| summary: Add "close_job" parameter to the stop datafeed API | ||
| area: Machine Learning | ||
| type: enhancement | ||
| issues: | ||
| - 138010 |
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
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
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
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
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 | ||
|---|---|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |||
| import org.elasticsearch.action.FailedNodeException; | ||||
| import org.elasticsearch.action.TaskOperationFailure; | ||||
| import org.elasticsearch.action.support.ActionFilters; | ||||
| import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||||
| import org.elasticsearch.action.support.tasks.TransportTasksAction; | ||||
| import org.elasticsearch.client.internal.Client; | ||||
| import org.elasticsearch.client.internal.OriginSettingClient; | ||||
|
|
@@ -27,7 +28,9 @@ | |||
| import org.elasticsearch.common.util.concurrent.ConcurrentCollections; | ||||
| import org.elasticsearch.common.util.concurrent.EsExecutors; | ||||
| import org.elasticsearch.core.FixForMultiProject; | ||||
| import org.elasticsearch.core.Predicates; | ||||
| import org.elasticsearch.core.TimeValue; | ||||
| import org.elasticsearch.core.Tuple; | ||||
| import org.elasticsearch.discovery.MasterNotDiscoveredException; | ||||
| import org.elasticsearch.injection.guice.Inject; | ||||
| import org.elasticsearch.persistent.PersistentTasksClusterService; | ||||
|
|
@@ -39,6 +42,7 @@ | |||
| import org.elasticsearch.transport.TransportResponseHandler; | ||||
| import org.elasticsearch.transport.TransportService; | ||||
| import org.elasticsearch.xpack.core.ml.MlTasks; | ||||
| import org.elasticsearch.xpack.core.ml.action.CloseJobAction; | ||||
| import org.elasticsearch.xpack.core.ml.action.StartDatafeedAction; | ||||
| import org.elasticsearch.xpack.core.ml.action.StopDatafeedAction; | ||||
| import org.elasticsearch.xpack.core.ml.datafeed.DatafeedState; | ||||
|
|
@@ -48,6 +52,7 @@ | |||
| import org.elasticsearch.xpack.ml.MachineLearning; | ||||
| import org.elasticsearch.xpack.ml.datafeed.persistence.DatafeedConfigProvider; | ||||
| import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; | ||||
| import org.elasticsearch.xpack.ml.utils.TypedChainTaskExecutor; | ||||
|
|
||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
|
|
@@ -58,8 +63,10 @@ | |||
| import java.util.concurrent.atomic.AtomicInteger; | ||||
| import java.util.stream.Collectors; | ||||
|
|
||||
| import static java.util.stream.Collectors.toList; | ||||
| import static org.elasticsearch.core.Strings.format; | ||||
| import static org.elasticsearch.xpack.core.ClientHelper.ML_ORIGIN; | ||||
| import static org.elasticsearch.xpack.core.ClientHelper.executeAsyncWithOrigin; | ||||
| import static org.elasticsearch.xpack.ml.utils.ExceptionCollectionHandling.exceptionArrayToStatusException; | ||||
|
|
||||
| public class TransportStopDatafeedAction extends TransportTasksAction< | ||||
|
|
@@ -106,7 +113,7 @@ public TransportStopDatafeedAction( | |||
| } | ||||
|
|
||||
| /** | ||||
| * Sort the datafeed IDs the their task state and add to one | ||||
| * Sort the datafeed IDs by their task state and add to one | ||||
| * of the list arguments depending on the state. | ||||
| * | ||||
| * @param expandedDatafeedIds The expanded set of IDs | ||||
|
|
@@ -211,7 +218,64 @@ private void doExecute( | |||
| if (request.isForce()) { | ||||
| forceStopDatafeed(request, listener, tasks, nodes, notStoppedDatafeeds); | ||||
| } else { | ||||
| normalStopDatafeed(task, request, listener, tasks, nodes, startedDatafeeds, stoppingDatafeeds, attempt); | ||||
| final List<String> startedDatafeedsJobs = new ArrayList<>(); | ||||
| for (String datafeedId : startedDatafeeds) { | ||||
| PersistentTasksCustomMetadata.PersistentTask<?> datafeedTask = MlTasks.getDatafeedTask(datafeedId, tasks); | ||||
| if (datafeedTask != null | ||||
| && PersistentTasksClusterService.needsReassignment(datafeedTask.getAssignment(), nodes) == false) { | ||||
| startedDatafeedsJobs.add(((StartDatafeedAction.DatafeedParams) datafeedTask.getParams()).getJobId()); | ||||
| } | ||||
| } | ||||
| if (request.closeJob() && startedDatafeedsJobs.isEmpty() == false) { | ||||
| // If the "close_job" parameter was set to "true" on the stop datafeed request we attempt to first close the | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the close jobs action where the datafeed is stopped please explicitly set close job to false so when looking at that code we are aware of this interation Line 329 in 88b5900
|
||||
| // jobs associated with the datafeeds. This will in turn attempt to stop the jobs' datafeeds (this time with the | ||||
| // "close_job" flag set to false, to avoid recursion) | ||||
| ActionListener<List<Tuple<String, AcknowledgedResponse>>> closeJobActionListener = listener | ||||
| .delegateFailureAndWrap((delegate, jobsResponses) -> { | ||||
| List<String> jobIds = jobsResponses.stream() | ||||
| .filter(t -> t.v2().isAcknowledged() == false) | ||||
| .map(Tuple::v1) | ||||
| .collect(toList()); | ||||
| if (jobIds.isEmpty()) { | ||||
| logger.debug("Successfully closed jobs (and associated datafeeds)"); | ||||
| } else { | ||||
| logger.warn("Failed to close jobs (and associated datafeeds): {}", jobIds); | ||||
| } | ||||
| delegate.onResponse(new StopDatafeedAction.Response(true)); | ||||
| }); | ||||
|
|
||||
| TypedChainTaskExecutor<Tuple<String, AcknowledgedResponse>> chainTaskExecutor = new TypedChainTaskExecutor<>( | ||||
| EsExecutors.DIRECT_EXECUTOR_SERVICE, | ||||
| Predicates.always(), | ||||
| Predicates.always() | ||||
| ); | ||||
| for (String jobId : startedDatafeedsJobs) { | ||||
| chainTaskExecutor.add( | ||||
| al -> executeAsyncWithOrigin( | ||||
| client, | ||||
| ML_ORIGIN, | ||||
| CloseJobAction.INSTANCE, | ||||
| new CloseJobAction.Request(jobId), | ||||
| listener.delegateFailureAndWrap( | ||||
| (l, response) -> l.onResponse(new StopDatafeedAction.Response(response.isClosed())) | ||||
| ) | ||||
| ) | ||||
| ); | ||||
| } | ||||
| chainTaskExecutor.execute(closeJobActionListener); | ||||
| } else { | ||||
| normalStopDatafeed( | ||||
| task, | ||||
| request, | ||||
| listener, | ||||
| tasks, | ||||
| nodes, | ||||
| startedDatafeeds, | ||||
| stoppingDatafeeds, | ||||
| startedDatafeedsJobs, | ||||
| attempt | ||||
| ); | ||||
| } | ||||
| } | ||||
| }, listener::onFailure) | ||||
| ); | ||||
|
|
@@ -226,10 +290,10 @@ private void normalStopDatafeed( | |||
| DiscoveryNodes nodes, | ||||
| List<String> startedDatafeeds, | ||||
| List<String> stoppingDatafeeds, | ||||
| List<String> startedDatafeedsJobs, | ||||
| int attempt | ||||
| ) { | ||||
| final Set<String> executorNodes = new HashSet<>(); | ||||
| final List<String> startedDatafeedsJobs = new ArrayList<>(); | ||||
| final List<String> resolvedStartedDatafeeds = new ArrayList<>(); | ||||
| final List<PersistentTasksCustomMetadata.PersistentTask<?>> allDataFeedsToWaitFor = new ArrayList<>(); | ||||
| for (String datafeedId : startedDatafeeds) { | ||||
|
|
@@ -240,7 +304,6 @@ private void normalStopDatafeed( | |||
| assert datafeedTask != null : msg; | ||||
| logger.error(msg); | ||||
| } else if (PersistentTasksClusterService.needsReassignment(datafeedTask.getAssignment(), nodes) == false) { | ||||
| startedDatafeedsJobs.add(((StartDatafeedAction.DatafeedParams) datafeedTask.getParams()).getJobId()); | ||||
| resolvedStartedDatafeeds.add(datafeedId); | ||||
| executorNodes.add(datafeedTask.getExecutorNode()); | ||||
| allDataFeedsToWaitFor.add(datafeedTask); | ||||
|
|
||||
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
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.
Are
closeJobParameterandjobStateused in this method?