Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resurrect hot_threads routes #73855

Merged
merged 6 commits into from
Jun 8, 2021
Merged

Conversation

joegallo
Copy link
Contributor

@joegallo joegallo commented Jun 7, 2021

Related to #51816 / #68905. Also related to #52640 / #55109.

Adds back the various removed hot_threads routes when using rest compatibility for a request.

warnings_regex:
- ".*hot_?threads.* is a deprecated endpoint.*"
- match:
$body: /:::/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This match is not my most favorite code ever. I wanted to verify that the response actually resembles a hot_threads response, but the regex match has to be on the first line and there's not all that much for us to match on there:

::: {runTask-0}{rNO3-C-BStGLmQ_xUdIecA}{PiMCJKfOSnuRkp0Uk1E7ig}{127.0.0.1}{127.0.0.1:9300}{cdfhilmrstw}{ml.machine_memory=68719476736, xpack.installed=true, testattr=test, ml.max_open_jobs=512, ml.max_jvm_size=536870912}
   Hot threads at 2021-06-07T15:44:46.079Z, interval=500ms, busiestThreads=3, ignoreIdleThreads=true:

Copy link
Contributor Author

@joegallo joegallo Jun 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, there is a ::: so I'm matching on that. A reasonable alternative would be to cut the match entirely and just run with "any non-error response is good enough".

@joegallo
Copy link
Contributor Author

joegallo commented Jun 7, 2021

One point of discussion:

joegallo@galactic:~/Code/elastic/elasticsearch $ curl -s -XGET 'http://localhost:9200/_cluster/nodes/hot_threads'
{"error":"no handler found for uri [/_cluster/nodes/hot_threads] and method [GET]"}%
joegallo@galactic:~/Code/elastic/elasticsearch $ curl -s -XGET -H'accept:application/json;compatible-with=7' 'http://localhost:9200/_cluster/nodes/hot_threads'
::: {runTask-0}{rNO3-C-BStGLmQ_xUdIecA}{PiMCJKfOSnuRkp0Uk1E7ig}{127.0.0.1}{127.0.0.1:9300}{cdfhilmrstw}{ml.machine_memory=68719476736, xpack.installed=true, testattr=test, ml.max_open_jobs=512, ml.max_jvm_size=536870912}
   Hot threads at 2021-06-07T15:44:46.079Z, interval=500ms, busiestThreads=3, ignoreIdleThreads=true:

joegallo@galactic:~/Code/elastic/elasticsearch $ curl -s -XGET -H'accept:text/plain;compatible-with=7' 'http://localhost:9200/_cluster/nodes/hot_threads'
::: {runTask-0}{rNO3-C-BStGLmQ_xUdIecA}{PiMCJKfOSnuRkp0Uk1E7ig}{127.0.0.1}{127.0.0.1:9300}{cdfhilmrstw}{ml.machine_memory=68719476736, xpack.installed=true, testattr=test, ml.max_open_jobs=512, ml.max_jvm_size=536870912}
   Hot threads at 2021-06-07T15:47:12.956Z, interval=500ms, busiestThreads=3, ignoreIdleThreads=true:

Given that the response is not JSON -- should application/json work here? Is text/plain intended to be supported in this way? I'm not 100% sure I'm holding it right.

@DaveCTurner
Copy link
Contributor

It's legitimate, although surprising, according to RFC7231 section 5.3.2:

                                            If the header field is
   present in a request and none of the available representations for
   the response have a media type that is listed as acceptable, the
   origin server can either honor the header field by sending a 406 (Not
   Acceptable) response or disregard the header field by treating the
   response as if it is not subject to content negotiation.

