Skip to content

Commit

Permalink
Reduce BWC version for HotThreads.sort (#79583)
Browse files Browse the repository at this point in the history
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 <nhat.nguyen@elastic.co>
  • Loading branch information
grcevski and dnhatn authored Oct 25, 2021
1 parent 2b5f6ce commit 3f0ea76
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.backwards;

import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.test.rest.ESRestTestCase;

import static org.hamcrest.Matchers.equalTo;

public class HotThreadsIT extends ESRestTestCase {

public void testHotThreads() throws Exception {
final IndexingIT.Nodes nodes = IndexingIT.buildNodeAndVersions(client());
assumeFalse("no new node found", nodes.getNewNodes().isEmpty());
assumeFalse("no bwc node found", nodes.getBWCNodes().isEmpty());
assumeTrue("new nodes are higher version than BWC nodes",
nodes.getNewNodes().get(0).getVersion().compareTo(nodes.getBWCNodes().get(0).getVersion()) > 0);
final Request request = new Request("GET", "/_nodes/hot_threads");
final Response response = client().performRequest(request);
final String responseString = EntityUtils.toString(response.getEntity());
final String[] nodeResponses = responseString.split("::: ");
int respondedNodes = 0;
for (String nodeResponse : nodeResponses) {
final String[] lines = nodeResponse.split("\n");
final String nodeId = lines[0].trim();
if (nodeId.isEmpty() == false) {
respondedNodes++;
}
}
assertThat(respondedNodes, equalTo(nodes.getNewNodes().size() + nodes.getBWCNodes().size()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,19 @@
"options":[
"cpu",
"wait",
"block"
"block",
"mem"
],
"description":"The type to sample (default: cpu)"
},
"sort":{
"type":"enum",
"options":[
"cpu",
"total"
],
"description":"The sort order for 'cpu' type (default: total)"
},
"timeout":{
"type":"time",
"description":"Explicit operation timeout"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
"Nodes hot threads - CPU":
- do:
nodes.hot_threads:
type: "cpu"
- match:
$body: |
/Hot\ threads\ at/
---
"Nodes hot threads - CPU sort":
- do:
nodes.hot_threads:
type: "cpu"
sort: "cpu"
- match:
$body: |
/Hot\ threads\ at/
---
"Nodes hot threads - WAIT":
- do:
nodes.hot_threads:
type: "wait"
- match:
$body: |
/Hot\ threads\ at/
---
"Nodes hot threads - BLOCK":
- do:
nodes.hot_threads:
type: "block"
- match:
$body: |
/Hot\ threads\ at/
---
"Nodes hot threads - MEM":
- do:
nodes.hot_threads:
type: "mem"
- match:
$body: |
/Hot\ threads\ at/
---
"Nodes hot threads - BAD":
- do:
catch: bad_request
nodes.hot_threads:
type: "gpu"
- match: { status: 400 }
- match: { error.type: illegal_argument_exception }
- match: { error.reason: "type not supported [gpu]" }

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public NodesHotThreadsRequest(StreamInput in) throws IOException {
type = HotThreads.ReportType.of(in.readString());
interval = in.readTimeValue();
snapshots = in.readInt();
if (in.getVersion().onOrAfter(Version.V_8_0_0)) {
if (in.getVersion().onOrAfter(Version.V_7_16_0)) {
sortOrder = HotThreads.SortOrder.of(in.readString());
}
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(type.getTypeValue());
out.writeTimeValue(interval);
out.writeInt(snapshots);
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
if (out.getVersion().onOrAfter(Version.V_7_16_0)) {
out.writeString(sortOrder.getOrderValue());
}
}
Expand Down

0 comments on commit 3f0ea76

Please sign in to comment.