Skip to content

Commit f9b198d

Browse files
committed
refactor: remove the cache entirely, and inline the plumbing built for it
See: [#14047](#14047)
1 parent b762c33 commit f9b198d

File tree

6 files changed

+54
-181
lines changed

6 files changed

+54
-181
lines changed

instrumentation/runtime-telemetry/runtime-telemetry-java17/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/java17/internal/AbstractThreadDispatchingHandler.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

instrumentation/runtime-telemetry/runtime-telemetry-java17/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/java17/internal/cpu/LongLockHandler.java

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,38 @@
99
import io.opentelemetry.api.metrics.DoubleHistogram;
1010
import io.opentelemetry.api.metrics.Meter;
1111
import io.opentelemetry.instrumentation.runtimemetrics.java17.JfrFeature;
12-
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.AbstractThreadDispatchingHandler;
1312
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.Constants;
1413
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.DurationUtil;
14+
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.RecordedEventHandler;
1515
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.ThreadGrouper;
1616
import java.time.Duration;
1717
import java.util.Optional;
18-
import java.util.function.Consumer;
1918
import jdk.jfr.consumer.RecordedEvent;
2019

2120
/**
2221
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
2322
* any time.
2423
*/
25-
public final class LongLockHandler extends AbstractThreadDispatchingHandler {
24+
public final class LongLockHandler implements RecordedEventHandler {
2625
private static final String METRIC_NAME = "jvm.cpu.longlock";
2726
private static final String METRIC_DESCRIPTION = "Long lock times";
2827
private static final String EVENT_NAME = "jdk.JavaMonitorWait";
2928

29+
private static final String EVENT_THREAD = "eventThread";
30+
3031
private final DoubleHistogram histogram;
32+
private final Attributes attributes;
3133

3234
public LongLockHandler(Meter meter, ThreadGrouper grouper) {
33-
super(grouper);
35+
super();
3436
histogram =
3537
meter
3638
.histogramBuilder(METRIC_NAME)
3739
.setDescription(METRIC_DESCRIPTION)
3840
.setUnit(Constants.SECONDS)
3941
.build();
42+
43+
attributes = Attributes.empty();
4044
}
4145

4246
@Override
@@ -50,34 +54,17 @@ public JfrFeature getFeature() {
5054
}
5155

5256
@Override
53-
public Consumer<RecordedEvent> createPerThreadSummarizer(String threadName) {
54-
return new PerThreadLongLockHandler(histogram);
57+
public void accept(RecordedEvent recordedEvent) {
58+
if (recordedEvent.hasField(EVENT_THREAD)) {
59+
histogram.record(DurationUtil.toSeconds(recordedEvent.getDuration()), attributes);
60+
}
61+
// What about the class name in MONITOR_CLASS ?
62+
// We can get a stack trace from the thread on the event
63+
// var eventThread = recordedEvent.getThread(EVENT_THREAD);
5564
}
5665

5766
@Override
5867
public Optional<Duration> getThreshold() {
5968
return Optional.empty();
6069
}
61-
62-
private static class PerThreadLongLockHandler implements Consumer<RecordedEvent> {
63-
private static final String EVENT_THREAD = "eventThread";
64-
65-
private final DoubleHistogram histogram;
66-
private final Attributes attributes;
67-
68-
public PerThreadLongLockHandler(DoubleHistogram histogram) {
69-
this.histogram = histogram;
70-
this.attributes = Attributes.empty();
71-
}
72-
73-
@Override
74-
public void accept(RecordedEvent recordedEvent) {
75-
if (recordedEvent.hasField(EVENT_THREAD)) {
76-
histogram.record(DurationUtil.toSeconds(recordedEvent.getDuration()), attributes);
77-
}
78-
// What about the class name in MONITOR_CLASS ?
79-
// We can get a stack trace from the thread on the event
80-
// var eventThread = recordedEvent.getThread(EVENT_THREAD);
81-
}
82-
}
8370
}

instrumentation/runtime-telemetry/runtime-telemetry-java17/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/java17/internal/memory/ObjectAllocationInNewTlabHandler.java

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
import io.opentelemetry.api.metrics.LongHistogram;
1010
import io.opentelemetry.api.metrics.Meter;
1111
import io.opentelemetry.instrumentation.runtimemetrics.java17.JfrFeature;
12-
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.AbstractThreadDispatchingHandler;
1312
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.Constants;
13+
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.RecordedEventHandler;
1414
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.ThreadGrouper;
15-
import java.util.function.Consumer;
1615
import jdk.jfr.consumer.RecordedEvent;
1716

1817
/**
@@ -22,20 +21,23 @@
2221
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
2322
* at any time.
2423
*/
25-
public final class ObjectAllocationInNewTlabHandler extends AbstractThreadDispatchingHandler {
24+
public final class ObjectAllocationInNewTlabHandler implements RecordedEventHandler {
2625
private static final String EVENT_NAME = "jdk.ObjectAllocationInNewTLAB";
26+
private static final String TLAB_SIZE = "tlabSize";
2727

2828
private final LongHistogram histogram;
29+
private final Attributes attributes;
2930

3031
public ObjectAllocationInNewTlabHandler(Meter meter, ThreadGrouper grouper) {
31-
super(grouper);
32+
super();
3233
histogram =
3334
meter
3435
.histogramBuilder(Constants.METRIC_NAME_MEMORY_ALLOCATION)
3536
.setDescription(Constants.METRIC_DESCRIPTION_MEMORY_ALLOCATION)
3637
.setUnit(Constants.BYTES)
3738
.ofLongs()
3839
.build();
40+
attributes = Attributes.of(Constants.ATTR_ARENA_NAME, "TLAB");
3941
}
4042

4143
@Override
@@ -49,28 +51,9 @@ public JfrFeature getFeature() {
4951
}
5052

5153
@Override
52-
public Consumer<RecordedEvent> createPerThreadSummarizer(String threadName) {
53-
return new PerThreadObjectAllocationInNewTlabHandler(histogram);
54-
}
55-
56-
/** This class aggregates all TLAB allocation JFR events for a single thread */
57-
private static class PerThreadObjectAllocationInNewTlabHandler
58-
implements Consumer<RecordedEvent> {
59-
private static final String TLAB_SIZE = "tlabSize";
60-
61-
private final LongHistogram histogram;
62-
private final Attributes attributes;
63-
64-
public PerThreadObjectAllocationInNewTlabHandler(LongHistogram histogram) {
65-
this.histogram = histogram;
66-
this.attributes = Attributes.of(Constants.ATTR_ARENA_NAME, "TLAB");
67-
}
68-
69-
@Override
70-
public void accept(RecordedEvent ev) {
71-
histogram.record(ev.getLong(TLAB_SIZE), attributes);
72-
// Probably too high a cardinality
73-
// ev.getClass("objectClass").getName();
74-
}
54+
public void accept(RecordedEvent ev) {
55+
histogram.record(ev.getLong(TLAB_SIZE), attributes);
56+
// Probably too high a cardinality
57+
// ev.getClass("objectClass").getName();
7558
}
7659
}

instrumentation/runtime-telemetry/runtime-telemetry-java17/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/java17/internal/memory/ObjectAllocationOutsideTlabHandler.java

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
import io.opentelemetry.api.metrics.LongHistogram;
1010
import io.opentelemetry.api.metrics.Meter;
1111
import io.opentelemetry.instrumentation.runtimemetrics.java17.JfrFeature;
12-
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.AbstractThreadDispatchingHandler;
1312
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.Constants;
13+
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.RecordedEventHandler;
1414
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.ThreadGrouper;
15-
import java.util.function.Consumer;
1615
import jdk.jfr.consumer.RecordedEvent;
1716

1817
/**
@@ -22,20 +21,24 @@
2221
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
2322
* at any time.
2423
*/
25-
public final class ObjectAllocationOutsideTlabHandler extends AbstractThreadDispatchingHandler {
24+
public final class ObjectAllocationOutsideTlabHandler implements RecordedEventHandler {
2625
private static final String EVENT_NAME = "jdk.ObjectAllocationOutsideTLAB";
26+
private static final String ALLOCATION_SIZE = "allocationSize";
2727

2828
private final LongHistogram histogram;
29+
private final Attributes attributes;
2930

3031
public ObjectAllocationOutsideTlabHandler(Meter meter, ThreadGrouper grouper) {
31-
super(grouper);
32+
super();
3233
histogram =
3334
meter
3435
.histogramBuilder(Constants.METRIC_NAME_MEMORY_ALLOCATION)
3536
.setDescription(Constants.METRIC_DESCRIPTION_MEMORY_ALLOCATION)
3637
.setUnit(Constants.BYTES)
3738
.ofLongs()
3839
.build();
40+
41+
attributes = Attributes.of(Constants.ATTR_ARENA_NAME, "Main");
3942
}
4043

4144
@Override
@@ -49,28 +52,9 @@ public JfrFeature getFeature() {
4952
}
5053

5154
@Override
52-
public Consumer<RecordedEvent> createPerThreadSummarizer(String threadName) {
53-
return new PerThreadObjectAllocationOutsideTlabHandler(histogram);
54-
}
55-
56-
/** This class aggregates all non-TLAB allocation JFR events for a single thread */
57-
private static class PerThreadObjectAllocationOutsideTlabHandler
58-
implements Consumer<RecordedEvent> {
59-
private static final String ALLOCATION_SIZE = "allocationSize";
60-
61-
private final LongHistogram histogram;
62-
private final Attributes attributes;
63-
64-
public PerThreadObjectAllocationOutsideTlabHandler(LongHistogram histogram) {
65-
this.histogram = histogram;
66-
this.attributes = Attributes.of(Constants.ATTR_ARENA_NAME, "Main");
67-
}
68-
69-
@Override
70-
public void accept(RecordedEvent ev) {
71-
histogram.record(ev.getLong(ALLOCATION_SIZE), attributes);
72-
// Probably too high a cardinality
73-
// ev.getClass("objectClass").getName();
74-
}
55+
public void accept(RecordedEvent ev) {
56+
histogram.record(ev.getLong(ALLOCATION_SIZE), attributes);
57+
// Probably too high a cardinality
58+
// ev.getClass("objectClass").getName();
7559
}
7660
}

instrumentation/runtime-telemetry/runtime-telemetry-java17/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/java17/internal/network/NetworkReadHandler.java

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,26 @@
1010
import io.opentelemetry.api.metrics.LongHistogram;
1111
import io.opentelemetry.api.metrics.Meter;
1212
import io.opentelemetry.instrumentation.runtimemetrics.java17.JfrFeature;
13-
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.AbstractThreadDispatchingHandler;
1413
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.Constants;
1514
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.DurationUtil;
15+
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.RecordedEventHandler;
1616
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.ThreadGrouper;
17-
import java.util.function.Consumer;
1817
import jdk.jfr.consumer.RecordedEvent;
1918

2019
/**
2120
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
2221
* any time.
2322
*/
24-
public final class NetworkReadHandler extends AbstractThreadDispatchingHandler {
23+
public final class NetworkReadHandler implements RecordedEventHandler {
2524
private static final String EVENT_NAME = "jdk.SocketRead";
25+
private static final String BYTES_READ = "bytesRead";
2626

2727
private final LongHistogram bytesHistogram;
2828
private final DoubleHistogram durationHistogram;
29+
private final Attributes attributes;
2930

3031
public NetworkReadHandler(Meter meter, ThreadGrouper nameNormalizer) {
31-
super(nameNormalizer);
32+
super();
3233
bytesHistogram =
3334
meter
3435
.histogramBuilder(Constants.METRIC_NAME_NETWORK_BYTES)
@@ -42,6 +43,7 @@ public NetworkReadHandler(Meter meter, ThreadGrouper nameNormalizer) {
4243
.setDescription(Constants.METRIC_DESCRIPTION_NETWORK_DURATION)
4344
.setUnit(Constants.SECONDS)
4445
.build();
46+
attributes = Attributes.of(Constants.ATTR_NETWORK_MODE, Constants.NETWORK_MODE_READ);
4547
}
4648

4749
@Override
@@ -55,28 +57,8 @@ public JfrFeature getFeature() {
5557
}
5658

5759
@Override
58-
public Consumer<RecordedEvent> createPerThreadSummarizer(String threadName) {
59-
return new PerThreadNetworkReadHandler(bytesHistogram, durationHistogram);
60-
}
61-
62-
private static class PerThreadNetworkReadHandler implements Consumer<RecordedEvent> {
63-
private static final String BYTES_READ = "bytesRead";
64-
65-
private final LongHistogram bytesHistogram;
66-
private final DoubleHistogram durationHistogram;
67-
private final Attributes attributes;
68-
69-
public PerThreadNetworkReadHandler(
70-
LongHistogram bytesHistogram, DoubleHistogram durationHistogram) {
71-
this.bytesHistogram = bytesHistogram;
72-
this.durationHistogram = durationHistogram;
73-
this.attributes = Attributes.of(Constants.ATTR_NETWORK_MODE, Constants.NETWORK_MODE_READ);
74-
}
75-
76-
@Override
77-
public void accept(RecordedEvent ev) {
78-
bytesHistogram.record(ev.getLong(BYTES_READ), attributes);
79-
durationHistogram.record(DurationUtil.toSeconds(ev.getDuration()), attributes);
80-
}
60+
public void accept(RecordedEvent ev) {
61+
bytesHistogram.record(ev.getLong(BYTES_READ), attributes);
62+
durationHistogram.record(DurationUtil.toSeconds(ev.getDuration()), attributes);
8163
}
8264
}

0 commit comments

Comments
 (0)