Skip to content

Commit 3f0ea76

Browse files
grcevskidnhatn
andauthored
Reduce BWC version for HotThreads.sort (#79583)
The sort by change has been merged in 7.x now and therefore we should make 8.0 use the same BWC version. Relates to #79392 and #79507 Co-authored-by: Nhat Nguyen <[email protected]>
1 parent 2b5f6ce commit 3f0ea76

File tree

4 files changed

+103
-3
lines changed

4 files changed

+103
-3
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.backwards;
10+
11+
import org.apache.http.util.EntityUtils;
12+
import org.elasticsearch.client.Request;
13+
import org.elasticsearch.client.Response;
14+
import org.elasticsearch.test.rest.ESRestTestCase;
15+
16+
import static org.hamcrest.Matchers.equalTo;
17+
18+
public class HotThreadsIT extends ESRestTestCase {
19+
20+
public void testHotThreads() throws Exception {
21+
final IndexingIT.Nodes nodes = IndexingIT.buildNodeAndVersions(client());
22+
assumeFalse("no new node found", nodes.getNewNodes().isEmpty());
23+
assumeFalse("no bwc node found", nodes.getBWCNodes().isEmpty());
24+
assumeTrue("new nodes are higher version than BWC nodes",
25+
nodes.getNewNodes().get(0).getVersion().compareTo(nodes.getBWCNodes().get(0).getVersion()) > 0);
26+
final Request request = new Request("GET", "/_nodes/hot_threads");
27+
final Response response = client().performRequest(request);
28+
final String responseString = EntityUtils.toString(response.getEntity());
29+
final String[] nodeResponses = responseString.split("::: ");
30+
int respondedNodes = 0;
31+
for (String nodeResponse : nodeResponses) {
32+
final String[] lines = nodeResponse.split("\n");
33+
final String nodeId = lines[0].trim();
34+
if (nodeId.isEmpty() == false) {
35+
respondedNodes++;
36+
}
37+
}
38+
assertThat(respondedNodes, equalTo(nodes.getNewNodes().size() + nodes.getBWCNodes().size()));
39+
}
40+
}

rest-api-spec/src/main/resources/rest-api-spec/api/nodes.hot_threads.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,19 @@
5353
"options":[
5454
"cpu",
5555
"wait",
56-
"block"
56+
"block",
57+
"mem"
5758
],
5859
"description":"The type to sample (default: cpu)"
5960
},
61+
"sort":{
62+
"type":"enum",
63+
"options":[
64+
"cpu",
65+
"total"
66+
],
67+
"description":"The sort order for 'cpu' type (default: total)"
68+
},
6069
"timeout":{
6170
"type":"time",
6271
"description":"Explicit operation timeout"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
"Nodes hot threads - CPU":
3+
- do:
4+
nodes.hot_threads:
5+
type: "cpu"
6+
- match:
7+
$body: |
8+
/Hot\ threads\ at/
9+
---
10+
"Nodes hot threads - CPU sort":
11+
- do:
12+
nodes.hot_threads:
13+
type: "cpu"
14+
sort: "cpu"
15+
- match:
16+
$body: |
17+
/Hot\ threads\ at/
18+
---
19+
"Nodes hot threads - WAIT":
20+
- do:
21+
nodes.hot_threads:
22+
type: "wait"
23+
- match:
24+
$body: |
25+
/Hot\ threads\ at/
26+
---
27+
"Nodes hot threads - BLOCK":
28+
- do:
29+
nodes.hot_threads:
30+
type: "block"
31+
- match:
32+
$body: |
33+
/Hot\ threads\ at/
34+
---
35+
"Nodes hot threads - MEM":
36+
- do:
37+
nodes.hot_threads:
38+
type: "mem"
39+
- match:
40+
$body: |
41+
/Hot\ threads\ at/
42+
---
43+
"Nodes hot threads - BAD":
44+
- do:
45+
catch: bad_request
46+
nodes.hot_threads:
47+
type: "gpu"
48+
- match: { status: 400 }
49+
- match: { error.type: illegal_argument_exception }
50+
- match: { error.reason: "type not supported [gpu]" }
51+

server/src/main/java/org/elasticsearch/action/admin/cluster/node/hotthreads/NodesHotThreadsRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public NodesHotThreadsRequest(StreamInput in) throws IOException {
3636
type = HotThreads.ReportType.of(in.readString());
3737
interval = in.readTimeValue();
3838
snapshots = in.readInt();
39-
if (in.getVersion().onOrAfter(Version.V_8_0_0)) {
39+
if (in.getVersion().onOrAfter(Version.V_7_16_0)) {
4040
sortOrder = HotThreads.SortOrder.of(in.readString());
4141
}
4242
}
@@ -118,7 +118,7 @@ public void writeTo(StreamOutput out) throws IOException {
118118
out.writeString(type.getTypeValue());
119119
out.writeTimeValue(interval);
120120
out.writeInt(snapshots);
121-
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
121+
if (out.getVersion().onOrAfter(Version.V_7_16_0)) {
122122
out.writeString(sortOrder.getOrderValue());
123123
}
124124
}

0 commit comments

Comments
 (0)