Search in sources :

Example 96 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project spring-boot by spring-projects.

the class TaskExecutorMetricsAutoConfigurationTests method taskSchedulerInstrumentationCanBeDisabled.

@Test
void taskSchedulerInstrumentationCanBeDisabled() {
    this.contextRunner.withPropertyValues("management.metrics.enable.executor=false").withConfiguration(AutoConfigurations.of(TaskSchedulingAutoConfiguration.class)).withUserConfiguration(SchedulingTestConfiguration.class).run((context) -> {
        MeterRegistry registry = context.getBean(MeterRegistry.class);
        assertThat(registry.find("executor.completed").tags("name", "taskScheduler").functionCounter()).isNull();
    });
}
Also used : TaskSchedulingAutoConfiguration(org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 97 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project spring-boot by spring-projects.

the class TaskExecutorMetricsAutoConfigurationTests method taskSchedulerUsingAutoConfigurationIsInstrumented.

@Test
void taskSchedulerUsingAutoConfigurationIsInstrumented() {
    this.contextRunner.withConfiguration(AutoConfigurations.of(TaskSchedulingAutoConfiguration.class)).withUserConfiguration(SchedulingTestConfiguration.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("taskScheduler"));
        assertThatExceptionOfType(MeterNotFoundException.class).isThrownBy(() -> registry.get("executor").timer());
    });
}
Also used : MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) TaskSchedulingAutoConfiguration(org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration) FunctionCounter(io.micrometer.core.instrument.FunctionCounter) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 98 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project spring-boot by spring-projects.

the class TaskExecutorMetricsAutoConfigurationTests method threadPoolTaskExecutorWithNoTaskExecutorIsIgnored.

@Test
void threadPoolTaskExecutorWithNoTaskExecutorIsIgnored() {
    ThreadPoolTaskExecutor unavailableTaskExecutor = mock(ThreadPoolTaskExecutor.class);
    given(unavailableTaskExecutor.getThreadPoolExecutor()).willThrow(new IllegalStateException("Test"));
    this.contextRunner.withBean("firstTaskExecutor", ThreadPoolTaskExecutor.class, ThreadPoolTaskExecutor::new).withBean("customName", ThreadPoolTaskExecutor.class, () -> unavailableTaskExecutor).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("firstTaskExecutor"));
    });
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) FunctionCounter(io.micrometer.core.instrument.FunctionCounter) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 99 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project spring-boot by spring-projects.

the class TaskExecutorMetricsAutoConfigurationTests method taskSchedulersWithCustomNamesAreInstrumented.

@Test
void taskSchedulersWithCustomNamesAreInstrumented() {
    this.contextRunner.withBean("firstTaskScheduler", Executor.class, ThreadPoolTaskScheduler::new).withBean("customName", ThreadPoolTaskScheduler.class, ThreadPoolTaskScheduler::new).run((context) -> {
        MeterRegistry registry = context.getBean(MeterRegistry.class);
        Collection<FunctionCounter> meters = registry.get("executor.completed").functionCounters();
        assertThat(meters).map((meter) -> meter.getId().getTag("name")).containsExactlyInAnyOrder("firstTaskScheduler", "customName");
    });
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) AutoConfigurations(org.springframework.boot.autoconfigure.AutoConfigurations) TaskExecutionAutoConfiguration(org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration) MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) Executor(java.util.concurrent.Executor) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MetricsRun(org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Test(org.junit.jupiter.api.Test) TaskSchedulingAutoConfiguration(org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration) Configuration(org.springframework.context.annotation.Configuration) BDDMockito.given(org.mockito.BDDMockito.given) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) FunctionCounter(io.micrometer.core.instrument.FunctionCounter) EnableScheduling(org.springframework.scheduling.annotation.EnableScheduling) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Mockito.mock(org.mockito.Mockito.mock) FunctionCounter(io.micrometer.core.instrument.FunctionCounter) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 100 with MeterRegistry

use of io.micrometer.core.instrument.MeterRegistry in project spring-boot by spring-projects.

the class DataSourcePoolMetricsAutoConfigurationTests method autoConfiguredHikariDataSourceIsInstrumented.

@Test
void autoConfiguredHikariDataSourceIsInstrumented() {
    this.contextRunner.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class)).run((context) -> {
        context.getBean(DataSource.class).getConnection();
        MeterRegistry registry = context.getBean(MeterRegistry.class);
        registry.get("hikaricp.connections").meter();
    });
}
Also used : DelegatingDataSource(org.springframework.jdbc.datasource.DelegatingDataSource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) DataSource(javax.sql.DataSource) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Aggregations

MeterRegistry (io.micrometer.core.instrument.MeterRegistry)136 Test (org.junit.jupiter.api.Test)83 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)60 CompositeMeterRegistry (io.micrometer.core.instrument.composite.CompositeMeterRegistry)17 Timer (io.micrometer.core.instrument.Timer)15 Test (org.junit.Test)15 PrometheusMeterRegistry (io.micrometer.prometheus.PrometheusMeterRegistry)12 Duration (java.time.Duration)11 ApplicationContextRunner (org.springframework.boot.test.context.runner.ApplicationContextRunner)10 HikariDataSource (com.zaxxer.hikari.HikariDataSource)9 DataSource (javax.sql.DataSource)9 DelegatingDataSource (org.springframework.jdbc.datasource.DelegatingDataSource)9 SampleConfig (io.micrometer.core.samples.utils.SampleConfig)8 Match (io.vertx.micrometer.Match)8 FunctionCounter (io.micrometer.core.instrument.FunctionCounter)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Normal (cern.jet.random.Normal)6 MersenneTwister64 (cern.jet.random.engine.MersenneTwister64)6 RandomEngine (cern.jet.random.engine.RandomEngine)6 Gauge (io.micrometer.core.instrument.Gauge)6