Skip to content

Commit 2fd13df

Browse files
committed
Draft of including thread names
1 parent 74d78bb commit 2fd13df

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ static TransportVersion def(int id) {
211211
public static final TransportVersion MULTI_PROJECT = def(9_018_0_00);
212212
public static final TransportVersion STORED_SCRIPT_CONTENT_LENGTH = def(9_019_0_00);
213213
public static final TransportVersion JINA_AI_EMBEDDING_TYPE_SUPPORT_ADDED = def(9_020_0_00);
214+
public static final TransportVersion ESQL_THREAD_NAME_IN_DRIVER_PROFILE = def(9_021_0_00);
214215

215216
/*
216217
* STOP! READ THIS FIRST! No, really,

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/DriverSleeps.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,28 @@
3131
public record DriverSleeps(Map<String, Long> counts, List<Sleep> first, List<Sleep> last) implements Writeable, ToXContentObject {
3232
/**
3333
* A record of a time the driver slept.
34-
* @param reason The reason the driver slept
35-
* @param sleep Millis since epoch when the driver slept
36-
* @param wake Millis since epoch when the driver woke, or 0 if it is currently sleeping
34+
*
35+
* @param reason The reason the driver slept
36+
* @param threadName
37+
* @param sleep Millis since epoch when the driver slept
38+
* @param wake Millis since epoch when the driver woke, or 0 if it is currently sleeping
3739
*/
38-
public record Sleep(String reason, long sleep, long wake) implements Writeable, ToXContentObject {
40+
public record Sleep(String reason, String threadName, long sleep, long wake) implements Writeable, ToXContentObject {
3941
Sleep(StreamInput in) throws IOException {
40-
this(in.readString(), in.readLong(), in.readLong());
42+
this(
43+
in.readString(),
44+
in.getTransportVersion().onOrAfter(TransportVersions.ESQL_THREAD_NAME_IN_DRIVER_PROFILE) ? in.readString() : "",
45+
in.readLong(),
46+
in.readLong()
47+
);
4148
}
4249

4350
@Override
4451
public void writeTo(StreamOutput out) throws IOException {
4552
out.writeString(reason);
53+
if (out.getTransportVersion().onOrAfter(TransportVersions.ESQL_THREAD_NAME_IN_DRIVER_PROFILE)) {
54+
out.writeString(threadName);
55+
}
4656
out.writeLong(sleep);
4757
out.writeLong(wake);
4858
}
@@ -51,7 +61,7 @@ Sleep wake(long now) {
5161
if (isStillSleeping() == false) {
5262
throw new IllegalStateException("Already awake.");
5363
}
54-
return new Sleep(reason, sleep, now);
64+
return new Sleep(reason, Thread.currentThread().getName(), sleep, now);
5565
}
5666

5767
public boolean isStillSleeping() {
@@ -62,6 +72,7 @@ public boolean isStillSleeping() {
6272
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
6373
builder.startObject();
6474
builder.field("reason", reason);
75+
builder.field("thread_name", threadName);
6576
builder.timestampFieldsFromUnixEpochMillis("sleep_millis", "sleep", sleep);
6677
if (wake > 0) {
6778
builder.timestampFieldsFromUnixEpochMillis("wake_millis", "wake", wake);
@@ -138,7 +149,7 @@ public DriverSleeps wake(long now) {
138149
private List<Sleep> append(List<Sleep> old, String reason, long now) {
139150
List<Sleep> sleeps = new ArrayList<>(old.size() + 1);
140151
sleeps.addAll(old);
141-
sleeps.add(new Sleep(reason, now, 0));
152+
sleeps.add(new Sleep(reason, Thread.currentThread().getName(), now, 0));
142153
return Collections.unmodifiableList(sleeps);
143154
}
144155

@@ -147,7 +158,7 @@ private List<Sleep> rollOnto(List<Sleep> old, String reason, long now) {
147158
for (int i = 1; i < old.size(); i++) {
148159
sleeps.add(old.get(i));
149160
}
150-
sleeps.add(new Sleep(reason, now, 0));
161+
sleeps.add(new Sleep(reason, Thread.currentThread().getName(), now, 0));
151162
return Collections.unmodifiableList(sleeps);
152163
}
153164

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/DriverProfileTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public void testToXContent() {
4141
),
4242
new DriverSleeps(
4343
Map.of("driver time", 1L),
44-
List.of(new DriverSleeps.Sleep("driver time", 1, 1)),
45-
List.of(new DriverSleeps.Sleep("driver time", 1, 1))
44+
List.of(new DriverSleeps.Sleep("driver time", "", 1, 1)),
45+
List.of(new DriverSleeps.Sleep("driver time", "", 1, 1))
4646
)
4747
);
4848
assertThat(Strings.toString(status, true, true), equalTo("""

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/DriverSleepsTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ public void testTracking() throws IOException {
149149
expectedCounts.compute(reason, (k, v) -> v == null ? 1 : v + 1);
150150

151151
sleeps = sleeps.sleep(reason, now);
152-
expectedFirst.add(new DriverSleeps.Sleep(reason, now, 0));
152+
expectedFirst.add(new DriverSleeps.Sleep(reason, "", now, 0));
153153
assertThat(sleeps, equalTo(new DriverSleeps(expectedCounts, expectedFirst, expectedFirst)));
154154
assertXContent(sleeps, expectedCounts, expectedFirst, expectedFirst);
155155

156156
now++;
157157
sleeps = sleeps.wake(now);
158-
expectedFirst.set(expectedFirst.size() - 1, new DriverSleeps.Sleep(reason, now - 1, now));
158+
expectedFirst.set(expectedFirst.size() - 1, new DriverSleeps.Sleep(reason, "", now - 1, now));
159159
assertThat(sleeps, equalTo(new DriverSleeps(expectedCounts, expectedFirst, expectedFirst)));
160160
assertXContent(sleeps, expectedCounts, expectedFirst, expectedFirst);
161161
}
@@ -172,13 +172,13 @@ public void testTracking() throws IOException {
172172

173173
sleeps = sleeps.sleep(reason, now);
174174
expectedLast.remove(0);
175-
expectedLast.add(new DriverSleeps.Sleep(reason, now, 0));
175+
expectedLast.add(new DriverSleeps.Sleep(reason, "", now, 0));
176176
assertThat(sleeps, equalTo(new DriverSleeps(expectedCounts, expectedFirst, expectedLast)));
177177
assertXContent(sleeps, expectedCounts, expectedFirst, expectedLast);
178178

179179
now++;
180180
sleeps = sleeps.wake(now);
181-
expectedLast.set(expectedLast.size() - 1, new DriverSleeps.Sleep(reason, now - 1, now));
181+
expectedLast.set(expectedLast.size() - 1, new DriverSleeps.Sleep(reason, "", now - 1, now));
182182
assertThat(sleeps, equalTo(new DriverSleeps(expectedCounts, expectedFirst, expectedLast)));
183183
assertXContent(sleeps, expectedCounts, expectedFirst, expectedLast);
184184
}

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/DriverStatusTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public void testToXContent() {
4545
List.of(new OperatorStatus("ExchangeSink", ExchangeSinkOperatorStatusTests.simple())),
4646
new DriverSleeps(
4747
Map.of("driver time", 1L),
48-
List.of(new DriverSleeps.Sleep("driver time", 1, 1)),
49-
List.of(new DriverSleeps.Sleep("driver time", 1, 1))
48+
List.of(new DriverSleeps.Sleep("driver time", "", 1, 1)),
49+
List.of(new DriverSleeps.Sleep("driver time", "", 1, 1))
5050
)
5151
);
5252
assertThat(Strings.toString(status, true, true), equalTo("""

0 commit comments

Comments
 (0)