From cf2a5638c343b2c907500342d8734d1def0feaee Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Wed, 26 May 2021 13:26:20 -0400 Subject: [PATCH 1/3] Resurrect the removed hot threads endpoints --- .../cluster/RestNodesHotThreadsAction.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java index 5d7f1c9a6b2d0..1f300fdc97e4e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java @@ -13,6 +13,7 @@ import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.RestApiVersion; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; @@ -23,16 +24,59 @@ import java.io.IOException; import java.util.List; +import java.util.Locale; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestNodesHotThreadsAction extends BaseRestHandler { + private static final String formatDeprecatedMessageWithoutNodeID = "[%s] is a deprecated endpoint. " + + "Please use [/_nodes/hot_threads] instead."; + private static final String formatDeprecatedMessageWithNodeID = "[%s] is a deprecated endpoint. " + + "Please use [/_nodes/{nodeId}/hot_threads] instead."; + private static final String DEPRECATED_MESSAGE_CLUSTER_NODES_HOT_THREADS = String.format(Locale.ROOT, + formatDeprecatedMessageWithoutNodeID, + "/_cluster/nodes/hot_threads" + ); + private static final String DEPRECATED_MESSAGE_CLUSTER_NODES_NODEID_HOT_THREADS = String.format(Locale.ROOT, + formatDeprecatedMessageWithNodeID, + "/_cluster/nodes/{nodeId}/hot_threads" + ); + private static final String DEPRECATED_MESSAGE_CLUSTER_NODES_HOTTHREADS = String.format(Locale.ROOT, + formatDeprecatedMessageWithoutNodeID, + "/_cluster/nodes/hotthreads" + ); + private static final String DEPRECATED_MESSAGE_CLUSTER_NODES_NODEID_HOTTHREADS = String.format(Locale.ROOT, + formatDeprecatedMessageWithNodeID, + "/_cluster/nodes/{nodeId}/hotthreads" + ); + private static final String DEPRECATED_MESSAGE_NODES_HOTTHREADS = String.format(Locale.ROOT, + formatDeprecatedMessageWithoutNodeID, + "/_nodes/hotthreads" + ); + private static final String DEPRECATED_MESSAGE_NODES_NODEID_HOTTHREADS = String.format(Locale.ROOT, + formatDeprecatedMessageWithNodeID, + "/_nodes/{nodeId}/hotthreads" + ); + @Override public List routes() { return List.of( new Route(GET, "/_nodes/hot_threads"), - new Route(GET, "/_nodes/{nodeId}/hot_threads") + new Route(GET, "/_nodes/{nodeId}/hot_threads"), + + Route.builder(GET, "/_cluster/nodes/hot_threads") + .deprecated(DEPRECATED_MESSAGE_CLUSTER_NODES_HOT_THREADS, RestApiVersion.V_7).build(), + Route.builder(GET, "/_cluster/nodes/{nodeId}/hot_threads") + .deprecated(DEPRECATED_MESSAGE_CLUSTER_NODES_NODEID_HOT_THREADS, RestApiVersion.V_7).build(), + Route.builder(GET, "/_cluster/nodes/hotthreads") + .deprecated(DEPRECATED_MESSAGE_CLUSTER_NODES_HOTTHREADS, RestApiVersion.V_7).build(), + Route.builder(GET, "/_cluster/nodes/{nodeId}/hotthreads") + .deprecated(DEPRECATED_MESSAGE_CLUSTER_NODES_NODEID_HOTTHREADS, RestApiVersion.V_7).build(), + Route.builder(GET, "/_nodes/hotthreads") + .deprecated(DEPRECATED_MESSAGE_NODES_HOTTHREADS, RestApiVersion.V_7).build(), + Route.builder(GET, "/_nodes/{nodeId}/hotthreads") + .deprecated(DEPRECATED_MESSAGE_NODES_NODEID_HOTTHREADS, RestApiVersion.V_7).build() ); } From 05e3d84a5f338d59a3e0ebf8cbf58508956f62f6 Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Wed, 26 May 2021 15:32:39 -0400 Subject: [PATCH 2/3] Add a simple yamlRestCompatTest test --- .../rest-api-spec/api/nodes.hotthreads.json | 102 ++++++++++++++++++ .../nodes.hotthreads/10_basic_compat.yml | 21 ++++ 2 files changed, 123 insertions(+) create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/api/nodes.hotthreads.json create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/nodes.hotthreads/10_basic_compat.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/api/nodes.hotthreads.json b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/api/nodes.hotthreads.json new file mode 100644 index 0000000000000..5e0ec6fb41447 --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/api/nodes.hotthreads.json @@ -0,0 +1,102 @@ +{ + "nodes.hotthreads":{ + "documentation":{ + "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-hot-threads.html", + "description":"Returns information about hot threads on each node in the cluster." + }, + "stability":"stable", + "visibility":"public", + "headers":{ + "accept": [ "text/plain"] + }, + "url":{ + "paths":[ + { + "path":"/_cluster/nodes/hotthreads", + "methods":[ + "GET" + ] + }, + { + "path":"/_cluster/nodes/hot_threads", + "methods":[ + "GET" + ] + }, + { + "path":"/_clusters/nodes/{node_id}/hotthreads", + "methods":[ + "GET" + ], + "parts":{ + "node_id":{ + "type":"list", + "description":"A comma-separated list of node IDs or names to limit the returned information; leave empty to get information from all nodes" + } + } + }, + { + "path":"/_clusters/nodes/{node_id}/hot_threads", + "methods":[ + "GET" + ], + "parts":{ + "node_id":{ + "type":"list", + "description":"A comma-separated list of node IDs or names to limit the returned information; leave empty to get information from all nodes" + } + } + }, + { + "path":"/_nodes/hotthreads", + "methods":[ + "GET" + ] + }, + { + "path":"/_nodes/{node_id}/hotthreads", + "methods":[ + "GET" + ], + "parts":{ + "node_id":{ + "type":"list", + "description":"A comma-separated list of node IDs or names to limit the returned information; leave empty to get information from all nodes" + } + } + } + ] + }, + "params":{ + "interval":{ + "type":"time", + "description":"The interval for the second sampling of threads" + }, + "snapshots":{ + "type":"number", + "description":"Number of samples of thread stacktrace (default: 10)" + }, + "threads":{ + "type":"number", + "description":"Specify the number of threads to provide information for (default: 3)" + }, + "ignore_idle_threads":{ + "type":"boolean", + "description":"Don't show threads that are in known-idle places, such as waiting on a socket select or pulling from an empty task queue (default: true)" + }, + "type":{ + "type":"enum", + "options":[ + "cpu", + "wait", + "block" + ], + "description":"The type to sample (default: cpu)" + }, + "timeout":{ + "type":"time", + "description":"Explicit operation timeout" + } + } + } +} diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/nodes.hotthreads/10_basic_compat.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/nodes.hotthreads/10_basic_compat.yml new file mode 100644 index 0000000000000..9d2273d6f7b7d --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/nodes.hotthreads/10_basic_compat.yml @@ -0,0 +1,21 @@ +--- +setup: + - skip: + version: "9.0.0 - " + reason: "compatible from 8.x to 7.x" + features: + - "headers" + - "warnings_regex" + +--- +"Get hot threads": + + - do: + headers: + Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" + Accept: "application/vnd.elasticsearch+json;compatible-with=7" + nodes.hotthreads: {} + warnings_regex: + - ".*hot_?threads.* is a deprecated endpoint.*" + - match: + $body: /:::/ From 2c01275eab41be78f45126a6b83536bd02e835f7 Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Tue, 8 Jun 2021 10:02:02 -0400 Subject: [PATCH 3/3] Drop the additional rest-api-spec here We can rely on the one from 7.x, which already includes the deprecated routes. But since it includes both the deprecated routes and the non-deprecated routes, we need to switch the warnings_regex to an allowed_warnings_regex. --- .../rest-api-spec/api/nodes.hotthreads.json | 102 ------------------ .../10_basic_compat.yml | 6 +- 2 files changed, 3 insertions(+), 105 deletions(-) delete mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/api/nodes.hotthreads.json rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/{nodes.hotthreads => nodes.hot_threads}/10_basic_compat.yml (81%) diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/api/nodes.hotthreads.json b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/api/nodes.hotthreads.json deleted file mode 100644 index 5e0ec6fb41447..0000000000000 --- a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/api/nodes.hotthreads.json +++ /dev/null @@ -1,102 +0,0 @@ -{ - "nodes.hotthreads":{ - "documentation":{ - "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-hot-threads.html", - "description":"Returns information about hot threads on each node in the cluster." - }, - "stability":"stable", - "visibility":"public", - "headers":{ - "accept": [ "text/plain"] - }, - "url":{ - "paths":[ - { - "path":"/_cluster/nodes/hotthreads", - "methods":[ - "GET" - ] - }, - { - "path":"/_cluster/nodes/hot_threads", - "methods":[ - "GET" - ] - }, - { - "path":"/_clusters/nodes/{node_id}/hotthreads", - "methods":[ - "GET" - ], - "parts":{ - "node_id":{ - "type":"list", - "description":"A comma-separated list of node IDs or names to limit the returned information; leave empty to get information from all nodes" - } - } - }, - { - "path":"/_clusters/nodes/{node_id}/hot_threads", - "methods":[ - "GET" - ], - "parts":{ - "node_id":{ - "type":"list", - "description":"A comma-separated list of node IDs or names to limit the returned information; leave empty to get information from all nodes" - } - } - }, - { - "path":"/_nodes/hotthreads", - "methods":[ - "GET" - ] - }, - { - "path":"/_nodes/{node_id}/hotthreads", - "methods":[ - "GET" - ], - "parts":{ - "node_id":{ - "type":"list", - "description":"A comma-separated list of node IDs or names to limit the returned information; leave empty to get information from all nodes" - } - } - } - ] - }, - "params":{ - "interval":{ - "type":"time", - "description":"The interval for the second sampling of threads" - }, - "snapshots":{ - "type":"number", - "description":"Number of samples of thread stacktrace (default: 10)" - }, - "threads":{ - "type":"number", - "description":"Specify the number of threads to provide information for (default: 3)" - }, - "ignore_idle_threads":{ - "type":"boolean", - "description":"Don't show threads that are in known-idle places, such as waiting on a socket select or pulling from an empty task queue (default: true)" - }, - "type":{ - "type":"enum", - "options":[ - "cpu", - "wait", - "block" - ], - "description":"The type to sample (default: cpu)" - }, - "timeout":{ - "type":"time", - "description":"Explicit operation timeout" - } - } - } -} diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/nodes.hotthreads/10_basic_compat.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/nodes.hot_threads/10_basic_compat.yml similarity index 81% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/nodes.hotthreads/10_basic_compat.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/nodes.hot_threads/10_basic_compat.yml index 9d2273d6f7b7d..a78130342519b 100644 --- a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/nodes.hotthreads/10_basic_compat.yml +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/nodes.hot_threads/10_basic_compat.yml @@ -5,7 +5,7 @@ setup: reason: "compatible from 8.x to 7.x" features: - "headers" - - "warnings_regex" + - "allowed_warnings_regex" --- "Get hot threads": @@ -14,8 +14,8 @@ setup: headers: Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" Accept: "application/vnd.elasticsearch+json;compatible-with=7" - nodes.hotthreads: {} - warnings_regex: + nodes.hot_threads: {} + allowed_warnings_regex: - ".*hot_?threads.* is a deprecated endpoint.*" - match: $body: /:::/