prometheus / client_java

Prometheus instrumentation library for JVM applications

Home Page:http://prometheus.github.io/client_java/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle possible ThreadMXBean findDeadlockedThreads UnsupportedOperationException

dhoard opened this issue · comments

While testing the JMX Exporter against the latest JVM versions...

https://github.com/prometheus/jmx_exporter/blob/main/integration_test_suite/integration_tests/src/test/resources/docker-image-names.all.txt

It seems that azul/prime:8, azul/prime:11, and azul/prime:17 have changed behavior and no longer support findDeadlockedThreads, throwing an UnsupportedOperationException

java.lang.UnsupportedOperationException: Monitoring of Synchronizer Usage is not supported.
at java.management/sun.management.ThreadImpl.findDeadlockedThreads(ThreadImpl.java:431)
at io.prometheus.jmx.shaded.io.prometheus.client.hotspot.ThreadExports.addThreadMetrics(ThreadExports.java:98)
at io.prometheus.jmx.shaded.io.prometheus.client.hotspot.ThreadExports.collect(ThreadExports.java:175)
at io.prometheus.jmx.shaded.io.prometheus.client.hotspot.ThreadExports.collect(ThreadExports.java:169)

This exists in the pre-1.0.0 code, but will also cause issues in the 1.0.0 code.

The code below needs to be changed to handle such scenarios since the JVM is not required to support findDeadlockedThreads

if (!isNativeImage) {
GaugeWithCallback.builder(config)
.name(JVM_THREADS_DEADLOCKED)
.help("Cycles of JVM-threads that are in deadlock waiting to acquire object monitors or ownable synchronizers")
.callback(callback -> callback.call(nullSafeArrayLength(threadBean.findDeadlockedThreads())))
.register(registry);