prometheus / client_java

Prometheus instrumentation library for JVM applications
http://prometheus.github.io/client_java/
Apache License 2.0
2.17k stars 792 forks source link

Illegal reflective access #443

Open GuiSim opened 5 years ago

GuiSim commented 5 years ago

Hello!

We recently upgraded to Java 11 (from Java 8) and we've hit the following WARNINGs in our services that use Prometheus:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.prometheus.client.hotspot.StandardExports (jar:redacted!/BOOT-INF/lib/simpleclient_hotspot-0.0.23.jar!/) to method com.ibm.lang.management.internal.ExtendedOperatingSystemMXBeanImpl.getProcessCpuTime()
WARNING: Please consider reporting this to the maintainers of io.prometheus.client.hotspot.StandardExports
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations 

This appears to be caused by this line: https://github.com/prometheus/client_java/blob/11408239035f02a125fe3c860f05fcd0be1e7873/simpleclient_hotspot/src/main/java/io/prometheus/client/hotspot/StandardExports.java#L64

I'd be curious to hear if this is something other users of the Prometheus Client library have hit. I'm unsure how to work around this, any suggestions?

brian-brazil commented 5 years ago

If you've got a proposal for how to deal with different JVM implementations without reflection, I'm all ears.

GuiSim commented 5 years ago

@brian-brazil

I suspect that this is a very dumb suggestion but.. can't we use System.nanoTime() ?

brian-brazil commented 5 years ago

That's the current time, not how much CPU has been used.

GuiSim commented 5 years ago

🤦‍♂️ Thanks, I knew I was missing something obvious.

pjfanning commented 5 years ago

One option would be to drop Java 6 support. https://docs.oracle.com/javase/7/docs/api/java/lang/management/OperatingSystemMXBean.html has the required methods in Java 7 and therefore could be called without reflection.

brian-brazil commented 5 years ago

I'm not seeing those methods there.

pjfanning commented 5 years ago

Apologies - I got confused by https://docs.oracle.com/javase/7/docs/jre/api/management/extension/com/sun/management/OperatingSystemMXBean.html (same class name, different package) but this is a com.sun.management interface so it seems best to use reflection.

brian-brazil commented 5 years ago

Yes, it's done this way to also work on the IBM JVM.

jsoref commented 4 years ago

Is https://github.com/hazelcast/hazelcast/pull/14798 relevant?

Specifically createRequirement.

Afaict, they seem to avoid using reflection to get there, mostly a Properties.getProperty