diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MetricsEndpointDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MetricsEndpointDocumentationTests.java index 604e052db7d6..5e57f74e6d75 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MetricsEndpointDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MetricsEndpointDocumentationTests.java @@ -54,6 +54,8 @@ public void metric() throws Exception { .andExpect(status().isOk()) .andDo(document("metrics/metric", responseFields( fieldWithPath("name").description("Name of the metric"), + fieldWithPath("description").description("Description of the metric"), + fieldWithPath("baseUnit").description("Base unit of the metric"), fieldWithPath("measurements") .description("Measurements of the metric"), fieldWithPath("measurements[].statistic") diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsEndpoint.java index c7055c3294d2..a80f1ae3ea9c 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsEndpoint.java @@ -91,7 +91,9 @@ public MetricResponse metric(@Selector String requiredMetricName, Map samples = getSamples(meters); Map> availableTags = getAvailableTags(meters); tags.forEach((t) -> availableTags.remove(t.getKey())); - return new MetricResponse(requiredMetricName, asList(samples, Sample::new), + Meter.Id meterId = meters.get(0).getId(); + return new MetricResponse(requiredMetricName, meterId.getDescription(), + meterId.getBaseUnit(), asList(samples, Sample::new), asList(availableTags, AvailableTag::new)); } @@ -183,13 +185,19 @@ public static final class MetricResponse { private final String name; + private final String description; + + private final String baseUnit; + private final List measurements; private final List availableTags; - MetricResponse(String name, List measurements, - List availableTags) { + MetricResponse(String name, String description, String baseUnit, + List measurements, List availableTags) { this.name = name; + this.description = description; + this.baseUnit = baseUnit; this.measurements = measurements; this.availableTags = availableTags; } @@ -198,6 +206,14 @@ public String getName() { return this.name; } + public String getDescription() { + return this.description; + } + + public String getBaseUnit() { + return this.baseUnit; + } + public List getMeasurements() { return this.measurements; }