From 21a0b0544a8ef753d2919621b54eaca64b14e92e Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Sun, 1 Mar 2020 14:02:03 +0900 Subject: [PATCH 1/2] Add descriptions for data source pool metrics See gh-20354 --- .../metrics/jdbc/DataSourcePoolMetrics.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java index 92cf4243b2..3f9a0fb524 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java @@ -22,6 +22,7 @@ import java.util.function.Function; import javax.sql.DataSource; +import io.micrometer.core.instrument.Gauge; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tag; import io.micrometer.core.instrument.Tags; @@ -65,23 +66,27 @@ public class DataSourcePoolMetrics implements MeterBinder { @Override public void bindTo(MeterRegistry registry) { if (this.metadataProvider.getDataSourcePoolMetadata(this.dataSource) != null) { - bindPoolMetadata(registry, "active", DataSourcePoolMetadata::getActive); - bindPoolMetadata(registry, "idle", DataSourcePoolMetadata::getIdle); - bindPoolMetadata(registry, "max", DataSourcePoolMetadata::getMax); - bindPoolMetadata(registry, "min", DataSourcePoolMetadata::getMin); + bindPoolMetadata(registry, "active", DataSourcePoolMetadata::getActive, + "Current number of active connections that have been allocated from the data source."); + bindPoolMetadata(registry, "idle", DataSourcePoolMetadata::getIdle, + "Number of established but idle connections."); + bindPoolMetadata(registry, "max", DataSourcePoolMetadata::getMax, + "Maximum number of active connections that can be allocated at the same time."); + bindPoolMetadata(registry, "min", DataSourcePoolMetadata::getMin, + "Minimum number of idle connections in the pool."); } } private void bindPoolMetadata(MeterRegistry registry, String metricName, - Function function) { - bindDataSource(registry, metricName, this.metadataProvider.getValueFunction(function)); + Function function, String description) { + bindDataSource(registry, metricName, this.metadataProvider.getValueFunction(function), description); } private void bindDataSource(MeterRegistry registry, String metricName, - Function function) { + Function function, String description) { if (function.apply(this.dataSource) != null) { - registry.gauge("jdbc.connections." + metricName, this.tags, this.dataSource, - (m) -> function.apply(m).doubleValue()); + Gauge.builder("jdbc.connections." + metricName, this.dataSource, (m) -> function.apply(m).doubleValue()) + .tags(this.tags).description(description).register(registry); } } From 925756dae15adf48f935cc6fc69890ef23504383 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Sun, 1 Mar 2020 10:59:38 -0500 Subject: [PATCH 2/2] Polish "Add descriptions for data source pool metrics" See gh-20354 --- .../metrics/jdbc/DataSourcePoolMetrics.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java index 3f9a0fb524..3ebdccd0ff 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 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. @@ -66,24 +66,26 @@ public class DataSourcePoolMetrics implements MeterBinder { @Override public void bindTo(MeterRegistry registry) { if (this.metadataProvider.getDataSourcePoolMetadata(this.dataSource) != null) { - bindPoolMetadata(registry, "active", DataSourcePoolMetadata::getActive, - "Current number of active connections that have been allocated from the data source."); - bindPoolMetadata(registry, "idle", DataSourcePoolMetadata::getIdle, - "Number of established but idle connections."); - bindPoolMetadata(registry, "max", DataSourcePoolMetadata::getMax, - "Maximum number of active connections that can be allocated at the same time."); - bindPoolMetadata(registry, "min", DataSourcePoolMetadata::getMin, - "Minimum number of idle connections in the pool."); + bindPoolMetadata(registry, "active", + "Current number of active connections that have been allocated from the data source.", + DataSourcePoolMetadata::getActive); + bindPoolMetadata(registry, "idle", "Number of established but idle connections.", + DataSourcePoolMetadata::getIdle); + bindPoolMetadata(registry, "max", + "Maximum number of active connections that can be allocated at the same time.", + DataSourcePoolMetadata::getMax); + bindPoolMetadata(registry, "min", "Minimum number of idle connections in the pool.", + DataSourcePoolMetadata::getMin); } } - private void bindPoolMetadata(MeterRegistry registry, String metricName, - Function function, String description) { - bindDataSource(registry, metricName, this.metadataProvider.getValueFunction(function), description); + private void bindPoolMetadata(MeterRegistry registry, String metricName, String description, + Function function) { + bindDataSource(registry, metricName, description, this.metadataProvider.getValueFunction(function)); } - private void bindDataSource(MeterRegistry registry, String metricName, - Function function, String description) { + private void bindDataSource(MeterRegistry registry, String metricName, String description, + Function function) { if (function.apply(this.dataSource) != null) { Gauge.builder("jdbc.connections." + metricName, this.dataSource, (m) -> function.apply(m).doubleValue()) .tags(this.tags).description(description).register(registry);