Merge pull request #30837 from izeye
* gh-30837: Apply key values rename consistently Closes gh-30837
This commit is contained in:
@@ -49,11 +49,11 @@ public class ObservationAutoConfiguration {
|
||||
static ObservationRegistryPostProcessor observationRegistryPostProcessor(
|
||||
ObjectProvider<ObservationRegistryCustomizer<?>> observationRegistryCustomizers,
|
||||
ObjectProvider<ObservationPredicate> observationPredicates,
|
||||
ObjectProvider<GlobalKeyValuesProvider<?>> tagProviders,
|
||||
ObjectProvider<GlobalKeyValuesProvider<?>> keyValuesProviders,
|
||||
ObjectProvider<ObservationHandler<Context>> observationHandlers,
|
||||
ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping) {
|
||||
return new ObservationRegistryPostProcessor(observationRegistryCustomizers, observationPredicates, tagProviders,
|
||||
observationHandlers, observationHandlerGrouping);
|
||||
return new ObservationRegistryPostProcessor(observationRegistryCustomizers, observationPredicates,
|
||||
keyValuesProviders, observationHandlers, observationHandlerGrouping);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.boot.util.LambdaSafe;
|
||||
* Configurer to apply {@link ObservationRegistryCustomizer customizers} to
|
||||
* {@link ObservationRegistry observation registries}. Installs
|
||||
* {@link ObservationPredicate observation predicates} and {@link GlobalKeyValuesProvider
|
||||
* global tag providers} into the {@link ObservationRegistry}. Also uses a
|
||||
* global key values providers} into the {@link ObservationRegistry}. Also uses a
|
||||
* {@link ObservationHandlerGrouping} to group handlers, which are then added to the
|
||||
* {@link ObservationRegistry}.
|
||||
*
|
||||
@@ -43,7 +43,7 @@ class ObservationRegistryConfigurer {
|
||||
|
||||
private final ObjectProvider<ObservationPredicate> observationPredicates;
|
||||
|
||||
private final ObjectProvider<GlobalKeyValuesProvider<?>> tagProviders;
|
||||
private final ObjectProvider<GlobalKeyValuesProvider<?>> keyValuesProviders;
|
||||
|
||||
private final ObjectProvider<ObservationHandler<Context>> observationHandlers;
|
||||
|
||||
@@ -51,19 +51,19 @@ class ObservationRegistryConfigurer {
|
||||
|
||||
ObservationRegistryConfigurer(ObjectProvider<ObservationRegistryCustomizer<?>> customizers,
|
||||
ObjectProvider<ObservationPredicate> observationPredicates,
|
||||
ObjectProvider<GlobalKeyValuesProvider<?>> tagProviders,
|
||||
ObjectProvider<GlobalKeyValuesProvider<?>> keyValuesProviders,
|
||||
ObjectProvider<ObservationHandler<Context>> observationHandlers,
|
||||
ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping) {
|
||||
this.customizers = customizers;
|
||||
this.observationPredicates = observationPredicates;
|
||||
this.tagProviders = tagProviders;
|
||||
this.keyValuesProviders = keyValuesProviders;
|
||||
this.observationHandlers = observationHandlers;
|
||||
this.observationHandlerGrouping = observationHandlerGrouping;
|
||||
}
|
||||
|
||||
void configure(ObservationRegistry registry) {
|
||||
registerObservationPredicates(registry);
|
||||
registerGlobalTagsProvider(registry);
|
||||
registerGlobalKeyValuesProviders(registry);
|
||||
registerHandlers(registry);
|
||||
customize(registry);
|
||||
}
|
||||
@@ -78,9 +78,9 @@ class ObservationRegistryConfigurer {
|
||||
(observationPredicate) -> registry.observationConfig().observationPredicate(observationPredicate));
|
||||
}
|
||||
|
||||
private void registerGlobalTagsProvider(ObservationRegistry registry) {
|
||||
this.tagProviders.orderedStream()
|
||||
.forEach((tagProvider) -> registry.observationConfig().keyValuesProvider(tagProvider));
|
||||
private void registerGlobalKeyValuesProviders(ObservationRegistry registry) {
|
||||
this.keyValuesProviders.orderedStream()
|
||||
.forEach((keyValuesProvider) -> registry.observationConfig().keyValuesProvider(keyValuesProvider));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -39,7 +39,7 @@ class ObservationRegistryPostProcessor implements BeanPostProcessor {
|
||||
|
||||
private final ObjectProvider<ObservationPredicate> observationPredicates;
|
||||
|
||||
private final ObjectProvider<GlobalKeyValuesProvider<?>> tagProviders;
|
||||
private final ObjectProvider<GlobalKeyValuesProvider<?>> keyValuesProviders;
|
||||
|
||||
private final ObjectProvider<ObservationHandler<Context>> observationHandlers;
|
||||
|
||||
@@ -49,12 +49,12 @@ class ObservationRegistryPostProcessor implements BeanPostProcessor {
|
||||
|
||||
ObservationRegistryPostProcessor(ObjectProvider<ObservationRegistryCustomizer<?>> observationRegistryCustomizers,
|
||||
ObjectProvider<ObservationPredicate> observationPredicates,
|
||||
ObjectProvider<GlobalKeyValuesProvider<?>> tagProviders,
|
||||
ObjectProvider<GlobalKeyValuesProvider<?>> keyValuesProviders,
|
||||
ObjectProvider<ObservationHandler<Context>> observationHandlers,
|
||||
ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping) {
|
||||
this.observationRegistryCustomizers = observationRegistryCustomizers;
|
||||
this.observationPredicates = observationPredicates;
|
||||
this.tagProviders = tagProviders;
|
||||
this.keyValuesProviders = keyValuesProviders;
|
||||
this.observationHandlers = observationHandlers;
|
||||
this.observationHandlerGrouping = observationHandlerGrouping;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ class ObservationRegistryPostProcessor implements BeanPostProcessor {
|
||||
private ObservationRegistryConfigurer getConfigurer() {
|
||||
if (this.configurer == null) {
|
||||
this.configurer = new ObservationRegistryConfigurer(this.observationRegistryCustomizers,
|
||||
this.observationPredicates, this.tagProviders, this.observationHandlers,
|
||||
this.observationPredicates, this.keyValuesProviders, this.observationHandlers,
|
||||
this.observationHandlerGrouping);
|
||||
}
|
||||
return this.configurer;
|
||||
|
||||
@@ -99,12 +99,12 @@ class ObservationAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void autoConfiguresGlobalTagsProvider() {
|
||||
this.contextRunner.withUserConfiguration(GlobalTagsProviders.class).run((context) -> {
|
||||
void autoConfiguresGlobalKeyValuesProvider() {
|
||||
this.contextRunner.withUserConfiguration(GlobalKeyValuesProviders.class).run((context) -> {
|
||||
ObservationRegistry observationRegistry = context.getBean(ObservationRegistry.class);
|
||||
Context micrometerContext = new Context();
|
||||
Observation.start("test-observation", micrometerContext, observationRegistry).stop();
|
||||
assertThat(micrometerContext.getAllKeyValues()).containsExactly(KeyValue.of("tag1", "value1"));
|
||||
assertThat(micrometerContext.getAllKeyValues()).containsExactly(KeyValue.of("key1", "value1"));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -161,10 +161,10 @@ class ObservationAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class GlobalTagsProviders {
|
||||
static class GlobalKeyValuesProviders {
|
||||
|
||||
@Bean
|
||||
Observation.GlobalKeyValuesProvider<?> customTagsProvider() {
|
||||
Observation.GlobalKeyValuesProvider<?> customKeyValuesProvider() {
|
||||
return new GlobalKeyValuesProvider<>() {
|
||||
@Override
|
||||
public boolean supportsContext(Context context) {
|
||||
@@ -173,7 +173,7 @@ class ObservationAutoConfigurationTests {
|
||||
|
||||
@Override
|
||||
public KeyValues getLowCardinalityKeyValues(Context context) {
|
||||
return KeyValues.of("tag1", "value1");
|
||||
return KeyValues.of("key1", "value1");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user