Avoid exposing time-related task metrics

Fixes gh-28535
pull/29081/head
Scott Frederick 3 years ago
parent d7f8931dd4
commit 8903c69b19

@ -16,6 +16,7 @@
package org.springframework.boot.actuate.autoconfigure.metrics.task;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
@ -66,7 +67,7 @@ public class TaskExecutorMetricsAutoConfiguration {
private void monitor(MeterRegistry registry, ThreadPoolExecutor threadPoolExecutor, String name) {
if (threadPoolExecutor != null) {
ExecutorServiceMetrics.monitor(registry, threadPoolExecutor, name);
new ExecutorServiceMetrics(threadPoolExecutor, name, Collections.emptyList()).bindTo(registry);
}
}

@ -21,6 +21,7 @@ import java.util.concurrent.Executor;
import io.micrometer.core.instrument.FunctionCounter;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.search.MeterNotFoundException;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
@ -34,6 +35,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@ -56,6 +58,8 @@ class TaskExecutorMetricsAutoConfigurationTests {
Collection<FunctionCounter> meters = registry.get("executor.completed").functionCounters();
assertThat(meters).singleElement().satisfies(
(meter) -> assertThat(meter.getId().getTag("name")).isEqualTo("applicationTaskExecutor"));
assertThatExceptionOfType(MeterNotFoundException.class)
.isThrownBy(() -> registry.get("executor").timer());
});
}
@ -101,6 +105,8 @@ class TaskExecutorMetricsAutoConfigurationTests {
Collection<FunctionCounter> meters = registry.get("executor.completed").functionCounters();
assertThat(meters).singleElement()
.satisfies((meter) -> assertThat(meter.getId().getTag("name")).isEqualTo("taskScheduler"));
assertThatExceptionOfType(MeterNotFoundException.class)
.isThrownBy(() -> registry.get("executor").timer());
});
}

Loading…
Cancel
Save