-
Couldn't load subscription status.
- Fork 41.6k
Description
Expected behaviour
When deploying an application with a RabbitMQ connection and prometheus metrics enabled to cloud foundy, the prometheus endpoint should expose metrics for RabbitMQ as documented in Spring Boot Reference Documentation similar to when run locally.
Observed behaviour
When deployed to cloud foundry, no RabbitMQ metrics are exposed on the prometheus endpoint.
Steps to reproduce
- Download sample src attached demo-rabbitmq-metrics-issue.zip
- Start RabbitMQ service (locally installed service or from docker-compose file in the source)
- Run the application with the profile
localand check prometheus endpoint for entries withrabbit-> Should have multiple - Deploy the app to cloud foundry with a RabbitMQ service attached and check the prometheus endpoint there for entries with
rabbit-> Should have none.
4.1 If there is no cloud foundry instance available for testing, you can run the app with profileabto see the metrics andifto not see them. More details in section Probable Cause.
Probable Cause
When investigating this issue I found that RabbitMetricsAutoConfiguration class has the condition @ConditionalOnBean({ AbstractConnectionFactory.class, MeterRegistry.class }) attached. From code snippets in the documentation I assume that cloud foundry exposes the connection as ConnectionFactory, an interface implemented by AbstractConnectionFactory. To test this theory I manually configured a CachingConnectionFactory and exposed it in a bean of type ConnectionFactory and AbstractConnectionFactory (see class RabbitConfig in attached code, profiles ab for AbstractConnectionFactory and if for ConnectionFactory). When exposing it as ConnectionFactory no metrics were available, but when using AbstractConnectionFactory the metrics showed up in the prometheus endpoint. Is it possible to change the conditional on RabbitMetricsAutoConfiguration to @ConditionalOnBean({ ConnectionFactory.class, MeterRegistry.class }) to fix this issue?