Skip to content

Commit 57eaa54

Browse files
Enable Setting Master Node Timeout in Watcher Start/Stop Requests (#70425) (#70433)
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 d9e4586 commit 57eaa54

File tree

4 files changed

+32
-30
lines changed

4 files changed

+32
-30
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ public String getName() {
5959
}
6060

6161
@Override
62-
public RestChannelConsumer doPrepareRequest(RestRequest request, WatcherClient client) {
63-
return channel -> client.watcherService(new WatcherServiceRequest().stop(), new RestToXContentListener<>(channel));
62+
public RestChannelConsumer doPrepareRequest(RestRequest restRequest, WatcherClient client) {
63+
final WatcherServiceRequest request = new WatcherServiceRequest().stop();
64+
request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout()));
65+
return channel -> client.watcherService(request, new RestToXContentListener<>(channel));
6466
}
6567
}
6668
}

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
@@ -35,18 +35,6 @@ public class TransportWatcherServiceAction extends AcknowledgedTransportMasterNo
3535

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

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

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

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

0 commit comments

Comments
 (0)