Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Compilation JVM metric binder #1589

Merged
merged 2 commits into from
Dec 16, 2019

Conversation

gquintana
Copy link
Contributor

Add a metric binder to get JVM compilation time

MeterRegistry registry = new SimpleMeterRegistry();
new CompilationMetrics().bindTo(registry);

assertThat(registry.get("jvm.compilation.time.total").gauge().value()).isGreaterThan(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this test fail on builds that run on alternate JDKs? I'm not too familiar with the build setup in that regard @shakuzen

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was of the false memory that we already had some kind of matrix build which don't just test the different Hotspot JVMs. Apparently that isn't the case. Was quickly testing a ./gradlew test with 8u222-openJ9 and there's quite some test failures before I could reach this one. (Hope I didn't screw up.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a problem in the end?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was of the false memory that we already had some kind of matrix build which don't just test the different Hotspot JVMs. Apparently that isn't the case.

I opened an issue for it but never got around to doing it - #1462. If a test is specific to a JVM, you can use JUnit Assumptions to skip it when those assumptions aren't meant. We do this for example in the ProcessorMetricsTest:

assumeTrue(classExists("com.ibm.lang.management.OperatingSystemMXBean"));


@NonNullApi
@NonNullFields
public class CompilationMetrics implements MeterBinder {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shakuzen @jkschneider Should this class be named JvmCompilationMetrics since these are metrics around the JVM?

Copy link
Contributor Author

@gquintana gquintana Sep 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind renaming the class but there is already a ClassLoaderMetrics class which should be renamed JvmClassLoaderMetrics in that case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree JvmCompilationMetrics is more clear here. ClassLoaderMetrics is already released public API so we can't change that without breaking all users of it.

public void bindTo(MeterRegistry registry) {
CompilationMXBean compilationBean = ManagementFactory.getCompilationMXBean();
if (compilationBean.isCompilationTimeMonitoringSupported()) {
FunctionCounter.builder("jvm.compilation.time.total", compilationBean, CompilationMXBean::getTotalCompilationTime)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure about the naming and the baseUnit usage below.
The PrometheusNamingConvention adds the unit and then the "_total" suffix again due to how it works for Counters:
jvm_compilation_time_total_ms_total

Unfortunately we can't make this a Timer due to not being triggered by the JVM so we don't really have any counts on compilation frequency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about jvm.compilation.ms.total ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will become jvm_compilation_ms_total_ms_total because the PrometheusNamingConvention will first add the base unit and then the _total.

How about just jvm.compilation.time and any NamingConvention specific to a registry implementation will make sure that it generates whatever is best practice for that backend. For Prometheus this would then become jvm_compilation_time_ms_total.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jvm.compilation.time sounds good to me.

@shakuzen shakuzen added the enhancement A general enhancement label Sep 29, 2019
@shakuzen shakuzen added this to the 1.4.0 milestone Sep 29, 2019
@shakuzen shakuzen added the spring-boot change Change is needed in Spring Boot for this issue label Dec 16, 2019
Copy link
Member

@shakuzen shakuzen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this enhancement. I'll add a polish commit after merging and link it here.

public void bindTo(MeterRegistry registry) {
CompilationMXBean compilationBean = ManagementFactory.getCompilationMXBean();
if (compilationBean.isCompilationTimeMonitoringSupported()) {
FunctionCounter.builder("jvm.compilation.time.total", compilationBean, CompilationMXBean::getTotalCompilationTime)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jvm.compilation.time sounds good to me.

@shakuzen shakuzen merged commit 9f8d0a0 into micrometer-metrics:master Dec 16, 2019
@shakuzen
Copy link
Member

Polish in 114d62b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A general enhancement spring-boot change Change is needed in Spring Boot for this issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants