From 1121a15eb7061a3bfb5443080ea67bfeae19f976 Mon Sep 17 00:00:00 2001 From: Alexander Reelsen Date: Thu, 31 Aug 2017 09:19:07 +0200 Subject: [PATCH] Watcher: Ensure emit_stacktraces parameter works in watcher stats (elastic/x-pack-elasticsearch#2399) This parameter ceased to work when Elasticsearch 5 introduced strict parameter handling, because of a missing test. This commit adds the parameter to the rest handler responseParams() and adds a test along with the needed YAML definition. relates elastic/x-pack-elasticsearch#2396 Original commit: elastic/x-pack-elasticsearch@8638df336c338ce0571d0dbe98a07a16673b69d5 --- .../watcher/rest/action/RestWatcherStatsAction.java | 10 ++++++++++ .../rest-api-spec/api/xpack.watcher.stats.json | 5 +++++ .../rest-api-spec/test/watcher/stats/10_basic.yml | 10 ++++++++++ 3 files changed, 25 insertions(+) diff --git a/plugin/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java b/plugin/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java index d16b2d6ae0b..6cbff4e7753 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java @@ -15,6 +15,7 @@ import org.elasticsearch.xpack.watcher.rest.WatcherRestHandler; import org.elasticsearch.xpack.watcher.transport.actions.stats.WatcherStatsRequest; import java.io.IOException; +import java.util.Collections; import java.util.Set; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -47,4 +48,13 @@ public class RestWatcherStatsAction extends WatcherRestHandler { return channel -> client.watcherStats(request, new RestActions.NodesResponseRestListener<>(channel)); } + + private static final Set RESPONSE_PARAMS = Collections.singleton("emit_stacktraces"); + + @Override + protected Set responseParams() { + // this parameter is only needed when current watches are supposed to be returned + // it's used in the WatchExecutionContext.toXContent() method + return RESPONSE_PARAMS; + } } diff --git a/plugin/src/test/resources/rest-api-spec/api/xpack.watcher.stats.json b/plugin/src/test/resources/rest-api-spec/api/xpack.watcher.stats.json index 089e42d80e1..40eda835a4b 100644 --- a/plugin/src/test/resources/rest-api-spec/api/xpack.watcher.stats.json +++ b/plugin/src/test/resources/rest-api-spec/api/xpack.watcher.stats.json @@ -17,6 +17,11 @@ "type" : "enum", "options" : ["_all", "queued_watches", "pending_watches"], "description" : "Controls what additional stat metrics should be include in the response" + }, + "emit_stacktraces": { + "type" : "boolean", + "description" : "Emits stack traces of currently running watches", + "required" : false } } }, diff --git a/plugin/src/test/resources/rest-api-spec/test/watcher/stats/10_basic.yml b/plugin/src/test/resources/rest-api-spec/test/watcher/stats/10_basic.yml index d98aab11304..6fa66667e26 100644 --- a/plugin/src/test/resources/rest-api-spec/test/watcher/stats/10_basic.yml +++ b/plugin/src/test/resources/rest-api-spec/test/watcher/stats/10_basic.yml @@ -4,3 +4,13 @@ - do: {xpack.watcher.stats: {}} - match: { "manually_stopped": false } - match: { "stats.0.watcher_state": "started" } + +--- +"Test watcher stats supports emit_stacktraces parameter": + + - do: + xpack.watcher.stats: + metric: "all" + emit_stacktraces: "true" + - match: { "manually_stopped": false } + - match: { "stats.0.watcher_state": "started" }