Skip to content

Commit

Permalink
Add assertions to aid troubleshooting Hot Threads test failures (elas…
Browse files Browse the repository at this point in the history
…tic#72837)

Sometimes generating hot threads will fail due to attempting to create a
TimeValue with a negative duration. This commit adds asserts at the time
we get the duration that will be used to create the TimeValue to aid the
debugging process.
  • Loading branch information
gwbrown authored May 11, 2021
1 parent 4cf5ffd commit c28beb8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions server/src/main/java/org/elasticsearch/monitor/jvm/HotThreads.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,20 @@ private String innerDetect() throws Exception {
// skip that for now
final ToLongFunction<MyThreadInfo> getter;
if ("cpu".equals(type)) {
getter = o -> o.cpuTime;
getter = o -> {
assert o.cpuTime >= -1 : "cpu time should not be negative, but was " + o.cpuTime + ", thread info: " + o.info;
return o.cpuTime;
};
} else if ("wait".equals(type)) {
getter = o -> o.waitedTime;
getter = o -> {
assert o.waitedTime >= -1 : "waited time should not be negative, but was " + o.waitedTime + ", thread info: " + o.info;
return o.waitedTime;
};
} else if ("block".equals(type)) {
getter = o -> o.blockedTime;
getter = o -> {
assert o.blockedTime >= -1 : "blocked time should not be negative, but was " + o.blockedTime + ", thread info: " + o.info;
return o.blockedTime;
};
} else {
throw new IllegalArgumentException("expected thread type to be either 'cpu', 'wait', or 'block', but was " + type);
}
Expand Down

0 comments on commit c28beb8

Please sign in to comment.