diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-09-08 22:43:35 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-09-08 22:43:35 +0200 |
commit | ad1456aa6f3f577cf03087655f317be3bb562c2c (patch) | |
tree | ef46cddea4527a2cfce8e3c99569f8e9784bd9b1 /metrics-proxy/src/main/java/ai/vespa/metricsproxy/core/VespaMetrics.java | |
parent | 66e16f6740f3893fa68c9209b62de97cf157d529 (diff) |
Instead of creatin a new Set of consumers every time, just keep an unmidifiable set that can be used directly. Saves both memory and space.
Diffstat (limited to 'metrics-proxy/src/main/java/ai/vespa/metricsproxy/core/VespaMetrics.java')
-rw-r--r-- | metrics-proxy/src/main/java/ai/vespa/metricsproxy/core/VespaMetrics.java | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/core/VespaMetrics.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/core/VespaMetrics.java index 0c83d8f73c4..3fc2bb316a1 100644 --- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/core/VespaMetrics.java +++ b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/core/VespaMetrics.java @@ -68,7 +68,7 @@ public class VespaMetrics { public List<MetricsPacket.Builder> getMetrics(List<VespaService> services) { List<MetricsPacket.Builder> metricsPackets = new ArrayList<>(); - Map<ConfiguredMetric, List<ConsumerId>> consumersByMetric = metricsConsumers.getConsumersByMetric(); + Map<ConfiguredMetric, Set<ConsumerId>> consumersByMetric = metricsConsumers.getConsumersByMetric(); for (VespaService service : services) { // One metrics packet for system metrics @@ -119,7 +119,7 @@ public class VespaMetrics { * In order to include a metric, it must exist in the given map of metric to consumers. * Each returned metric will contain a collection of consumers that it should be routed to. */ - private Metrics getServiceMetrics(Metrics allServiceMetrics, Map<ConfiguredMetric, List<ConsumerId>> consumersByMetric) { + private Metrics getServiceMetrics(Metrics allServiceMetrics, Map<ConfiguredMetric, Set<ConsumerId>> consumersByMetric) { Metrics configuredServiceMetrics = new Metrics(); configuredServiceMetrics.setTimeStamp(getMostRecentTimestamp(allServiceMetrics)); for (Metric candidate : allServiceMetrics.getMetrics()) { @@ -139,21 +139,17 @@ public class VespaMetrics { return dimensions; } - private Set<ConsumerId> extractConsumers(List<ConsumerId> configuredConsumers) { + private Set<ConsumerId> extractConsumers(Set<ConsumerId> configuredConsumers) { Set<ConsumerId> consumers = Collections.emptySet(); if (configuredConsumers != null) { - if ( configuredConsumers.size() == 1) { - consumers = Collections.singleton(configuredConsumers.get(0)); - } else if (configuredConsumers.size() > 1){ - consumers = Set.copyOf(configuredConsumers); - } + consumers = configuredConsumers; } return consumers; } private Metric metricWithConfigProperties(Metric candidate, ConfiguredMetric configuredMetric, - Map<ConfiguredMetric, List<ConsumerId>> consumersByMetric) { + Map<ConfiguredMetric, Set<ConsumerId>> consumersByMetric) { Metric metric = candidate.clone(); metric.setDimensions(extractDimensions(candidate.getDimensions(), configuredMetric.dimension())); metric.setConsumers(extractConsumers(consumersByMetric.get(configuredMetric))); |