mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Allow custom ExemplarSampler to be used
See gh-35619
This commit is contained in:
parent
3586bfb629
commit
94b17ecd26
@ -90,7 +90,7 @@ public class PrometheusMetricsExportAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnMissingBean(ExemplarSampler.class)
|
||||
@ConditionalOnBean(SpanContextSupplier.class)
|
||||
public DefaultExemplarSampler exemplarSampler(SpanContextSupplier spanContextSupplier) {
|
||||
return new DefaultExemplarSampler(spanContextSupplier);
|
||||
|
@ -20,6 +20,8 @@ import io.micrometer.core.instrument.Clock;
|
||||
import io.micrometer.prometheus.PrometheusConfig;
|
||||
import io.micrometer.prometheus.PrometheusMeterRegistry;
|
||||
import io.prometheus.client.CollectorRegistry;
|
||||
import io.prometheus.client.exemplars.DefaultExemplarSampler;
|
||||
import io.prometheus.client.exemplars.Exemplar;
|
||||
import io.prometheus.client.exemplars.ExemplarSampler;
|
||||
import io.prometheus.client.exemplars.tracer.common.SpanContextSupplier;
|
||||
import io.prometheus.client.exporter.BasicAuthHttpConnectionFactory;
|
||||
@ -64,6 +66,12 @@ class PrometheusMetricsExportAutoConfigurationTests {
|
||||
this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(PrometheusMeterRegistry.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void backsOfWhenExemplarSamplerIsPresent() {
|
||||
this.contextRunner.withUserConfiguration(CustomExemplarSamplerConfiguration.class)
|
||||
.run((context) -> assertThat(context).doesNotHaveBean(DefaultExemplarSampler.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfiguresItsConfigCollectorRegistryAndMeterRegistry() {
|
||||
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
|
||||
@ -119,7 +127,7 @@ class PrometheusMetricsExportAutoConfigurationTests {
|
||||
|
||||
@Test
|
||||
void autoConfiguresExemplarSamplerIfSpanContextSupplierIsPresent() {
|
||||
this.contextRunner.withUserConfiguration(ExemplarsConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(DefaultExemplarSamplerConfiguration.class)
|
||||
.run((context) -> assertThat(context).hasSingleBean(SpanContextSupplier.class)
|
||||
.hasSingleBean(ExemplarSampler.class)
|
||||
.hasSingleBean(PrometheusMeterRegistry.class));
|
||||
@ -287,7 +295,7 @@ class PrometheusMetricsExportAutoConfigurationTests {
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Import(BaseConfiguration.class)
|
||||
static class ExemplarsConfiguration {
|
||||
static class DefaultExemplarSamplerConfiguration {
|
||||
|
||||
@Bean
|
||||
SpanContextSupplier spanContextSupplier() {
|
||||
@ -313,4 +321,26 @@ class PrometheusMetricsExportAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Import(BaseConfiguration.class)
|
||||
static class CustomExemplarSamplerConfiguration {
|
||||
|
||||
@Bean
|
||||
ExemplarSampler exemplarSampler() {
|
||||
return new ExemplarSampler() {
|
||||
|
||||
@Override
|
||||
public Exemplar sample(double value, double bucketFrom, double bucketTo, Exemplar previous) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Exemplar sample(double increment, Exemplar previous) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user