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
Auto-configured ExemplarSampler bean only backs off when a DefaultExemplarSampler is defined #35619
Conversation
…ExemplarSampler to avoid @ConditionalOnMissingBean missing user defined beans
@johnnywiller Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@johnnywiller Thank you for signing the Contributor License Agreement! |
@@ -92,7 +92,7 @@ public CollectorRegistry collectorRegistry() { | |||
@Bean | |||
@ConditionalOnMissingBean | |||
@ConditionalOnBean(SpanContextSupplier.class) | |||
public DefaultExemplarSampler exemplarSampler(SpanContextSupplier spanContextSupplier) { |
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.
Rather than changing the return type, which deprives the bean factory of type information, it would be better to change @ConditionalOnMissingBean
to @ConditionalOnMissingBean(ExamplarSampler.class)
. This will cause exemplarSampler
to back off if there's an ExamplarEampler
bean defined, while also still telling the bean factory that exemplarSampler
is a DefaultExemplarSampler
.
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 review, changed.
I'm not particularly familiar with best practices around bean autoconfiguration and conditional beans idiom, but I though defining interfaces instead of implementation would allow for more overall flexibility.
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.
When Spring Framework creates bean definitions from @Configuration
classes it only has the method signature to go on. It won't actually invoke the method and get the real bean instance until much later.
For that reason, it's always best to use the most specific type in the method signature. That way Spring has as much information as possible.
…r) to avoid depriving BeanFactory of the actual bean type Signed-off-by: Johnny Goncalves <j.goncalves@ocado.com>
We should add a test for the backing-off behavior as part of merging this. |
Signed-off-by: Johnny Goncalves <j.goncalves@ocado.com>
…on ExemplarsConfiguration Signed-off-by: Johnny Goncalves <j.goncalves@ocado.com>
Signed-off-by: Johnny Goncalves <j.goncalves@ocado.com>
...e/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfigurationTests.java
Outdated
Show resolved
Hide resolved
...e/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfigurationTests.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Johnny Goncalves <j.goncalves@ocado.com>
...e/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfigurationTests.java
Outdated
Show resolved
Hide resolved
Out of curiosity (I think this is a good change that we should merge in): what is your use case for having a custom exemplar sampler? |
We are decorating the bean The decorator looks like
|
…on this test, also removed mockito.mock in favor of empty impl Signed-off-by: Johnny Goncalves <j.goncalves@ocado.com>
I'm thinking, if prometheus sampler/supplier and/or Boot should provide this functionality. I have another quick question: I did not check this so I'm not sure what can go wrong with it but wouldn't this be possible in the |
You mean, providing a extension point to add custom tags to the spans, or directly tag a span as exemplar?
We just want to tag spans when they are being used as exemplars on metrics, not for all spans.
So to me, if feels more solid to add the tagging behaviour close to
I forgot to mention in the use case description, the otel collector has a TAIL SAMPLING rule to avoid dropping spans with the |
We can let you inject a
I'm not sure what is the relevance of this,
The only thing I can think of right now is doing this in a getter ( Let's continue this discussion here: prometheus/client_java#843, if we can find a good general solution, I think we can add support for this in Micrometer and Boot. |
@johnnywiller thank you for making your first contribution to Spring Boot. |
Having Spring Actuator autoconfiguring a
DefaultExemplarSampler
makes it harder for the user to define its own bean of typeExemplarSampler
, since@ConditionalOnMissingBean
will still create aDefaultExemplarSampler
causing two beans of typeExemplarSampler
to be created.This PR simply points to the interface instead.
Another option would be to explicitly add
@ConditionalOnMissingBean(ExemplarSampler.class)
but seems less correct.