feat: support legacy and new prometheus client stacks#16132
Conversation
- add an adapter-based Prometheus reporter for both Micrometer registries - detect both legacy and new Prometheus dependencies at runtime - wire new Prometheus pushgateway dependencies into the BOM and Spring Boot autoconfigure
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 3.3 #16132 +/- ##
============================================
+ Coverage 60.77% 60.82% +0.04%
- Complexity 15 11758 +11743
============================================
Files 1953 1953
Lines 89119 89182 +63
Branches 13445 13453 +8
============================================
+ Hits 54165 54243 +78
+ Misses 29380 29370 -10
+ Partials 5574 5569 -5
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:
|
|
Do you test https://github.com/SavitarC/dubbo-support-prometheusmetrics with applying this pr? |
|
i tested https://github.com/apache/dubbo-samples/tree/master/4-governance/dubbo-samples-metrics-prometheus with applying this pr by bumping the versions, then build the test projects, run the provider app and execute such command, but i got such response: |
|
@zrlw I found the root cause. The In this PR, I moved the required Prometheus client dependencies and the old/new Prometheus client compatibility logic into
With Spring Boot 3.5.x, the old simpleclient-based Prometheus stack is no longer brought in through the Spring Boot / Micrometer dependency path. Therefore, the Dubbo Prometheus extension module, I have tested again with:
After adding For the XML-based However, I am not fully sure about the expected dependency convention for If that is the expected behavior, I will update this PR to make |
|
As for me, |
|
But it seemed a little bit weird that |
|
this pr should be ok since apache/dubbo-samples#1291 has been merged. |
|
ConsumerMetricsIT and ProviderMetricsIT at apache/dubbo-samples#1291 will fail due to unmatched metric names if running them with springboot 3.5.10 and this pr, e.g., refer to the reason that you said at #14964 Could you provide a compatible solution? |
|
By the way, there are many metric names that does not be normalized, e.g., |
|
@zrlw Thanks for the reminder. I rechecked both the Dubbo metric registration path and the Micrometer / Prometheus naming logic. In Dubbo, these metrics are registered with different sample types:
For the legacy For the new So the expected exposed names are:
This also explains why some Therefore, I do not think we should apply a generic A safer compatible solution is to update
Then the tests can assert that one of the resolved names exists. I will update the tests in this direction. This keeps Dubbo's raw metric names unchanged, avoids hard-coded aliases scattered across tests, and makes the samples compatible with both Prometheus client implementations. |
Solved by apache/dubbo-samples#1293 Good job, thanks! |
|
@SavitarC |
What is this PR for?
Fix #16109
This PR adds compatibility for both the legacy and the new Prometheus client stacks in Dubbo metrics reporting, allowing users to run with either dependency set without changing Dubbo-side logic. By default, the new stack is preferred when both are present on the classpath.
The reporter now detects a supported Prometheus stack at runtime and continues to support Pushgateway workflows, including basic authentication.
What changes were made?
micrometer-registry-prometheus/simpleclientstackmicrometer-registry-prometheus(prometheusmetrics) / new Pushgateway stackPrometheusMetricsReporterto use an adapter abstraction:LegacyPrometheusClientAdapterNewPrometheusClientAdapterprometheus-metrics-exporter-pushgatewayWhy is this needed?
Different deployments currently depend on different generations of Prometheus and Micrometer libraries. This change makes the Dubbo metrics reporter compatible with both stacks and reduces upgrade friction for users migrating between them.
How to use it
Use the following dependencies together:
dubbo-spring-boot-starterdubbo-metrics-prometheusdubbo-observability-spring-boot-starterspring-boot-starter-actuatorWith this combination, the new Prometheus stack is preferred by default when both stacks are available.
Additional Notes
Spring Boot 3.3.x and 3.4.x registry conflict
In Spring Boot 3.3.x and 3.4.x, both of the following auto-configurations may coexist:
PrometheusSimpleclientMetricsExportAutoConfigurationPrometheusMetricsExportAutoConfigurationWhen both are active at the same time, registry conflicts may occur, causing Prometheus metrics to become invisible.
Solutions
There are two possible solutions:
Manually exclude one of the two Prometheus registry implementations from
dubbo-metrics-prometheus:micrometer-registry-prometheus-simpleclientmicrometer-registry-prometheusOnly one of them should remain.
Enable the following configuration:
dubbo.metrics.use-global-registry=true