mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge pull request #35619 from johnnywiller
* pr/35619: Polish "Allow custom ExemplarSampler to be used" Allow custom ExemplarSampler to be used Closes gh-35619
This commit is contained in:
commit
c0e263dc3c
@ -90,7 +90,7 @@ public class PrometheusMetricsExportAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnMissingBean(ExemplarSampler.class)
|
||||
@ConditionalOnBean(SpanContextSupplier.class)
|
||||
public DefaultExemplarSampler exemplarSampler(SpanContextSupplier spanContextSupplier) {
|
||||
return new DefaultExemplarSampler(spanContextSupplier);
|
||||
|
@ -45,6 +45,7 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link PrometheusMetricsExportAutoConfiguration}.
|
||||
@ -125,6 +126,15 @@ class PrometheusMetricsExportAutoConfigurationTests {
|
||||
.hasSingleBean(PrometheusMeterRegistry.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void allowsCustomExemplarSamplerToBeUsed() {
|
||||
this.contextRunner.withUserConfiguration(ExemplarsConfiguration.class)
|
||||
.withBean("customExemplarSampler", ExemplarSampler.class, () -> mock(ExemplarSampler.class))
|
||||
.run((context) -> assertThat(context).hasSingleBean(ExemplarSampler.class)
|
||||
.getBean(ExemplarSampler.class)
|
||||
.isSameAs(context.getBean("customExemplarSampler")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void exemplarSamplerIsNotAutoConfiguredIfSpanContextSupplierIsMissing() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
|
Loading…
Reference in New Issue
Block a user