Skip to content

RabbitMetricsAutoConfiguration is instantiated too late #12855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mzakes opened this issue Apr 13, 2018 · 5 comments
Closed

RabbitMetricsAutoConfiguration is instantiated too late #12855

mzakes opened this issue Apr 13, 2018 · 5 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@mzakes
Copy link

mzakes commented Apr 13, 2018

Hi,

Micrometer metrics for RabbitMQ are instantiated too late which leads that metrics are never updated. Instead a NoOpMetricsCollector is used and it's methods are invoked. It seems that rabbitmq connection is created before in com.rabbitmq.client.ConnectionFactory.

    public Connection newConnection(ExecutorService executor, AddressResolver addressResolver, String clientProvidedName)
        throws IOException, TimeoutException {
        if(this.metricsCollector == null) {
            this.metricsCollector = new NoOpMetricsCollector();
        }

Workaround that works for me now is to create a RabbitMQConfiguration class with:

@PostConstruct
public void init() {
  com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = this.connectionFactory.getRabbitConnectionFactory();
  rabbitConnectionFactory.setMetricsCollector(new MicrometerMetricsCollector(registry));
}

spring-boot: 2.0.1.RELEASE

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 13, 2018
@snicoll
Copy link
Member

snicoll commented Apr 13, 2018

@mzakes Can you share a sample that we can run ourselves that demonstrates what you mean by "too late"?

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Apr 13, 2018
@mzakes
Copy link
Author

mzakes commented Apr 13, 2018

@snicoll Here is the example. Hope that it helps.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 13, 2018
@philwebb philwebb added type: bug A general bug and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Apr 13, 2018
@philwebb philwebb added this to the 2.0.x milestone Apr 13, 2018
@philwebb
Copy link
Member

/cc @jkschneider

@snicoll
Copy link
Member

snicoll commented May 18, 2018

Micrometer metrics for RabbitMQ are instantiated too late

I am not sure I understand that statement, nor the NoOp part. Debugging your sample application (that indeed exhibits an issue), a connection is created when the factory is created (I'd assume to check that the broker is available?) which will initialize the metricsCollector but that field is overridden later on by the auto-configuration and before message starts to be consumed. Something doesn't look right in this arrangement but I haven't figured out what exactly.

@snicoll
Copy link
Member

snicoll commented May 18, 2018

Alright so that configure method on your example creates a Connection and that Connection is cached and reused. So this very first connection uses the NoOp metrics collector while any further call to create a Connection will effectively use the micrometer metrics collector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants