Skip to content

Commit 023d579

Browse files
Enable Setting Master Node Timeout in Watcher Start/Stop Requests (#70425)
It's in the title, we have to be able to set this timeout. Otherwise, it's impossible to deactive/active watcher or a slow master node. In the worst case scenario, Wacher may be at fault for making the master slow and it becomes impossible to deactive it.
1 parent 17d56d3 commit 023d579

File tree

4 files changed

+32
-31
lines changed

4 files changed

+32
-31
lines changed

x-pack/docs/en/rest-api/watcher/start.asciidoc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ information, see <<security-privileges>>.
2424
//[[watcher-api-start-path-params]]
2525
//==== {api-path-parms-title}
2626

27-
//[[watcher-api-start-query-params]]
28-
//==== {api-query-parms-title}
27+
[[watcher-api-start-query-params]]
28+
==== {api-query-parms-title}
29+
30+
`master_timeout`::
31+
(Optional, <<time-units, time units>>) Specifies the period of time to wait for
32+
a connection to the master node. If no response is received before the timeout
33+
expires, the request fails and returns an error. Defaults to `30s`.
2934

3035
//[[watcher-api-start-request-body]]
3136
//==== {api-request-body-title}

x-pack/docs/en/rest-api/watcher/stop.asciidoc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ information, see <<security-privileges>>.
2424
//[[watcher-api-stop-path-params]]
2525
//==== {api-path-parms-title}
2626

27-
//[[watcher-api-stop-query-params]]
28-
//==== {api-query-parms-title}
27+
[[watcher-api-stop-query-params]]
28+
==== {api-query-parms-title}
29+
30+
`master_timeout`::
31+
(Optional, <<time-units, time units>>) Specifies the period of time to wait for
32+
a connection to the master node. If no response is received before the timeout
33+
expires, the request fails and returns an error. Defaults to `30s`.
2934

3035
//[[watcher-api-stop-request-body]]
3136
//==== {api-request-body-title}

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatchServiceAction.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ public String getName() {
4949
}
5050

5151
@Override
52-
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) {
53-
return channel ->
54-
client.execute(WatcherServiceAction.INSTANCE, new WatcherServiceRequest().stop(), new RestToXContentListener<>(channel));
52+
public RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) {
53+
final WatcherServiceRequest request = new WatcherServiceRequest().stop();
54+
request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout()));
55+
return channel -> client.execute(WatcherServiceAction.INSTANCE, request, new RestToXContentListener<>(channel));
5556
}
5657
}
5758
}

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/TransportWatcherServiceAction.java

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,6 @@ public class TransportWatcherServiceAction extends AcknowledgedTransportMasterNo
3636

3737
private static final Logger logger = LogManager.getLogger(TransportWatcherServiceAction.class);
3838

39-
private static final AckedRequest ackedRequest = new AckedRequest() {
40-
@Override
41-
public TimeValue ackTimeout() {
42-
return AcknowledgedRequest.DEFAULT_ACK_TIMEOUT;
43-
}
44-
45-
@Override
46-
public TimeValue masterNodeTimeout() {
47-
return AcknowledgedRequest.DEFAULT_ACK_TIMEOUT;
48-
}
49-
};
50-
5139
@Inject
5240
public TransportWatcherServiceAction(TransportService transportService, ClusterService clusterService,
5341
ThreadPool threadPool, ActionFilters actionFilters,
@@ -59,20 +47,22 @@ public TransportWatcherServiceAction(TransportService transportService, ClusterS
5947
@Override
6048
protected void masterOperation(Task task, WatcherServiceRequest request, ClusterState state,
6149
ActionListener<AcknowledgedResponse> listener) {
62-
switch (request.getCommand()) {
63-
case STOP:
64-
setWatcherMetadataAndWait(true, listener);
65-
break;
66-
case START:
67-
setWatcherMetadataAndWait(false, listener);
68-
break;
69-
}
70-
}
50+
final boolean manuallyStopped = request.getCommand() == WatcherServiceRequest.Command.STOP;
51+
final String source = manuallyStopped ? "update_watcher_manually_stopped" : "update_watcher_manually_started";
7152

72-
private void setWatcherMetadataAndWait(boolean manuallyStopped, final ActionListener<AcknowledgedResponse> listener) {
73-
String source = manuallyStopped ? "update_watcher_manually_stopped" : "update_watcher_manually_started";
53+
// TODO: make WatcherServiceRequest a real AckedRequest so that we have both a configurable timeout and master node timeout like
54+
// we do elsewhere
55+
clusterService.submitStateUpdateTask(source, new AckedClusterStateUpdateTask(new AckedRequest() {
56+
@Override
57+
public TimeValue ackTimeout() {
58+
return AcknowledgedRequest.DEFAULT_ACK_TIMEOUT;
59+
}
7460

75-
clusterService.submitStateUpdateTask(source, new AckedClusterStateUpdateTask(ackedRequest, listener) {
61+
@Override
62+
public TimeValue masterNodeTimeout() {
63+
return request.masterNodeTimeout();
64+
}
65+
}, listener) {
7666
@Override
7767
public ClusterState execute(ClusterState clusterState) {
7868
XPackPlugin.checkReadyForXPackCustomMetadata(clusterState);

0 commit comments

Comments
 (0)