Skip to content

Commit bd64e05

Browse files
committed
Instrument AMQP AbstractCF when defined as a ConnectionFactory
Fixes gh-25138
1 parent 82dc2df commit bd64e05

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@
4242
@AutoConfigureAfter({ MetricsAutoConfiguration.class, RabbitAutoConfiguration.class,
4343
SimpleMetricsExportAutoConfiguration.class })
4444
@ConditionalOnClass({ ConnectionFactory.class, AbstractConnectionFactory.class })
45-
@ConditionalOnBean({ AbstractConnectionFactory.class, MeterRegistry.class })
45+
@ConditionalOnBean({ org.springframework.amqp.rabbit.connection.ConnectionFactory.class, MeterRegistry.class })
4646
public class RabbitMetricsAutoConfiguration {
4747

4848
@Bean

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitMetricsAutoConfigurationTests.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,10 +19,14 @@
1919
import io.micrometer.core.instrument.MeterRegistry;
2020
import org.junit.jupiter.api.Test;
2121

22+
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
23+
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
2224
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
2325
import org.springframework.boot.autoconfigure.AutoConfigurations;
2426
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
2527
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
28+
import org.springframework.context.annotation.Bean;
29+
import org.springframework.context.annotation.Configuration;
2630

2731
import static org.assertj.core.api.Assertions.assertThat;
2832

@@ -45,6 +49,15 @@ void autoConfiguredConnectionFactoryIsInstrumented() {
4549
});
4650
}
4751

52+
@Test
53+
void abstractConnectionFactoryDefinedAsAConnectionFactoryIsInstrumented() {
54+
this.contextRunner.withUserConfiguration(ConnectionFactoryConfiguration.class).run((context) -> {
55+
assertThat(context).hasBean("customConnectionFactory");
56+
MeterRegistry registry = context.getBean(MeterRegistry.class);
57+
registry.get("rabbitmq.connections").meter();
58+
});
59+
}
60+
4861
@Test
4962
void rabbitmqNativeConnectionFactoryInstrumentationCanBeDisabled() {
5063
this.contextRunner.withPropertyValues("management.metrics.enable.rabbitmq=false").run((context) -> {
@@ -53,4 +66,14 @@ void rabbitmqNativeConnectionFactoryInstrumentationCanBeDisabled() {
5366
});
5467
}
5568

69+
@Configuration
70+
static class ConnectionFactoryConfiguration {
71+
72+
@Bean
73+
ConnectionFactory customConnectionFactory() {
74+
return new CachingConnectionFactory();
75+
}
76+
77+
}
78+
5679
}

0 commit comments

Comments
 (0)