Commit 9ba28a8b authored by Andy Wilkinson's avatar Andy Wilkinson

Merge branch '2.3.x' into 2.4.x

Closes gh-25185
parents 75fc8963 bd64e052
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -42,7 +42,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -42,7 +42,7 @@ import org.springframework.context.annotation.Configuration;
@AutoConfigureAfter({ MetricsAutoConfiguration.class, RabbitAutoConfiguration.class, @AutoConfigureAfter({ MetricsAutoConfiguration.class, RabbitAutoConfiguration.class,
SimpleMetricsExportAutoConfiguration.class }) SimpleMetricsExportAutoConfiguration.class })
@ConditionalOnClass({ ConnectionFactory.class, AbstractConnectionFactory.class }) @ConditionalOnClass({ ConnectionFactory.class, AbstractConnectionFactory.class })
@ConditionalOnBean({ AbstractConnectionFactory.class, MeterRegistry.class }) @ConditionalOnBean({ org.springframework.amqp.rabbit.connection.ConnectionFactory.class, MeterRegistry.class })
public class RabbitMetricsAutoConfiguration { public class RabbitMetricsAutoConfiguration {
@Bean @Bean
......
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -19,10 +19,14 @@ package org.springframework.boot.actuate.autoconfigure.metrics.amqp; ...@@ -19,10 +19,14 @@ package org.springframework.boot.actuate.autoconfigure.metrics.amqp;
import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.MeterRegistry;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun; import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -45,6 +49,15 @@ class RabbitMetricsAutoConfigurationTests { ...@@ -45,6 +49,15 @@ class RabbitMetricsAutoConfigurationTests {
}); });
} }
@Test
void abstractConnectionFactoryDefinedAsAConnectionFactoryIsInstrumented() {
this.contextRunner.withUserConfiguration(ConnectionFactoryConfiguration.class).run((context) -> {
assertThat(context).hasBean("customConnectionFactory");
MeterRegistry registry = context.getBean(MeterRegistry.class);
registry.get("rabbitmq.connections").meter();
});
}
@Test @Test
void rabbitmqNativeConnectionFactoryInstrumentationCanBeDisabled() { void rabbitmqNativeConnectionFactoryInstrumentationCanBeDisabled() {
this.contextRunner.withPropertyValues("management.metrics.enable.rabbitmq=false").run((context) -> { this.contextRunner.withPropertyValues("management.metrics.enable.rabbitmq=false").run((context) -> {
...@@ -53,4 +66,14 @@ class RabbitMetricsAutoConfigurationTests { ...@@ -53,4 +66,14 @@ class RabbitMetricsAutoConfigurationTests {
}); });
} }
@Configuration
static class ConnectionFactoryConfiguration {
@Bean
ConnectionFactory customConnectionFactory() {
return new CachingConnectionFactory();
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment