Add Gauges for memory usage after GC#7296
Add Gauges for memory usage after GC#7296shakuzen wants to merge 3 commits intomicrometer-metrics:mainfrom
Conversation
See https://opentelemetry.io/docs/specs/semconv/runtime/jvm-metrics/#metric-jvmmemoryused_after_last_gc. Register gauges in JvmMemoryMetrics and add MeterConvention for it.
| * | ||
| * @author Michael Weirauch | ||
| */ | ||
| @Tag("gc") |
There was a problem hiding this comment.
I figured it is worth running these tests with different GC configurations to ensure there are no surprises.
There was a problem hiding this comment.
Updated to use @GcTest which is equivalent.
|
|
||
| JvmMemoryMeterConventions.JvmMemoryUsedAfterLastGcConvention memoryUsedAfterLastGcConvention = conventions | ||
| .getMemoryUsedAfterLastGcConvention(); | ||
| if (memoryPoolBean.getCollectionUsage() != null) { |
There was a problem hiding this comment.
I did have a version of this code that registered pools even if this returns null, but they always have the value NaN which didn't seem worthwhile registering.
| * | ||
| * @since 1.17.0 | ||
| */ | ||
| interface JvmMemoryUsedAfterLastGcConvention extends MeterConvention<MemoryPoolMXBean> { |
There was a problem hiding this comment.
I don't know if it would be better to make this a top level type - it can be a bit annoying to reference it as JvmMemoryMeterConventions.JvmMemoryUsedAfterLastGcConvention, but maybe it also logically groups what would be the individual convention types (if we had them for the other conventions here, that is).
There was a problem hiding this comment.
Grouping makes sense to me. Not sure how well-known it is but if people annoyed by using JvmMemoryMeterConventions.JvmMemoryUsedAfterLastGcConvention, they can static import it:
import static io.micrometer.core.instrument.binder.jvm.convention.JvmMemoryMeterConventions.JvmMemoryUsedAfterLastGcConvention;and use only JvmMemoryUsedAfterLastGcConvention like it would be a top-level type.
| * @return convention for JVM memory used after last GC | ||
| * @since 1.17.0 | ||
| */ | ||
| default JvmMemoryUsedAfterLastGcConvention getMemoryUsedAfterLastGcConvention() { |
There was a problem hiding this comment.
While other methods here have return type MeterConvention<MemoryPoolMXBean>, that was probably a mistake that I tried to not repeat here. In a framework's configuration model, it would be reasonable for there to be a way for a user to provide a custom convention for a specific convention, and that's made harder by using generic types that do not uniquely identify a single convention.
There was a problem hiding this comment.
Should we create an issue for 2.x?
|
|
||
| @Override | ||
| default Tags getTags(MemoryPoolMXBean memoryPoolBean) { | ||
| return Tags.empty(); |
There was a problem hiding this comment.
The default implementation is not useful, but it was needed since we can't add a new non-default method to the JvmMemoryMeterConventions interface without breaking types that extend/implement it.
|
It's perhaps worth mentioning that there is a similarly named existing gauge for the calculated value of post-GC heap usage percentage: Maybe it makes sense to deprecate that in lieu of this newly added metric. |
I think so, I'm also thinking to disable it by default in the future and make it possible to the users to re-enable it. |
|
I opened #7311 for introducing a proper deprecation concept. Until then, let's start with just mentioning the deprecation in the description of the deprecated meter. |
|
I've moved this to 1.18 and made it a draft PR. I want to figure out what we plan to do going forward with the meter conventions (current draft #7369) before adding this. I suppose we could add it first without a convention to avoid tackling that issue, but also no one asked for this, so it doesn't seem high priority either. |
See https://opentelemetry.io/docs/specs/semconv/runtime/jvm-metrics/#metric-jvmmemoryused_after_last_gc.
Register gauges in JvmMemoryMetrics and add MeterConvention for it.
Sample scrape output in Prometheus format with the default convention:
With the OpenTelemetry convention configured: