Adapt to breaking API changes in latest Micrometer snapshots

See gh-30800
pull/30825/head
Andy Wilkinson 3 years ago
parent fb16907c0e
commit 6d15e6d4ef

@ -17,6 +17,7 @@
package org.springframework.boot.actuate.autoconfigure.observation;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.observation.Observation.Context;
import io.micrometer.observation.Observation.GlobalKeyValuesProvider;
import io.micrometer.observation.ObservationHandler;
import io.micrometer.observation.ObservationPredicate;
@ -49,7 +50,7 @@ public class ObservationAutoConfiguration {
ObjectProvider<ObservationRegistryCustomizer<?>> observationRegistryCustomizers,
ObjectProvider<ObservationPredicate> observationPredicates,
ObjectProvider<GlobalKeyValuesProvider<?>> tagProviders,
ObjectProvider<ObservationHandler<?>> observationHandlers,
ObjectProvider<ObservationHandler<Context>> observationHandlers,
ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping) {
return new ObservationRegistryPostProcessor(observationRegistryCustomizers, observationPredicates, tagProviders,
observationHandlers, observationHandlerGrouping);

@ -18,6 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.observation;
import java.util.Collection;
import io.micrometer.observation.Observation.Context;
import io.micrometer.observation.ObservationHandler;
import io.micrometer.observation.ObservationRegistry.ObservationConfig;
@ -34,6 +35,6 @@ interface ObservationHandlerGrouping {
* @param handlers the list of observation handlers
* @param config the config to apply the handlers to
*/
void apply(Collection<ObservationHandler<?>> handlers, ObservationConfig config);
void apply(Collection<ObservationHandler<Context>> handlers, ObservationConfig config);
}

@ -18,6 +18,7 @@ package org.springframework.boot.actuate.autoconfigure.observation;
import java.util.List;
import io.micrometer.observation.Observation.Context;
import io.micrometer.observation.Observation.GlobalKeyValuesProvider;
import io.micrometer.observation.ObservationHandler;
import io.micrometer.observation.ObservationPredicate;
@ -44,14 +45,14 @@ class ObservationRegistryConfigurer {
private final ObjectProvider<GlobalKeyValuesProvider<?>> tagProviders;
private final ObjectProvider<ObservationHandler<?>> observationHandlers;
private final ObjectProvider<ObservationHandler<Context>> observationHandlers;
private final ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping;
ObservationRegistryConfigurer(ObjectProvider<ObservationRegistryCustomizer<?>> customizers,
ObjectProvider<ObservationPredicate> observationPredicates,
ObjectProvider<GlobalKeyValuesProvider<?>> tagProviders,
ObjectProvider<ObservationHandler<?>> observationHandlers,
ObjectProvider<ObservationHandler<Context>> observationHandlers,
ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping) {
this.customizers = customizers;
this.observationPredicates = observationPredicates;

@ -16,6 +16,7 @@
package org.springframework.boot.actuate.autoconfigure.observation;
import io.micrometer.observation.Observation.Context;
import io.micrometer.observation.Observation.GlobalKeyValuesProvider;
import io.micrometer.observation.ObservationHandler;
import io.micrometer.observation.ObservationPredicate;
@ -40,7 +41,7 @@ class ObservationRegistryPostProcessor implements BeanPostProcessor {
private final ObjectProvider<GlobalKeyValuesProvider<?>> tagProviders;
private final ObjectProvider<ObservationHandler<?>> observationHandlers;
private final ObjectProvider<ObservationHandler<Context>> observationHandlers;
private final ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping;
@ -49,7 +50,7 @@ class ObservationRegistryPostProcessor implements BeanPostProcessor {
ObservationRegistryPostProcessor(ObjectProvider<ObservationRegistryCustomizer<?>> observationRegistryCustomizers,
ObjectProvider<ObservationPredicate> observationPredicates,
ObjectProvider<GlobalKeyValuesProvider<?>> tagProviders,
ObjectProvider<ObservationHandler<?>> observationHandlers,
ObjectProvider<ObservationHandler<Context>> observationHandlers,
ObjectProvider<ObservationHandlerGrouping> observationHandlerGrouping) {
this.observationRegistryCustomizers = observationRegistryCustomizers;
this.observationPredicates = observationPredicates;

@ -21,6 +21,7 @@ import java.util.Collection;
import java.util.List;
import io.micrometer.core.instrument.observation.MeterObservationHandler;
import io.micrometer.observation.Observation.Context;
import io.micrometer.observation.ObservationHandler;
import io.micrometer.observation.ObservationHandler.FirstMatchingCompositeObservationHandler;
import io.micrometer.observation.ObservationRegistry.ObservationConfig;
@ -38,9 +39,9 @@ import io.micrometer.observation.ObservationRegistry.ObservationConfig;
class OnlyMetricsObservationHandlerGrouping implements ObservationHandlerGrouping {
@Override
public void apply(Collection<ObservationHandler<?>> handlers, ObservationConfig config) {
List<ObservationHandler<?>> meterObservationHandlers = new ArrayList<>();
for (ObservationHandler<?> handler : handlers) {
public void apply(Collection<ObservationHandler<Context>> handlers, ObservationConfig config) {
List<ObservationHandler<Context>> meterObservationHandlers = new ArrayList<>();
for (ObservationHandler<Context> handler : handlers) {
if (handler instanceof MeterObservationHandler<?>) {
meterObservationHandlers.add(handler);
}
@ -50,15 +51,8 @@ class OnlyMetricsObservationHandlerGrouping implements ObservationHandlerGroupin
}
if (!meterObservationHandlers.isEmpty()) {
config.observationHandler(
new FirstMatchingCompositeObservationHandler(castToRawType(meterObservationHandlers)));
config.observationHandler(new FirstMatchingCompositeObservationHandler(meterObservationHandlers));
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private List<ObservationHandler> castToRawType(List<ObservationHandler<?>> handlers) {
// See https://github.com/micrometer-metrics/micrometer/issues/3064
return (List) handlers;
}
}

@ -21,6 +21,7 @@ import java.util.Collection;
import java.util.List;
import io.micrometer.core.instrument.observation.MeterObservationHandler;
import io.micrometer.observation.Observation.Context;
import io.micrometer.observation.ObservationHandler;
import io.micrometer.observation.ObservationHandler.FirstMatchingCompositeObservationHandler;
import io.micrometer.observation.ObservationRegistry.ObservationConfig;
@ -41,10 +42,10 @@ import io.micrometer.tracing.handler.TracingObservationHandler;
class TracingObservationHandlerGrouping implements ObservationHandlerGrouping {
@Override
public void apply(Collection<ObservationHandler<?>> handlers, ObservationConfig config) {
List<ObservationHandler<?>> meterObservationHandlers = new ArrayList<>();
List<ObservationHandler<?>> tracingObservationHandlers = new ArrayList<>();
for (ObservationHandler<?> handler : handlers) {
public void apply(Collection<ObservationHandler<Context>> handlers, ObservationConfig config) {
List<ObservationHandler<Context>> meterObservationHandlers = new ArrayList<>();
List<ObservationHandler<Context>> tracingObservationHandlers = new ArrayList<>();
for (ObservationHandler<Context> handler : handlers) {
if (handler instanceof MeterObservationHandler<?>) {
meterObservationHandlers.add(handler);
}
@ -57,19 +58,11 @@ class TracingObservationHandlerGrouping implements ObservationHandlerGrouping {
}
if (!meterObservationHandlers.isEmpty()) {
config.observationHandler(
new FirstMatchingCompositeObservationHandler(castToRawType(meterObservationHandlers)));
config.observationHandler(new FirstMatchingCompositeObservationHandler(meterObservationHandlers));
}
if (!tracingObservationHandlers.isEmpty()) {
config.observationHandler(
new FirstMatchingCompositeObservationHandler(castToRawType(tracingObservationHandlers)));
config.observationHandler(new FirstMatchingCompositeObservationHandler(tracingObservationHandlers));
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private List<ObservationHandler> castToRawType(List<ObservationHandler<?>> handlers) {
// See https://github.com/micrometer-metrics/micrometer/issues/3064
return (List) handlers;
}
}

Loading…
Cancel
Save