-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
Proper ordering of metrics auto-configurations #21134
Proper ordering of metrics auto-configurations #21134
Conversation
@bendiscz Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@bendiscz Thank you for signing the Contributor License Agreement! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Did you fix those 5 auto-configurations because you were affected by them or have you reviewed all of them and those particular 5 were a problem?
I've also added a suggestion as I don't really understand looking at the code why those two are necessary as one runs before the other.
@@ -37,7 +38,7 @@ | |||
* @since 2.1.0 | |||
*/ | |||
@Configuration(proxyBeanMethods = false) | |||
@AutoConfigureAfter(MetricsAutoConfiguration.class) | |||
@AutoConfigureAfter({ CompositeMeterRegistryAutoConfiguration.class, SimpleMetricsExportAutoConfiguration.class }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SimpleMetricsExportAutoConfiguration runs before
CompositeMeterRegistryAutoConfigurationso I don't understand why both of them have to be defined here. If you run after
CompositeMeterRegistryAutoConfiguration,
SimpleMetricsExportAutoConfiguration` should have been processed too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right, CompositeMeterRegistryAutoConfiguration
should be sufficient. I added both because I saw this combination in other metrics auto-configurations, but –looking at it again – those were configurations for exporters (and the ordering was "before").
I'm going to change it.
I was directly affected by |
Metrics auto-configurations that depend on a MeterRegistry bean should be configured AFTER configurations that create the MeterRegistry. However, `@AutoConfigureAfter(MetricsAutoConfiguration.class)` is not sufficient. MetricsAutoConfiguration does not export MeterRegistry. This commit changes the `@AutoConfigureAfter` annotations so that the proper ordering of configurations in ensured.
Possible related to #11890 |
Update metrics auto-configurations so that they are auto-configured after `CompositeMeterRegistryAutoConfiguration` in order to ensure the `MeterRegistry` bean has been defined. Prior to this commit, metrics auto-configurations that depended on a `MeterRegistry` has `@AutoConfigureAfter(MetricsAutoConfiguration.class)` which is not sufficient since `MetricsAutoConfiguration` does not export a `MeterRegistry`. See gh-21134
Thanks very much for the PR @bendiscz. One of the reasons we've got away with this for so long is that Unfortunately, despite my best efforts, I couldn't find an easy way to test the fix. Each test I tried ended up causing a order cycle. I'm pretty confident with the fix, so we'll have to just run with it. |
Metrics auto-configurations that depend on a
MeterRegistry
beanshould be configured AFTER configurations that create the
MeterRegistry
. However,@AutoConfigureAfter(MetricsAutoConfiguration.class)
is not sufficient.
MetricsAutoConfiguration
does not export aMeterRegistry
.This commit changes the
@AutoConfigureAfter
annotations so that theproper ordering of configurations in ensured.
The long story:
I ran into issues in one of my spring-boot services when trying to fix a Micrometer bug. After adding a simple custom auto-configuration with dependency on
MeterRegistry
andLogbackMetrics
, the application failed to start because of a missingLogbackMetrics
dependency. Debug output showed that theLogbackMetricsAutoConfiguration
is disabled because the condition@ConditionalOnBean(MeterRegistry.class)
is not met. After more debugging I found out thatLogbackMetricsAutoConfiguration
was evaluated beforePrometheusMetricsExportAutoConfiguration
.I created a sample project that demonstrates this issue.
A simple workaround that I currently use in my projects is a dummy auto-configuration that inserts itself between
LogbackMetricsAutoConfiguration
and configurations that create theMeterRegistry
: