Allow DefaultMeterObservationHandler to be replaced by user's bean
Closes gh-32462 Co-authored-by: Jonatan Ivanov <jonatan.ivanov@gmail.com>pull/31255/head
parent
4a80b36160
commit
78a64d7f61
@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2022 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure.observation;
|
|
||||||
|
|
||||||
import io.micrometer.core.instrument.MeterRegistry;
|
|
||||||
import io.micrometer.core.instrument.observation.DefaultMeterObservationHandler;
|
|
||||||
import io.micrometer.observation.ObservationRegistry;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers the {@link DefaultMeterObservationHandler} with an
|
|
||||||
* {@link ObservationRegistry}.
|
|
||||||
*
|
|
||||||
* @author Moritz Halbritter
|
|
||||||
*/
|
|
||||||
class DefaultMeterObservationHandlerObservationRegistryCustomizer
|
|
||||||
implements ObservationRegistryCustomizer<ObservationRegistry> {
|
|
||||||
|
|
||||||
private final MeterRegistry meterRegistry;
|
|
||||||
|
|
||||||
DefaultMeterObservationHandlerObservationRegistryCustomizer(MeterRegistry meterRegistry) {
|
|
||||||
this.meterRegistry = meterRegistry;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void customize(ObservationRegistry registry) {
|
|
||||||
registry.observationConfig().observationHandler(new DefaultMeterObservationHandler(this.meterRegistry));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012-2022 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.springframework.boot.actuate.autoconfigure.observation;
|
|
||||||
|
|
||||||
import io.micrometer.core.instrument.MeterRegistry;
|
|
||||||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
|
|
||||||
import io.micrometer.observation.Observation;
|
|
||||||
import io.micrometer.observation.ObservationRegistry;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link DefaultMeterObservationHandlerObservationRegistryCustomizer}.
|
|
||||||
*
|
|
||||||
* @author Moritz Halbritter
|
|
||||||
*/
|
|
||||||
class DefaultMeterObservationHandlerObservationRegistryCustomizerTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void customizeInstallsDefaultMeterObservationHandler() {
|
|
||||||
MeterRegistry meterRegistry = new SimpleMeterRegistry();
|
|
||||||
DefaultMeterObservationHandlerObservationRegistryCustomizer sut = new DefaultMeterObservationHandlerObservationRegistryCustomizer(
|
|
||||||
meterRegistry);
|
|
||||||
ObservationRegistry observationRegistry = ObservationRegistry.create();
|
|
||||||
sut.customize(observationRegistry);
|
|
||||||
Observation.start("test-1", observationRegistry).stop();
|
|
||||||
assertThat(meterRegistry.find("test-1").timer().count()).isEqualTo(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue