From f10210f7697602c2727d38f379eee32f5c04cd79 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 11 Jan 2018 13:53:36 +0100 Subject: [PATCH] Make MetricsEndpoint response types public Closes gh-11602 --- .../boot/actuate/metrics/MetricsEndpoint.java | 85 ++++++++++--------- .../actuate/metrics/MetricsEndpointTests.java | 4 +- 2 files changed, 45 insertions(+), 44 deletions(-) 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 746cc25e60..9e068fdaca 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 @@ -92,8 +92,8 @@ public class MetricsEndpoint { Map> availableTags = getAvailableTags(meters); tags.forEach((t) -> availableTags.remove(t.getKey())); return new MetricResponse(requiredMetricName, - asList(samples, MetricResponse.Sample::new), - asList(availableTags, MetricResponse.AvailableTag::new)); + asList(samples, Sample::new), + asList(availableTags, AvailableTag::new)); } private List parseTags(List tags) { @@ -154,7 +154,7 @@ public class MetricsEndpoint { /** * Response payload for a metric name listing. */ - static class ListNamesResponse { + public static final class ListNamesResponse { private final Set names; @@ -170,7 +170,7 @@ public class MetricsEndpoint { /** * Response payload for a metric name selector. */ - static class MetricResponse { + public static final class MetricResponse { private final String name; @@ -197,58 +197,59 @@ public class MetricsEndpoint { return this.availableTags; } - /** - * A set of tags for further dimensional drilldown and their potential values. - */ - static class AvailableTag { + } - private final String tag; + /** + * A set of tags for further dimensional drilldown and their potential values. + */ + public static final class AvailableTag { - private final Set values; + private final String tag; - AvailableTag(String tag, Set values) { - this.tag = tag; - this.values = values; - } + private final Set values; - public String getTag() { - return this.tag; - } - - public Set getValues() { - return this.values; - } + AvailableTag(String tag, Set values) { + this.tag = tag; + this.values = values; } - /** - * A measurement sample combining a {@link Statistic statistic} and a value. - */ - static class Sample { + public String getTag() { + return this.tag; + } - private final Statistic statistic; + public Set getValues() { + return this.values; + } + } - private final Double value; + /** + * A measurement sample combining a {@link Statistic statistic} and a value. + */ + public static final class Sample { - Sample(Statistic statistic, Double value) { - this.statistic = statistic; - this.value = value; - } + private final Statistic statistic; - public Statistic getStatistic() { - return this.statistic; - } + private final Double value; - public Double getValue() { - return this.value; - } + Sample(Statistic statistic, Double value) { + this.statistic = statistic; + this.value = value; + } - @Override - public String toString() { - return "MeasurementSample{" + "statistic=" + this.statistic + ", value=" - + this.value + '}'; - } + public Statistic getStatistic() { + return this.statistic; + } + public Double getValue() { + return this.value; + } + + @Override + public String toString() { + return "MeasurementSample{" + "statistic=" + this.statistic + ", value=" + + this.value + '}'; } } + } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/MetricsEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/MetricsEndpointTests.java index b5784b3f3d..328fde5b06 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/MetricsEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/metrics/MetricsEndpointTests.java @@ -132,12 +132,12 @@ public class MetricsEndpointTests { private Optional getCount(MetricsEndpoint.MetricResponse response) { return response.getMeasurements().stream() .filter((ms) -> ms.getStatistic().equals(Statistic.Count)).findAny() - .map(MetricsEndpoint.MetricResponse.Sample::getValue); + .map(MetricsEndpoint.Sample::getValue); } private Stream availableTagKeys(MetricsEndpoint.MetricResponse response) { return response.getAvailableTags().stream() - .map(MetricsEndpoint.MetricResponse.AvailableTag::getTag); + .map(MetricsEndpoint.AvailableTag::getTag); } }