fix(metrics): support new micrometer prometheus package and make pushgateway optional#16128
fix(metrics): support new micrometer prometheus package and make pushgateway optional#16128utafrali wants to merge 1 commit intoapache:3.3from
Conversation
…gateway optional MetricsSupportUtil.isSupportPrometheus() checked for class names from older micrometer-prometheus and simpleclient packages that no longer exist in Spring Boot 3.3+ / Micrometer 1.13+. The check also required PushGateway exporter classes which are not always on the classpath. Updated the detection to accept both io.micrometer.prometheus and io.micrometer.prometheusmetrics packages. Removed the hard requirement on PushGateway exporter classes since they are only needed when pushgateway mode is explicitly enabled. Also wrapped PushGateway initialization in PrometheusMetricsReporter with a NoClassDefFoundError handler so the scrape endpoint still works when pushgateway dependencies are absent. Broadened the error handling in PrometheusMetricsReporterFactory to catch missing prometheus/micrometer classes gracefully. Fixes apache#16109
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 3.3 #16128 +/- ##
============================================
- Coverage 60.79% 60.79% -0.01%
+ Complexity 11754 11752 -2
============================================
Files 1953 1953
Lines 89118 89122 +4
Branches 13444 13443 -1
============================================
- Hits 54182 54178 -4
- Misses 29368 29375 +7
- Partials 5568 5569 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for the pointer to #16132 — the adapter approach there is more thorough than what I have here. Just to clarify the scope of this PR in case it's useful: it doesn't drop PushGateway support. It only stops requiring the PushGateway classes inside That said, #16132 covers proper dual-stack detection and both legacy/new PushGateway paths, which supersedes this. If that one lands I'm happy to close this out; leaving it open for now only in case a smaller interim patch is useful. |
Fixes #16109
Ran into this while setting up Dubbo 3.3.6 with Spring Boot 3.5 and
dubbo-observability-spring-boot-starter. Prometheus metrics were silently not initializing becauseMetricsSupportUtil.isSupportPrometheus()was checking for class names that no longer exist in Micrometer 1.13+ (io.micrometer.prometheus.PrometheusConfig) and requiring PushGateway exporter classes that aren't always on the classpath.The detection now accepts both the old
io.micrometer.prometheusand the newio.micrometer.prometheusmetricspackage. PushGateway classes are no longer required for the check since most setups just use the scrape endpoint.Also wrapped PushGateway initialization in
PrometheusMetricsReporterwith aNoClassDefFoundErrorcatch so the reporter still works for scrape mode when pushgateway deps are missing. Broadened the error handling inPrometheusMetricsReporterFactory.dependenciesNotFound()to properly catch any micrometer or prometheus class loading failures.Tests:
All passing locally on JDK 21.