Skip to content

Commit 1ec1692

Browse files
committed
Merge pull request #13813 from joshiste:issue-13791
* pr/13813: Polish "Add metric description and base unit to metrics endpoint" Add metric description and base unit to metrics endpoint
2 parents a7b13db + 7176c54 commit 1ec1692

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/MetricsEndpointDocumentationTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public void metric() throws Exception {
5454
.andExpect(status().isOk())
5555
.andDo(document("metrics/metric", responseFields(
5656
fieldWithPath("name").description("Name of the metric"),
57+
fieldWithPath("description")
58+
.description("Description of the metric"),
59+
fieldWithPath("baseUnit").description("Base unit of the metric"),
5760
fieldWithPath("measurements")
5861
.description("Measurements of the metric"),
5962
fieldWithPath("measurements[].statistic")

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/MetricsEndpoint.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ public MetricResponse metric(@Selector String requiredMetricName,
9191
Map<Statistic, Double> samples = getSamples(meters);
9292
Map<String, Set<String>> availableTags = getAvailableTags(meters);
9393
tags.forEach((t) -> availableTags.remove(t.getKey()));
94-
return new MetricResponse(requiredMetricName, asList(samples, Sample::new),
94+
Meter.Id meterId = meters.get(0).getId();
95+
return new MetricResponse(requiredMetricName, meterId.getDescription(),
96+
meterId.getBaseUnit(), asList(samples, Sample::new),
9597
asList(availableTags, AvailableTag::new));
9698
}
9799

@@ -183,13 +185,19 @@ public static final class MetricResponse {
183185

184186
private final String name;
185187

188+
private final String description;
189+
190+
private final String baseUnit;
191+
186192
private final List<Sample> measurements;
187193

188194
private final List<AvailableTag> availableTags;
189195

190-
MetricResponse(String name, List<Sample> measurements,
191-
List<AvailableTag> availableTags) {
196+
MetricResponse(String name, String description, String baseUnit,
197+
List<Sample> measurements, List<AvailableTag> availableTags) {
192198
this.name = name;
199+
this.description = description;
200+
this.baseUnit = baseUnit;
193201
this.measurements = measurements;
194202
this.availableTags = availableTags;
195203
}
@@ -198,6 +206,14 @@ public String getName() {
198206
return this.name;
199207
}
200208

209+
public String getDescription() {
210+
return this.description;
211+
}
212+
213+
public String getBaseUnit() {
214+
return this.baseUnit;
215+
}
216+
201217
public List<Sample> getMeasurements() {
202218
return this.measurements;
203219
}

0 commit comments

Comments
 (0)