In #23818 support for Task Execution and Scheduling Metrics was added..
In it the name for the "executorServiceName" of the auto registered ThreadPoolTaskExecutor
and ThreadPoolTaskScheduler
is identitcal ("application"). This means that the only the metrics of one executor are used.
Here is an example test cases demonstrating the problem.
@Test
void taskSchedulerAndThreadPoolUsingAutoConfigurationAreInstrumented() {
this.contextRunner.withConfiguration(AutoConfigurations.of(TaskSchedulingAutoConfiguration.class, TaskExecutionAutoConfiguration.class))
.withPropertyValues(
"spring.task.execution.pool.max-size=10"
)
.withUserConfiguration(SchedulingTestConfiguration.class).run((context) -> {
MeterRegistry registry = context.getBean(MeterRegistry.class);
Collection<Gauge> meters = registry.get("executor.pool.max").gauges();
assertThat(meters)
.extracting(Gauge::value)
.containsExactlyInAnyOrder(Double.valueOf(10), Double.valueOf(Integer.MAX_VALUE));
});
}
The same problem will occur when I register my own custom beans.
e.g. when I have myCustomTaskScheduler
and myCustomTaskExecutor
then only the value of one of them will be monitored.
I noticed this because we have our own metrics, that are slightly different then the ones configured here and I was trying to adapt our usage to use MeterFilter
in order to rely on the Spring Boot auto configuration.