Search in sources :

Example 91 with MeterRegistry

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

the class ConnectionPoolMetricsAutoConfigurationTests method allConnectionPoolsCanBeInstrumented.

@Test
void allConnectionPoolsCanBeInstrumented() {
    this.contextRunner.withUserConfiguration(TwoConnectionPoolsConfiguration.class).run((context) -> {
        MeterRegistry registry = context.getBean(MeterRegistry.class);
        assertThat(registry.find("r2dbc.pool.acquired").gauges()).extracting(Meter::getId).extracting((id) -> id.getTag("name")).containsExactlyInAnyOrder("firstPool", "secondPool");
    });
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) AutoConfigurations(org.springframework.boot.autoconfigure.AutoConfigurations) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MetricsRun(org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun) H2ConnectionOption(io.r2dbc.h2.H2ConnectionOption) ConnectionPoolConfiguration(io.r2dbc.pool.ConnectionPoolConfiguration) Meter(io.micrometer.core.instrument.Meter) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) UUID(java.util.UUID) ConnectionPool(io.r2dbc.pool.ConnectionPool) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) H2ConnectionFactory(io.r2dbc.h2.H2ConnectionFactory) R2dbcAutoConfiguration(org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) CloseableConnectionFactory(io.r2dbc.h2.CloseableConnectionFactory) Meter(io.micrometer.core.instrument.Meter) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 92 with MeterRegistry

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

the class WebClientMetricsConfigurationTests method getInitializedMeterRegistry.

private MeterRegistry getInitializedMeterRegistry(AssertableApplicationContext context) {
    WebClient webClient = mockWebClient(context.getBean(WebClient.Builder.class));
    MeterRegistry registry = context.getBean(MeterRegistry.class);
    for (int i = 0; i < 3; i++) {
        webClient.get().uri("https://example.org/projects/" + i).retrieve().toBodilessEntity().block(Duration.ofSeconds(30));
    }
    return registry;
}
Also used : WebClient(org.springframework.web.reactive.function.client.WebClient) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 93 with MeterRegistry

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

the class WebClientMetricsConfigurationTests method autoTimeRequestsCanBeConfigured.

@Test
void autoTimeRequestsCanBeConfigured() {
    this.contextRunner.withPropertyValues("management.metrics.web.client.request.autotime.enabled=true", "management.metrics.web.client.request.autotime.percentiles=0.5,0.7", "management.metrics.web.client.request.autotime.percentiles-histogram=true").run((context) -> {
        MeterRegistry registry = getInitializedMeterRegistry(context);
        Timer timer = registry.get("http.client.requests").timer();
        HistogramSnapshot snapshot = timer.takeSnapshot();
        assertThat(snapshot.percentileValues()).hasSize(2);
        assertThat(snapshot.percentileValues()[0].percentile()).isEqualTo(0.5);
        assertThat(snapshot.percentileValues()[1].percentile()).isEqualTo(0.7);
    });
}
Also used : Timer(io.micrometer.core.instrument.Timer) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) HistogramSnapshot(io.micrometer.core.instrument.distribution.HistogramSnapshot) Test(org.junit.jupiter.api.Test)

Example 94 with MeterRegistry

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

the class TaskExecutorMetricsAutoConfigurationTests method taskExecutorUsingAutoConfigurationIsInstrumented.

@Test
void taskExecutorUsingAutoConfigurationIsInstrumented() {
    this.contextRunner.withConfiguration(AutoConfigurations.of(TaskExecutionAutoConfiguration.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());
    });
}
Also used : MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) FunctionCounter(io.micrometer.core.instrument.FunctionCounter) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 95 with MeterRegistry

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

the class TaskExecutorMetricsAutoConfigurationTests method taskExecutorInstrumentationCanBeDisabled.

@Test
void taskExecutorInstrumentationCanBeDisabled() {
    this.contextRunner.withPropertyValues("management.metrics.enable.executor=false").withConfiguration(AutoConfigurations.of(TaskExecutionAutoConfiguration.class)).run((context) -> {
        MeterRegistry registry = context.getBean(MeterRegistry.class);
        assertThat(registry.find("executor.completed").tags("name", "applicationTaskExecutor").functionCounter()).isNull();
    });
}
Also used : 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