Skip to content

Commit

Permalink
Avoid exposing time-related task metrics
Browse files Browse the repository at this point in the history
Fixes gh-28535
  • Loading branch information
scottfrederick committed Nov 15, 2021
1 parent d7f8931 commit 8903c69
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Expand Up @@ -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;
Expand Down Expand Up @@ -66,7 +67,7 @@ else if (executor instanceof ThreadPoolTaskScheduler) {

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);
}
}

Expand Down
Expand Up @@ -21,6 +21,7 @@

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;
Expand All @@ -34,6 +35,7 @@
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;

Expand All @@ -56,6 +58,8 @@ void taskExecutorUsingAutoConfigurationIsInstrumented() {
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());
});
}

Expand Down Expand Up @@ -101,6 +105,8 @@ void taskSchedulerUsingAutoConfigurationIsInstrumented() {
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());
});
}

Expand Down

0 comments on commit 8903c69

Please sign in to comment.