diff options
author | Morten Tokle <mortent@verizonmedia.com> | 2020-06-07 21:20:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-07 21:20:50 +0200 |
commit | c6696dd4623ae421d557558fe8ac24e31dffd621 (patch) | |
tree | 1da3189429e5c4fd816b7261031ba1000c259a96 | |
parent | 4368171fdc096a02e76e7d88000fccdf46b2d540 (diff) | |
parent | 993f5f8e5f51bdc92c205a3544bb3f926f211bef (diff) |
Merge pull request #13487 from vespa-engine/mortent/remove-metric-impl
Remove unused metric implementation
7 files changed, 2 insertions, 319 deletions
diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Deployment.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Deployment.java index 8327916b41d..7d7b2f74981 100644 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Deployment.java +++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Deployment.java @@ -2,7 +2,7 @@ package ai.vespa.hosted.cd; /** - * A deployment of a Vespa application, which contains endpoints for document and metrics retrieval. + * A deployment of a Vespa application, which contains endpoints for document retrieval. * * @author jonmv */ diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java index 46f5f8ef5fd..bd6f30767f2 100644 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java +++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java @@ -2,7 +2,6 @@ package ai.vespa.hosted.cd; import ai.vespa.hosted.api.EndpointAuthenticator; -import ai.vespa.hosted.cd.metric.Metrics; import java.net.URI; import java.net.http.HttpClient; @@ -17,7 +16,7 @@ import static java.net.URLEncoder.encode; import static java.nio.charset.StandardCharsets.UTF_8; /** - * An endpoint in a Vespa application {@link Deployment}, which allows document and metrics retrieval. + * An endpoint in a Vespa application {@link Deployment}, which allows document retrieval. * * @author jonmv */ diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Metric.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Metric.java deleted file mode 100644 index 39e9cd5bc75..00000000000 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Metric.java +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package ai.vespa.hosted.cd.metric; - -import java.util.HashMap; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Set; -import java.util.StringJoiner; - -import static java.util.Map.copyOf; -import static java.util.stream.Collectors.reducing; -import static java.util.stream.Collectors.toUnmodifiableMap; - -/** - * A set of statistics for a metric, for points over a space with named dimensions of arbitrary type. - * - * @author jonmv - */ -public class Metric { - - private final Map<Map<String, ?>, Statistic> statistics; - - private Metric(Map<Map<String, ?>, Statistic> statistics) { - this.statistics = statistics; - } - - /** Creates a new Metric with a copy of the given data. */ - public static Metric of(Map<Map<String, ?>, Statistic> data) { - if (data.isEmpty()) - throw new IllegalArgumentException("No data given."); - - Map<Map<String, ?>, Statistic> copies = new HashMap<>(); - Set<String> dimensions = data.keySet().iterator().next().keySet(); - data.forEach((point, statistic) -> { - if ( ! point.keySet().equals(dimensions)) - throw new IllegalArgumentException("Given data has inconsistent dimensions: '" + dimensions + "' vs '" + point.keySet() + "'."); - - copies.put(copyOf(point), statistic); - }); - - return new Metric(copyOf(copies)); - } - - /** Returns a Metric view of the subset of points in the given hyperplane; its dimensions must be a subset of those of this Metric. */ - public Metric at(Map<String, ?> hyperplane) { - return new Metric(statistics.keySet().stream() - .filter(point -> point.entrySet().containsAll(hyperplane.entrySet())) - .collect(toUnmodifiableMap(point -> point, statistics::get))); - } - - /** Returns a version of this where statistics along the given hyperspace are aggregated. This does not preserve last, 95 and 99 percentile values. */ - public Metric collapse(Set<String> hyperspace) { - return new Metric(statistics.keySet().stream() - .collect(toUnmodifiableMap(point -> point.keySet().stream() - .filter(dimension -> ! hyperspace.contains(dimension)) - .collect(toUnmodifiableMap(dimension -> dimension, point::get)), - statistics::get, - Statistic::mergedWith))); - } - - /** Returns a collapsed version of this, with all statistics aggregated. This does not preserve last, 95 and 99 percentile values. */ - public Metric collapse() { - Map<String, ?> firstStatistic = statistics.keySet().iterator().next(); - return firstStatistic == null ? this : collapse(firstStatistic.keySet()); - } - - /** If this Metric contains a single point, returns the Statistic of that point; otherwise, throws an exception. */ - public Statistic statistic() { - if (statistics.size() == 1) - return statistics.values().iterator().next(); - - if (statistics.isEmpty()) - throw new NoSuchElementException("This Metric has no data."); - - throw new IllegalStateException("This Metric has more than one point of data."); - } - - /** Returns the underlying, unmodifiable Map. */ - public Map<Map<String, ?>, Statistic> asMap() { - return statistics; - } - - @Override - public String toString() { - return new StringJoiner(", ", Metric.class.getSimpleName() + "[", "]") - .add("statistics=" + statistics) - .toString(); - } - -} diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Metrics.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Metrics.java deleted file mode 100644 index bdcfac2529e..00000000000 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Metrics.java +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package ai.vespa.hosted.cd.metric; - -import ai.vespa.hosted.cd.Endpoint; - -import java.time.Instant; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.StringJoiner; - -import static java.util.Map.copyOf; - -/** - * Metrics from a Vespa application {@link Endpoint}, indexed by their names, and optionally by a set of custom dimensions. - * - * Metrics are collected from the <a href="https://docs.vespa.ai/documentation/reference/metrics.html">metrics</a> - * API of a Vespa endpoint, and contain the current health status of the endpoint, values for all configured metrics in - * that endpoint, and the time interval from which these metrics were sampled. - * - * Each metric is indexed by a name, and, optionally, along a custom set of dimensions, given by a {@code Map<String, String>}. - * - * @author jonmv - */ -public class Metrics { - - private final Instant start, end; - private final Map<String, Metric> metrics; - - private Metrics(Instant start, Instant end, Map<String, Metric> metrics) { - this.start = start; - this.end = end; - this.metrics = metrics; - } - - public static Metrics of(Instant start, Instant end, Map<String, Metric> metrics) { - if ( ! start.isBefore(end)) - throw new IllegalArgumentException("Given time interval must be positive: '" + start + "' to '" + end + "'."); - - return new Metrics(start, end, copyOf(metrics)); - } - - /** Returns the start of the time window from which these metrics were sampled, or throws if the status is {@code Status.down}. */ - public Instant start() { - return start; - } - - /** Returns the end of the time window from which these metrics were sampled, or throws if the status is {@code Status.down}. */ - public Instant end() { - return end; - } - - /** Returns the metric with the given name, or throws a NoSuchElementException if no such Metric is known. */ - public Metric get(String name) { - if ( ! metrics.containsKey(name)) - throw new NoSuchElementException("No metric with name '" + name + "'."); - - return metrics.get(name); - } - - /** Returns the underlying, unmodifiable Map. */ - public Map<String, Metric> asMap() { - return metrics; - } - - @Override - public String toString() { - return new StringJoiner(", ", Metrics.class.getSimpleName() + "[", "]") - .add("start=" + start) - .add("end=" + end) - .add("metrics=" + metrics) - .toString(); - } - -} diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Space.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Space.java deleted file mode 100644 index 561c0f9dee3..00000000000 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Space.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package ai.vespa.hosted.cd.metric; - -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.IntStream; - -import static java.util.stream.Collectors.toUnmodifiableMap; - -/** - * Used to easily generate points (Map<String, ?>) for a space defined here by its dimension names. - * - * @author jonmv - */ -public class Space { - - private final List<String> dimensions; - - private Space(List<String> dimensions) { - this.dimensions = dimensions; - } - - /** Creates a new space with the given named dimensions, in order. */ - public static Space of(List<String> dimensions) { - if (Set.copyOf(dimensions).size() != dimensions.size()) - throw new IllegalArgumentException("Duplicated dimension names in '" + dimensions + "'."); - - return new Space(List.copyOf(dimensions)); - } - - /** Returns a point in this space, with the given values along each dimensions, in order. */ - public Map<String, ?> at(List<?> values) { - if (dimensions.size() != values.size()) - throw new IllegalArgumentException("This space has " + dimensions.size() + " dimensions, but " + values.size() + " were given."); - - return IntStream.range(0, dimensions.size()).boxed().collect(toUnmodifiableMap(dimensions::get, values::get)); - } - - /** Returns a point in this space, with the given values along each dimensions, in order. */ - public Map<String, ?> at(Object... values) { - return at(List.of(values)); - } - -} diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Statistic.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Statistic.java deleted file mode 100644 index 62b2528e0a4..00000000000 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Statistic.java +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package ai.vespa.hosted.cd.metric; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.StringJoiner; - -import static java.util.Map.copyOf; - -/** - * Known statistic about a metric, at a certain point. - * - * @author jonmv - */ -public class Statistic { - - private final Map<Type, Double> data; - - /** Creates a new Statistic with a copy of the given data. */ - private Statistic(Map<Type, Double> data) { - this.data = data; - } - - public static Statistic of(Map<Type, Double> data) { - for (Type type : List.of(Type.count, Type.rate, Type.average)) - if ( ! data.containsKey(type)) - throw new IllegalArgumentException("Required data type '" + type + "' not present in '" + data + "'"); - - return new Statistic(copyOf(data)); - } - - /** Returns the value of the given type, or throws a NoSuchElementException if this isn't known. */ - public double get(Type key) { - if ( ! data.containsKey(key)) - throw new NoSuchElementException("No value with key '" + key + "' is known."); - - return data.get(key); - } - - /** Returns the underlying, unmodifiable Map. */ - public Map<Type, Double> asMap() { - return data; - } - - Statistic mergedWith(Statistic other) { - if (data.keySet().equals(other.data.keySet())) - throw new IllegalArgumentException("Unequal key sets '" + data.keySet() + "' and '" + other.data.keySet() + "'."); - - Map<Type, Double> merged = new HashMap<>(); - double n1 = get(Type.count), n2 = other.get(Type.count); - for (Type type : data.keySet()) switch (type) { - case count: merged.put(type, n1 + n2); break; - case rate: merged.put(type, get(Type.rate) + other.get(Type.rate)); break; - case max: merged.put(type, Math.max(get(Type.max), other.get(Type.max))); break; - case min: merged.put(type, Math.min(get(Type.min), other.get(Type.min))); break; - case average: merged.put(type, (n1 * get(Type.average) + n2 * other.get(Type.average)) / (n1 + n2)); break; - case last: - case percentile95: - case percentile99: break; - default: throw new IllegalArgumentException("Unexpected type '" + type + "'."); - } - return of(merged); - } - - @Override - public String toString() { - return new StringJoiner(", ", Statistic.class.getSimpleName() + "[", "]") - .add("data=" + data) - .toString(); - } - -} diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Type.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Type.java deleted file mode 100644 index d02593e5eb3..00000000000 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Type.java +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package ai.vespa.hosted.cd.metric; - -/** - * Known statistic types. - */ -public enum Type { - - /** 95th percentile measurement. */ - percentile95, - - /** 99th percentile measurement. */ - percentile99, - - /** Average over all measurements. */ - average, - - /** Number of measurements. */ - count, - - /** Last measurement. */ - last, - - /** Maximum measurement. */ - max, - - /** Minimum measurement. */ - min, - - /** Number of measurements per second. */ - rate; - -} |