Skip to content

Missing RabbitMQ metrics if bean is defined as a ConnectionFactory #25138

Closed
@Huo12345

Description

@Huo12345

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

  1. Download sample src attached demo-rabbitmq-metrics-issue.zip
  2. Start RabbitMQ service (locally installed service or from docker-compose file in the source)
  3. Run the application with the profile local and check prometheus endpoint for entries with rabbit -> Should have multiple
  4. 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 profile ab to see the metrics and if to 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?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions