From 5baedf92750ddc04b635dcf348580f5d1eccbc07 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 5 Jan 2018 13:41:49 +0100 Subject: [PATCH] Polish "Deduplicate tag values in metrics actuator endpoint" Closes gh-11492 --- .../boot/actuate/metrics/MetricsEndpoint.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 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 151a80a8dd..3188537336 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -16,6 +16,11 @@ package org.springframework.boot.actuate.metrics; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -62,7 +67,8 @@ public class MetricsEndpoint { if (registry instanceof CompositeMeterRegistry) { ((CompositeMeterRegistry) registry).getRegistries() .forEach((member) -> collectNames(names, member)); - } else { + } + else { registry.getMeters().stream().map(this::getName).forEach(names::add); } } @@ -102,7 +108,8 @@ public class MetricsEndpoint { if (registry instanceof CompositeMeterRegistry) { ((CompositeMeterRegistry) registry).getRegistries() .forEach((member) -> collectMeters(meters, member, name, tags)); - } else { + } + else { meters.addAll(registry.find(name).tags(tags).meters()); } } @@ -124,7 +131,7 @@ public class MetricsEndpoint { return availableTags; } - private void mergeAvailableTags(Map> availableTags, + private void mergeAvailableTags(Map> availableTags, Meter meter) { meter.getId().getTags().forEach((tag) -> { Set value = Collections.singleton(tag.getValue());