Skip to content
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

RabbitMetricsAutoConfiguration is instantiated too late #12855

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

Comments

Projects
None yet
4 participants
@mzakes
Copy link

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

@snicoll

This comment has been minimized.

Copy link
Member

commented Apr 13, 2018

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

@mzakes

This comment has been minimized.

Copy link
Author

commented Apr 13, 2018

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

@philwebb

This comment has been minimized.

Copy link
Member

commented Apr 13, 2018

@snicoll

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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.

@snicoll snicoll self-assigned this May 18, 2018

@snicoll snicoll modified the milestones: 2.0.x, 2.0.3 May 18, 2018

@snicoll snicoll closed this in 6893be5 May 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.