Add JFR metrics for virtual thread pinning and submit failures#19092
Add JFR metrics for virtual thread pinning and submit failures#19092tsawada wants to merge 2 commits into
Conversation
|
|
There was a problem hiding this comment.
Pull request overview
This PR adds two new JFR-based runtime-telemetry metrics for virtual threads: jvm.thread.virtual.pinned (a histogram of pinning durations from jdk.VirtualThreadPinned) and jvm.thread.virtual.submit_failed (a counter from jdk.VirtualThreadSubmitFailed). Both are gated behind a new experimental, default-disabled VIRTUAL_THREAD_METRICS JfrFeature. The handlers live in the existing java17 source set (the events exist since Java 19), and a new testJava21 source set is introduced to host tests that need GA virtual-thread APIs. The new handlers closely mirror the existing LongLockHandler pattern and are wired into HandlerRegistry.
Changes:
- Add
VirtualThreadPinnedHandlerandVirtualThreadSubmitFailedHandler, plus theVIRTUAL_THREAD_METRICSfeature, and register both handlers. - Add a
testJava21source set, configurations, compile/test task wiring, and aJfrVirtualThreadPinnedTest.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
.../internal/threads/VirtualThreadPinnedHandler.java |
New handler recording pinning duration as a seconds histogram. |
.../internal/threads/VirtualThreadSubmitFailedHandler.java |
New handler counting submit-failed events. |
.../internal/JfrFeature.java |
Adds the experimental, default-disabled VIRTUAL_THREAD_METRICS feature. |
.../internal/HandlerRegistry.java |
Registers the two new handlers. |
.../build.gradle.kts |
Adds testJava21 source set, configurations, compile/test tasks, and check wiring. |
.../testJava21/.../JfrVirtualThreadPinnedTest.java |
New Java 21+ test exercising virtual-thread pinning. |
|
This PR has review comments. Review suggestions, whether from maintainers or automated reviewers, aren't always correct or required. Please evaluate each comment on its merits, then make sure each thread has a clear outcome. For example, link to the commit if you applied a suggestion, explain why it wasn't applied, or ask a follow-up question. Automation flags a PR for human review once every review thread has a reply or is marked as resolved. Status across open PRs is visible on the pull request dashboard. |
| int feature = Runtime.version().feature(); | ||
| Assumptions.assumeTrue(feature >= 21 && feature < 24, "Requires Java 21-23"); |
There was a problem hiding this comment.
could consider @EnabledOnJre(JRE.JAVA_21)
laurit
left a comment
There was a problem hiding this comment.
https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/runtime-telemetry/library/README.md should be updated with the added metrics
jdk.VirtualThreadPinnedasjvm.thread.virtual.pinnedhistogram (seconds)jdk.VirtualThreadSubmitFailedasjvm.thread.virtual.submit_failedcounterVIRTUAL_THREAD_METRICSfeature to JfrFeature (experimental, disabled by default) - Add testJava21 source set for tests requiring Java 21+ APIsBoth events exist since Java 19. The implementation lives in the java17 source set since only the event name strings depend on JVM version.
No test for
VirtualThreadSubmitFailed, as I couldn't come up with a reliable way to trigger it.VirtualThreadPinnedthreshold defaults to 20 ms, which may be worth making configurable. Other handlers such as LongLockHandler also rely on the JFR default threshold, so I've kept the same approach here.Related: #14949