diff --git a/x-pack/docs/en/rest-api/watcher/stats.asciidoc b/x-pack/docs/en/rest-api/watcher/stats.asciidoc index 38f8ede925e4b..3f875485ba006 100644 --- a/x-pack/docs/en/rest-api/watcher/stats.asciidoc +++ b/x-pack/docs/en/rest-api/watcher/stats.asciidoc @@ -25,7 +25,7 @@ currently being executed by {watcher}. Additional information is shared per watch that is currently executing. This information includes the `watch_id`, the time its execution started and its current execution phase. -To include this metric, the `metric` option should be set to `executing_watches` +To include this metric, the `metric` option should be set to `current_watches` or `_all`. In addition you can also specify the `emit_stacktraces=true` parameter, which adds stack traces for each watch that is being executed. These stack traces can give you more insight into an execution of a watch. @@ -51,7 +51,7 @@ To include this metric, the `metric` option should include `queued_watches` or `metric`:: (enum) Defines which additional metrics are included in the response. - `executing_watches`::: Includes the current executing watches in the response. + `current_watches`::: Includes the current executing watches in the response. `queued_watches`::: Includes the watches queued for execution in the response. `_all`::: Includes all metrics in the response. @@ -98,7 +98,7 @@ and will include the basic metrics and metrics about the current executing watch [source,js] -------------------------------------------------- -GET _xpack/watcher/stats?metric=executing_watches +GET _xpack/watcher/stats?metric=current_watches -------------------------------------------------- // CONSOLE diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.watcher.stats.json b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.watcher.stats.json index 40eda835a4bc8..86c982a888151 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.watcher.stats.json +++ b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.watcher.stats.json @@ -8,14 +8,14 @@ "parts": { "metric": { "type" : "enum", - "options" : ["_all", "queued_watches", "pending_watches"], + "options" : ["_all", "queued_watches", "current_watches", "pending_watches"], "description" : "Controls what additional stat metrics should be include in the response" } }, "params": { "metric": { "type" : "enum", - "options" : ["_all", "queued_watches", "pending_watches"], + "options" : ["_all", "queued_watches", "current_watches", "pending_watches"], "description" : "Controls what additional stat metrics should be include in the response" }, "emit_stacktraces": { diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/stats/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/stats/10_basic.yml index 9844dea9135a3..5a90af3725294 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/stats/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/watcher/stats/10_basic.yml @@ -12,3 +12,55 @@ emit_stacktraces: "true" - match: { "manually_stopped": false } - match: { "stats.0.watcher_state": "started" } + +--- +"Test watcher stats current watches": + - skip: + version: " - 6.99.99" + reason: metrics were fixed in 7.0.0 + + - do: + xpack.watcher.stats: + metric: "current_watches" + + - is_false: stats.0.queued_watches + - is_true: stats.0.current_watches + +--- +"Test watcher stats queued watches": + - skip: + version: " - 6.99.99" + reason: metrics were fixed in 7.0.0 + + - do: + xpack.watcher.stats: + metric: "queued_watches" + + - is_false: stats.0.current_watches + - is_true: stats.0.queued_watches + +--- +"Test watcher stats queued watches using pending_watches": + - skip: + version: " - 6.99.99" + reason: metrics were fixed in 7.0.0 + features: warnings + + - do: + warnings: + - 'The pending_watches parameter is deprecated, use queued_watches instead' + + xpack.watcher.stats: + metric: "pending_watches" + + - is_false: stats.0.current_watches + - is_true: stats.0.queued_watches + +--- +"Test watcher stats all watches": + - do: + xpack.watcher.stats: + metric: "_all" + + - is_true: stats.0.current_watches + - is_true: stats.0.queued_watches diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java index 90c756c1323be..fad5b9cf93fa3 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java @@ -5,6 +5,9 @@ */ package org.elasticsearch.xpack.watcher.rest.action; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.RestController; @@ -21,6 +24,9 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestWatcherStatsAction extends WatcherRestHandler { + private static final Logger logger = LogManager.getLogger(RestWatcherStatsAction.class); + private static final DeprecationLogger deprecationLogger = new DeprecationLogger(logger); + public RestWatcherStatsAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(GET, URI_BASE + "/stats", this); @@ -41,8 +47,12 @@ protected RestChannelConsumer doPrepareRequest(final RestRequest restRequest, Wa request.includeCurrentWatches(true); request.includeQueuedWatches(true); } else { - request.includeCurrentWatches(metrics.contains("queued_watches")); - request.includeQueuedWatches(metrics.contains("pending_watches")); + request.includeCurrentWatches(metrics.contains("current_watches")); + request.includeQueuedWatches(metrics.contains("queued_watches") || metrics.contains("pending_watches")); + } + + if (metrics.contains("pending_watches")) { + deprecationLogger.deprecated("The pending_watches parameter is deprecated, use queued_watches instead"); }