|
|
@ -54,19 +54,16 @@ public class DataSourcePoolMetricsAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void autoConfiguredDataSourceIsInstrumented() {
|
|
|
|
public void autoConfiguredDataSourceIsInstrumented() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
context.getBean(DataSource.class).getConnection().getMetaData();
|
|
|
|
context.getBean(DataSource.class).getConnection().getMetaData();
|
|
|
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
|
|
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
|
|
|
registry.get("jdbc.connections.max").tags("name", "dataSource").meter();
|
|
|
|
registry.get("jdbc.connections.max").tags("name", "dataSource")
|
|
|
|
});
|
|
|
|
.meter();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void dataSourceInstrumentationCanBeDisabled() {
|
|
|
|
public void dataSourceInstrumentationCanBeDisabled() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.withPropertyValues("management.metrics.enable.jdbc=false")
|
|
|
|
.withPropertyValues("management.metrics.enable.jdbc=false")
|
|
|
|
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
context.getBean(DataSource.class).getConnection().getMetaData();
|
|
|
|
context.getBean(DataSource.class).getConnection().getMetaData();
|
|
|
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
|
|
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
|
|
@ -92,23 +89,20 @@ public class DataSourcePoolMetricsAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void autoConfiguredHikariDataSourceIsInstrumented() {
|
|
|
|
public void autoConfiguredHikariDataSourceIsInstrumented() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
context.getBean(DataSource.class).getConnection();
|
|
|
|
context.getBean(DataSource.class).getConnection();
|
|
|
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
|
|
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
|
|
|
registry.get("hikaricp.connections").meter();
|
|
|
|
registry.get("hikaricp.connections").meter();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void hikariDataSourceInstrumentationCanBeDisabled() {
|
|
|
|
public void hikariDataSourceInstrumentationCanBeDisabled() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.withPropertyValues("management.metrics.enable.hikaricp=false")
|
|
|
|
.withPropertyValues("management.metrics.enable.hikaricp=false")
|
|
|
|
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
context.getBean(DataSource.class).getConnection();
|
|
|
|
context.getBean(DataSource.class).getConnection();
|
|
|
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
|
|
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
|
|
|
assertThat(registry.find("hikaricp.connections").meter())
|
|
|
|
assertThat(registry.find("hikaricp.connections").meter()).isNull();
|
|
|
|
.isNull();
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -135,7 +129,7 @@ public class DataSourcePoolMetricsAutoConfigurationTests {
|
|
|
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
|
|
|
MeterRegistry registry = context.getBean(MeterRegistry.class);
|
|
|
|
assertThat(registry.get("hikaricp.connections").meter().getId()
|
|
|
|
assertThat(registry.get("hikaricp.connections").meter().getId()
|
|
|
|
.getTags())
|
|
|
|
.getTags())
|
|
|
|
.containsExactly(Tag.of("pool", "firstDataSource"));
|
|
|
|
.containsExactly(Tag.of("pool", "firstDataSource"));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -215,8 +209,7 @@ public class DataSourcePoolMetricsAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
private org.apache.tomcat.jdbc.pool.DataSource createTomcatDataSource() {
|
|
|
|
private org.apache.tomcat.jdbc.pool.DataSource createTomcatDataSource() {
|
|
|
|
String url = "jdbc:hsqldb:mem:test-" + UUID.randomUUID();
|
|
|
|
String url = "jdbc:hsqldb:mem:test-" + UUID.randomUUID();
|
|
|
|
return DataSourceBuilder
|
|
|
|
return DataSourceBuilder.create().url(url)
|
|
|
|
.create().url(url)
|
|
|
|
|
|
|
|
.type(org.apache.tomcat.jdbc.pool.DataSource.class).build();
|
|
|
|
.type(org.apache.tomcat.jdbc.pool.DataSource.class).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|