20
20
import io .micrometer .prometheus .PrometheusConfig ;
21
21
import io .micrometer .prometheus .PrometheusMeterRegistry ;
22
22
import io .prometheus .client .CollectorRegistry ;
23
- import io .prometheus .client .exemplars .DefaultExemplarSampler ;
24
- import io .prometheus .client .exemplars .Exemplar ;
25
23
import io .prometheus .client .exemplars .ExemplarSampler ;
26
24
import io .prometheus .client .exemplars .tracer .common .SpanContextSupplier ;
27
25
import io .prometheus .client .exporter .BasicAuthHttpConnectionFactory ;
47
45
import org .springframework .test .util .ReflectionTestUtils ;
48
46
49
47
import static org .assertj .core .api .Assertions .assertThat ;
48
+ import static org .mockito .Mockito .mock ;
50
49
51
50
/**
52
51
* Tests for {@link PrometheusMetricsExportAutoConfiguration}.
@@ -66,12 +65,6 @@ void backsOffWithoutAClock() {
66
65
this .contextRunner .run ((context ) -> assertThat (context ).doesNotHaveBean (PrometheusMeterRegistry .class ));
67
66
}
68
67
69
- @ Test
70
- void backsOfWhenExemplarSamplerIsPresent () {
71
- this .contextRunner .withUserConfiguration (CustomExemplarSamplerConfiguration .class )
72
- .run ((context ) -> assertThat (context ).doesNotHaveBean (DefaultExemplarSampler .class ));
73
- }
74
-
75
68
@ Test
76
69
void autoConfiguresItsConfigCollectorRegistryAndMeterRegistry () {
77
70
this .contextRunner .withUserConfiguration (BaseConfiguration .class )
@@ -127,12 +120,21 @@ void allowsCustomCollectorRegistryToBeUsed() {
127
120
128
121
@ Test
129
122
void autoConfiguresExemplarSamplerIfSpanContextSupplierIsPresent () {
130
- this .contextRunner .withUserConfiguration (DefaultExemplarSamplerConfiguration .class )
123
+ this .contextRunner .withUserConfiguration (ExemplarsConfiguration .class )
131
124
.run ((context ) -> assertThat (context ).hasSingleBean (SpanContextSupplier .class )
132
125
.hasSingleBean (ExemplarSampler .class )
133
126
.hasSingleBean (PrometheusMeterRegistry .class ));
134
127
}
135
128
129
+ @ Test
130
+ void allowsCustomExemplarSamplerToBeUsed () {
131
+ this .contextRunner .withUserConfiguration (ExemplarsConfiguration .class )
132
+ .withBean ("customExemplarSampler" , ExemplarSampler .class , () -> mock (ExemplarSampler .class ))
133
+ .run ((context ) -> assertThat (context ).hasSingleBean (ExemplarSampler .class )
134
+ .getBean (ExemplarSampler .class )
135
+ .isSameAs (context .getBean ("customExemplarSampler" )));
136
+ }
137
+
136
138
@ Test
137
139
void exemplarSamplerIsNotAutoConfiguredIfSpanContextSupplierIsMissing () {
138
140
this .contextRunner .withUserConfiguration (BaseConfiguration .class )
@@ -295,7 +297,7 @@ PrometheusScrapeEndpoint customEndpoint(CollectorRegistry collectorRegistry) {
295
297
296
298
@ Configuration (proxyBeanMethods = false )
297
299
@ Import (BaseConfiguration .class )
298
- static class DefaultExemplarSamplerConfiguration {
300
+ static class ExemplarsConfiguration {
299
301
300
302
@ Bean
301
303
SpanContextSupplier spanContextSupplier () {
@@ -321,26 +323,4 @@ public boolean isSampled() {
321
323
322
324
}
323
325
324
- @ Configuration (proxyBeanMethods = false )
325
- @ Import (BaseConfiguration .class )
326
- static class CustomExemplarSamplerConfiguration {
327
-
328
- @ Bean
329
- ExemplarSampler exemplarSampler () {
330
- return new ExemplarSampler () {
331
-
332
- @ Override
333
- public Exemplar sample (double value , double bucketFrom , double bucketTo , Exemplar previous ) {
334
- return null ;
335
- }
336
-
337
- @ Override
338
- public Exemplar sample (double increment , Exemplar previous ) {
339
- return null ;
340
- }
341
- };
342
- }
343
-
344
- }
345
-
346
326
}
0 commit comments