From ba21c9035515344873c38a1575f08c6336de90c8 Mon Sep 17 00:00:00 2001 From: Vladimir Konkov Date: Fri, 3 Sep 2021 21:27:00 +0300 Subject: [PATCH] Auto-configure JVM heap pressure metrics See gh-27868 --- .../autoconfigure/metrics/JvmMetricsAutoConfiguration.java | 7 +++++++ .../metrics/JvmMetricsAutoConfigurationTests.java | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfiguration.java index bbe9cd6c47..f2ca2cf6cb 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfiguration.java @@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.metrics; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics; import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics; +import io.micrometer.core.instrument.binder.jvm.JvmHeapPressureMetrics; import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics; import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics; @@ -48,6 +49,12 @@ public class JvmMetricsAutoConfiguration { return new JvmGcMetrics(); } + @Bean + @ConditionalOnMissingBean + public JvmHeapPressureMetrics jvmHeapPressureMetrics() { + return new JvmHeapPressureMetrics(); + } + @Bean @ConditionalOnMissingBean public JvmMemoryMetrics jvmMemoryMetrics() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfigurationTests.java index f9e2106e32..f4d640532f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfigurationTests.java @@ -18,6 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.metrics; import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics; import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics; +import io.micrometer.core.instrument.binder.jvm.JvmHeapPressureMetrics; import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics; import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics; import org.junit.jupiter.api.Test; @@ -74,7 +75,8 @@ class JvmMetricsAutoConfigurationTests { private ContextConsumer assertMetricsBeans() { return (context) -> assertThat(context).hasSingleBean(JvmGcMetrics.class).hasSingleBean(JvmMemoryMetrics.class) - .hasSingleBean(JvmThreadMetrics.class).hasSingleBean(ClassLoaderMetrics.class); + .hasSingleBean(JvmHeapPressureMetrics.class).hasSingleBean(JvmThreadMetrics.class) + .hasSingleBean(ClassLoaderMetrics.class); } @Configuration(proxyBeanMethods = false)