"url":{
"paths":[
{
"path":"/_cluster/nodes/hotthreads",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it more correct to re-introduce this path (and the like) as deprecated in the spec for 7.x and add the allowed warning (for any tests that call this API) ?

This would allow you to avoid introducing the spec only for compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea! Just to make sure I'm following -- that'd be a PR pointed at 7.x (no version that hits master) that adds these as deprecated endpoints to the rest-api-spec, and then in this PR we wouldn't need a new test or any specs, because this would all execute automatically by way of the yamlRestCompatTest tests.

Is there any downside to adding these as deprecated in 7.x? I'm thinking, for example, that perhaps the autogenerated client code might actually start using them (if so, that'd be strictly worse, and we probably wouldn't want to go this way).

@pgomulka what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like that idea too!
if a test client will use it, maybe we can ignore the warning in 7.x for this? Like we do for types removal in 7.x

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that'd be a PR pointed at 7.x (no version that hits master) that adds these as deprecated endpoints to the rest-api-spec,

yes, that is what i meant. I think it works well in this case (and any other one off cases) since it probably should have been that way from the start and should have minimal pollution in 7.x.

However, I don't think this should be a rule of thumb for all missing paths. For example, for the _xpack/ prefix i can see the argument for not polluting 7.x since there are so many, somewhat inconsistent (depending on when it was added), and has a lot of associated tests that would need to allow warnings.

@sethmlarson sethmlarson added the Team:Clients Meta label for clients team label Jun 7, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/clients-team (Team:Clients)

@swallez
Copy link
Member

swallez commented Jun 7, 2021

After a discussion with @joegallo about route deprecations and how clients handle them: a client selects the route that matches the parameters specified by the application (e.g. non null in Java). What I'm not sure about is what happens when there are two matching routes. We have to make sure deprecated routes have lower priority in the selection algorithm and that we don't just choose the first matching route. I'll bring this as a discussion/verification topic to the clients team.

Copy link
Contributor

@pgomulka pgomulka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


import static org.elasticsearch.rest.RestRequest.Method.GET;

public class RestNodesHotThreadsAction extends BaseRestHandler {

private static final String formatDeprecatedMessageWithoutNodeID = "[%s] is a deprecated endpoint. " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a thought. we could just use one message for all. We have a used endpoint as a key, API_GET_/_nodes/{nodeid}/hot_threads
not as readable as here, but might save some effort
but it looks good now too!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I basically did a revert + edit of the commit that removed the apis, so it was cheap to do it as is (and keeps the code mostly in line with the way it is on 7.x).

"url":{
"paths":[
{
"path":"/_cluster/nodes/hotthreads",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like that idea too!
if a test client will use it, maybe we can ignore the warning in 7.x for this? Like we do for types removal in 7.x

@pgomulka
Copy link
Contributor

pgomulka commented Jun 8, 2021

re text/plain;compatible-with=7 this possibly works by mistake at the moment and is a flavour of this #72969

joegallo added 2 commits June 8, 2021 10:02
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.
@joegallo
Copy link
Contributor Author

joegallo commented Jun 8, 2021

joegallo@galactic:~/Code/elastic/elasticsearch-7.x $ cat rest-api-spec/src/main/resources/rest-api-spec/api/nodes.hot_threads.json | grep -E 'path|deprecated'
      "paths":[
          "path":"/_nodes/hot_threads",
          "path":"/_nodes/{node_id}/hot_threads",
          "path":"/_cluster/nodes/hotthreads",
          "deprecated":{
          "path":"/_cluster/nodes/{node_id}/hotthreads",
          "deprecated":{
          "path":"/_nodes/hotthreads",
          "deprecated":{
          "path":"/_nodes/{node_id}/hotthreads",
          "deprecated":{
          "path":"/_cluster/nodes/hot_threads",
          "deprecated":{
          "path":"/_cluster/nodes/{node_id}/hot_threads",
          "deprecated":{

Some enterprising developer liked this conversation so much they went back in time and made 7.x already have those routes in there as deprecated. So I've dropped my copy from this PR and switched the warnings_regex to an allowed_warnings_regex (sometimes the test will hit the non-deprecated APIs, so we can't rely on the warning appearing).

@joegallo joegallo requested a review from jakelandis June 8, 2021 14:27
Copy link
Contributor

@jakelandis jakelandis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@joegallo joegallo merged commit 4bb1f28 into elastic:master Jun 8, 2021
@joegallo joegallo deleted the resurrect-hotthreads branch June 8, 2021 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants