Skip to content

Commit

Permalink
Merge branch '3.0.x' into 3.1.x
Browse files Browse the repository at this point in the history
Closes gh-37838
  • Loading branch information
wilkinsona committed Oct 12, 2023
2 parents 4115863 + f780cc6 commit 19b877f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.
Expand All @@ -25,6 +25,7 @@
import io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.LazyInitializationExcludeFilter;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfiguration;
Expand All @@ -33,6 +34,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
import org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

Expand Down Expand Up @@ -63,6 +65,11 @@ else if (executor instanceof ThreadPoolTaskScheduler threadPoolTaskScheduler) {
});
}

@Bean
static LazyInitializationExcludeFilter eagerTaskExecutorMetrics() {
return LazyInitializationExcludeFilter.forBeanTypes(TaskExecutorMetricsAutoConfiguration.class);
}

private void monitor(MeterRegistry registry, ThreadPoolExecutor threadPoolExecutor, String name) {
if (threadPoolExecutor != null) {
new ExecutorServiceMetrics(threadPoolExecutor, name, Collections.emptyList()).bindTo(registry);
Expand Down
Expand Up @@ -24,6 +24,7 @@
import io.micrometer.core.instrument.search.MeterNotFoundException;
import org.junit.jupiter.api.Test;

import org.springframework.boot.LazyInitializationBeanFactoryPostProcessor;
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
Expand Down Expand Up @@ -64,6 +65,21 @@ void taskExecutorUsingAutoConfigurationIsInstrumented() {
});
}

@Test
void taskExecutorIsInstrumentedWhenUsingLazyInitialization() {
this.contextRunner.withConfiguration(AutoConfigurations.of(TaskExecutionAutoConfiguration.class))
.withBean(LazyInitializationBeanFactoryPostProcessor.class)
.run((context) -> {
MeterRegistry registry = context.getBean(MeterRegistry.class);
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());
});
}

@Test
void taskExecutorsWithCustomNamesAreInstrumented() {
this.contextRunner.withBean("firstTaskExecutor", Executor.class, ThreadPoolTaskExecutor::new)
Expand Down

0 comments on commit 19b877f

Please sign in to comment.