Skip to content

[7.x] Add other time accounting in HotThreads(#79392) #79507

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

Merged
merged 4 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.elasticsearch.action.admin.cluster.node.hotthreads;

import org.elasticsearch.Version;
import org.elasticsearch.action.support.nodes.BaseNodesRequest;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.io.stream.StreamInput;
Expand All @@ -22,6 +23,7 @@ public class NodesHotThreadsRequest extends BaseNodesRequest<NodesHotThreadsRequ

int threads = 3;
HotThreads.ReportType type = HotThreads.ReportType.CPU;
HotThreads.SortOrder sortOrder = HotThreads.SortOrder.TOTAL;
TimeValue interval = new TimeValue(500, TimeUnit.MILLISECONDS);
int snapshots = 10;
boolean ignoreIdleThreads = true;
Expand All @@ -34,6 +36,9 @@ public NodesHotThreadsRequest(StreamInput in) throws IOException {
type = HotThreads.ReportType.of(in.readString());
interval = in.readTimeValue();
snapshots = in.readInt();
if (in.getVersion().onOrAfter(Version.V_7_16_0)) {
sortOrder = HotThreads.SortOrder.of(in.readString());
}
}

/**
Expand Down Expand Up @@ -78,6 +83,15 @@ public HotThreads.ReportType type() {
return this.type;
}

public NodesHotThreadsRequest sortOrder(HotThreads.SortOrder sortOrder) {
this.sortOrder = sortOrder;
return this;
}

public HotThreads.SortOrder sortOrder() {
return this.sortOrder;
}

public NodesHotThreadsRequest interval(TimeValue interval) {
this.interval = interval;
return this;
Expand All @@ -104,5 +118,8 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(type.getTypeValue());
out.writeTimeValue(interval);
out.writeInt(snapshots);
if (out.getVersion().onOrAfter(Version.V_7_16_0)) {
out.writeString(sortOrder.getOrderValue());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public NodesHotThreadsRequestBuilder setType(HotThreads.ReportType type) {
return this;
}

public NodesHotThreadsRequestBuilder setSortOrder(HotThreads.SortOrder sortOrder) {
request.sortOrder(sortOrder);
return this;
}

public NodesHotThreadsRequestBuilder setInterval(TimeValue interval) {
request.interval(interval);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected NodeHotThreads nodeOperation(NodeRequest request) {
HotThreads hotThreads = new HotThreads()
.busiestThreads(request.request.threads)
.type(request.request.type)
.sortOrder(request.request.sortOrder)
.interval(request.request.interval)
.threadElementsSnapshotCount(request.request.snapshots)
.ignoreIdleThreads(request.request.ignoreIdleThreads);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.elasticsearch.core.internal.io.IOUtils;
import org.elasticsearch.env.Environment;
import org.elasticsearch.jdk.JarHell;
import org.elasticsearch.monitor.jvm.HotThreads;
import org.elasticsearch.jdk.JavaVersion;
import org.elasticsearch.monitor.jvm.JvmInfo;
import org.elasticsearch.monitor.os.OsProbe;
Expand Down Expand Up @@ -156,6 +157,7 @@ static void initializeProbes() {
ProcessProbe.getInstance();
OsProbe.getInstance();
JvmInfo.jvmInfo();
HotThreads.initializeRuntimeMonitoring();
}

private void setup(boolean addShutdownHook, Environment environment) throws BootstrapException {
Expand Down
290 changes: 202 additions & 88 deletions server/src/main/java/org/elasticsearch/monitor/jvm/HotThreads.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId"));
NodesHotThreadsRequest nodesHotThreadsRequest = new NodesHotThreadsRequest(nodesIds);
nodesHotThreadsRequest.threads(request.paramAsInt("threads", nodesHotThreadsRequest.threads()));
nodesHotThreadsRequest.ignoreIdleThreads(request.paramAsBoolean("ignore_idle_threads", nodesHotThreadsRequest.ignoreIdleThreads()));
nodesHotThreadsRequest.ignoreIdleThreads(
request.paramAsBoolean("ignore_idle_threads", nodesHotThreadsRequest.ignoreIdleThreads()));
nodesHotThreadsRequest.type(HotThreads.ReportType.of(request.param("type", nodesHotThreadsRequest.type().getTypeValue())));
nodesHotThreadsRequest.interval(TimeValue.parseTimeValue(request.param("interval"), nodesHotThreadsRequest.interval(), "interval"));
nodesHotThreadsRequest.sortOrder(
HotThreads.SortOrder.of(request.param("sort", nodesHotThreadsRequest.sortOrder().getOrderValue())));
nodesHotThreadsRequest.interval(
TimeValue.parseTimeValue(request.param("interval"), nodesHotThreadsRequest.interval(), "interval"));
nodesHotThreadsRequest.snapshots(request.paramAsInt("snapshots", nodesHotThreadsRequest.snapshots()));
nodesHotThreadsRequest.timeout(request.param("timeout"));
return channel -> client.admin().cluster().nodesHotThreads(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ grant codeBase "${codebase.elasticsearch}" {
permission java.lang.RuntimePermission "setContextClassLoader";
// needed for SPI class loading
permission java.lang.RuntimePermission "accessDeclaredMembers";
// needed by HotThreads to enable wait/block time accounting on demand
permission java.lang.management.ManagementPermission "control";
};

//// Very special jar permissions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testBWCSerialization() throws IOException {
out.setVersion(previous);
request.writeTo(out);
try (StreamInput in = out.bytes().streamInput()) {
in.setVersion(latest);
in.setVersion(previous);
NodesHotThreadsRequest deserialized = new NodesHotThreadsRequest(in);
assertEquals(request.threads(), deserialized.threads());
assertEquals(request.ignoreIdleThreads(), deserialized.ignoreIdleThreads());
Expand Down
Loading