Merge branch '3.0.x'

Closes gh-34121
pull/34125/head
Andy Wilkinson 2 years ago
commit 1c9e22c845

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2022 the original author or authors. * Copyright 2012-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,6 +23,7 @@ import io.micrometer.core.instrument.observation.DefaultMeterObservationHandler;
import io.micrometer.core.instrument.observation.MeterObservationHandler; import io.micrometer.core.instrument.observation.MeterObservationHandler;
import io.micrometer.observation.GlobalObservationConvention; import io.micrometer.observation.GlobalObservationConvention;
import io.micrometer.observation.Observation; import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationFilter;
import io.micrometer.observation.ObservationHandler; import io.micrometer.observation.ObservationHandler;
import io.micrometer.observation.ObservationPredicate; import io.micrometer.observation.ObservationPredicate;
import io.micrometer.observation.ObservationRegistry; import io.micrometer.observation.ObservationRegistry;
@ -62,9 +63,10 @@ public class ObservationAutoConfiguration {
ObjectProvider<ObservationPredicate> observationPredicates, ObjectProvider<ObservationPredicate> observationPredicates,
ObjectProvider<GlobalObservationConvention<?>> observationConventions, ObjectProvider<GlobalObservationConvention<?>> observationConventions,
ObjectProvider<ObservationHandler<?>> observationHandlers, ObjectProvider<ObservationHandler<?>> observationHandlers,
ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping) { ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping,
ObjectProvider<ObservationFilter> observationFilters) {
return new ObservationRegistryPostProcessor(observationRegistryCustomizers, observationPredicates, return new ObservationRegistryPostProcessor(observationRegistryCustomizers, observationPredicates,
observationConventions, observationHandlers, observationHandlerGrouping); observationConventions, observationHandlers, observationHandlerGrouping, observationFilters);
} }
@Bean @Bean

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2022 the original author or authors. * Copyright 2012-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.observation;
import java.util.List; import java.util.List;
import io.micrometer.observation.GlobalObservationConvention; import io.micrometer.observation.GlobalObservationConvention;
import io.micrometer.observation.ObservationFilter;
import io.micrometer.observation.ObservationHandler; import io.micrometer.observation.ObservationHandler;
import io.micrometer.observation.ObservationPredicate; import io.micrometer.observation.ObservationPredicate;
import io.micrometer.observation.ObservationRegistry; import io.micrometer.observation.ObservationRegistry;
@ -48,22 +49,27 @@ class ObservationRegistryConfigurer {
private final ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping; private final ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping;
private final ObjectProvider<ObservationFilter> observationFilters;
ObservationRegistryConfigurer(ObjectProvider<ObservationRegistryCustomizer<?>> customizers, ObservationRegistryConfigurer(ObjectProvider<ObservationRegistryCustomizer<?>> customizers,
ObjectProvider<ObservationPredicate> observationPredicates, ObjectProvider<ObservationPredicate> observationPredicates,
ObjectProvider<GlobalObservationConvention<?>> observationConventions, ObjectProvider<GlobalObservationConvention<?>> observationConventions,
ObjectProvider<ObservationHandler<?>> observationHandlers, ObjectProvider<ObservationHandler<?>> observationHandlers,
ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping) { ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping,
ObjectProvider<ObservationFilter> observationFilters) {
this.customizers = customizers; this.customizers = customizers;
this.observationPredicates = observationPredicates; this.observationPredicates = observationPredicates;
this.observationConventions = observationConventions; this.observationConventions = observationConventions;
this.observationHandlers = observationHandlers; this.observationHandlers = observationHandlers;
this.observationHandlerGrouping = observationHandlerGrouping; this.observationHandlerGrouping = observationHandlerGrouping;
this.observationFilters = observationFilters;
} }
void configure(ObservationRegistry registry) { void configure(ObservationRegistry registry) {
registerObservationPredicates(registry); registerObservationPredicates(registry);
registerGlobalObservationConventions(registry); registerGlobalObservationConventions(registry);
registerHandlers(registry); registerHandlers(registry);
registerFilters(registry);
customize(registry); customize(registry);
} }
@ -80,6 +86,10 @@ class ObservationRegistryConfigurer {
this.observationConventions.orderedStream().forEach(registry.observationConfig()::observationConvention); this.observationConventions.orderedStream().forEach(registry.observationConfig()::observationConvention);
} }
private void registerFilters(ObservationRegistry registry) {
this.observationFilters.orderedStream().forEach(registry.observationConfig()::observationFilter);
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void customize(ObservationRegistry registry) { private void customize(ObservationRegistry registry) {
LambdaSafe.callbacks(ObservationRegistryCustomizer.class, asOrderedList(this.customizers), registry) LambdaSafe.callbacks(ObservationRegistryCustomizer.class, asOrderedList(this.customizers), registry)

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2022 the original author or authors. * Copyright 2012-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.observation; package org.springframework.boot.actuate.autoconfigure.observation;
import io.micrometer.observation.GlobalObservationConvention; import io.micrometer.observation.GlobalObservationConvention;
import io.micrometer.observation.ObservationFilter;
import io.micrometer.observation.ObservationHandler; import io.micrometer.observation.ObservationHandler;
import io.micrometer.observation.ObservationPredicate; import io.micrometer.observation.ObservationPredicate;
import io.micrometer.observation.ObservationRegistry; import io.micrometer.observation.ObservationRegistry;
@ -44,18 +45,22 @@ class ObservationRegistryPostProcessor implements BeanPostProcessor {
private final ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping; private final ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping;
private final ObjectProvider<ObservationFilter> observationFilters;
private volatile ObservationRegistryConfigurer configurer; private volatile ObservationRegistryConfigurer configurer;
ObservationRegistryPostProcessor(ObjectProvider<ObservationRegistryCustomizer<?>> observationRegistryCustomizers, ObservationRegistryPostProcessor(ObjectProvider<ObservationRegistryCustomizer<?>> observationRegistryCustomizers,
ObjectProvider<ObservationPredicate> observationPredicates, ObjectProvider<ObservationPredicate> observationPredicates,
ObjectProvider<GlobalObservationConvention<?>> observationConventions, ObjectProvider<GlobalObservationConvention<?>> observationConventions,
ObjectProvider<ObservationHandler<?>> observationHandlers, ObjectProvider<ObservationHandler<?>> observationHandlers,
ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping) { ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping,
ObjectProvider<ObservationFilter> observationFilters) {
this.observationRegistryCustomizers = observationRegistryCustomizers; this.observationRegistryCustomizers = observationRegistryCustomizers;
this.observationPredicates = observationPredicates; this.observationPredicates = observationPredicates;
this.observationConventions = observationConventions; this.observationConventions = observationConventions;
this.observationHandlers = observationHandlers; this.observationHandlers = observationHandlers;
this.observationHandlerGrouping = observationHandlerGrouping; this.observationHandlerGrouping = observationHandlerGrouping;
this.observationFilters = observationFilters;
} }
@Override @Override
@ -70,7 +75,7 @@ class ObservationRegistryPostProcessor implements BeanPostProcessor {
if (this.configurer == null) { if (this.configurer == null) {
this.configurer = new ObservationRegistryConfigurer(this.observationRegistryCustomizers, this.configurer = new ObservationRegistryConfigurer(this.observationRegistryCustomizers,
this.observationPredicates, this.observationConventions, this.observationHandlers, this.observationPredicates, this.observationConventions, this.observationHandlers,
this.observationHandlerGrouping); this.observationHandlerGrouping, this.observationFilters);
} }
return this.configurer; return this.configurer;
} }

@ -28,6 +28,7 @@ import io.micrometer.core.instrument.search.MeterNotFoundException;
import io.micrometer.observation.GlobalObservationConvention; import io.micrometer.observation.GlobalObservationConvention;
import io.micrometer.observation.Observation; import io.micrometer.observation.Observation;
import io.micrometer.observation.Observation.Context; import io.micrometer.observation.Observation.Context;
import io.micrometer.observation.ObservationFilter;
import io.micrometer.observation.ObservationHandler; import io.micrometer.observation.ObservationHandler;
import io.micrometer.observation.ObservationHandler.AllMatchingCompositeObservationHandler; import io.micrometer.observation.ObservationHandler.AllMatchingCompositeObservationHandler;
import io.micrometer.observation.ObservationHandler.FirstMatchingCompositeObservationHandler; import io.micrometer.observation.ObservationHandler.FirstMatchingCompositeObservationHandler;
@ -176,6 +177,16 @@ class ObservationAutoConfigurationTests {
}); });
} }
@Test
void autoConfiguresObservationFilters() {
this.contextRunner.withUserConfiguration(ObservationFilters.class).run((context) -> {
ObservationRegistry observationRegistry = context.getBean(ObservationRegistry.class);
Observation.start("filtered", observationRegistry).stop();
MeterRegistry meterRegistry = context.getBean(MeterRegistry.class);
assertThat(meterRegistry.get("filtered").tag("filter", "one").timer().count()).isOne();
});
}
@Test @Test
void autoConfiguresGlobalObservationConventions() { void autoConfiguresGlobalObservationConventions() {
this.contextRunner.withUserConfiguration(CustomGlobalObservationConvention.class).run((context) -> { this.contextRunner.withUserConfiguration(CustomGlobalObservationConvention.class).run((context) -> {
@ -273,6 +284,23 @@ class ObservationAutoConfigurationTests {
} }
@Configuration(proxyBeanMethods = false)
static class ObservationFilters {
@Bean
@Order(1)
ObservationFilter observationFilterOne() {
return (context) -> context.addLowCardinalityKeyValue(KeyValue.of("filter", "one"));
}
@Bean
@Order(0)
ObservationFilter observationFilterTwo() {
return (context) -> context.addLowCardinalityKeyValue(KeyValue.of("filter", "two"));
}
}
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
static class CustomGlobalObservationConvention { static class CustomGlobalObservationConvention {

Loading…
Cancel
Save