summaryrefslogtreecommitdiffstats
path: root/tenant-cd
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2019-12-13 08:50:14 +0100
committerJon Marius Venstad <venstad@gmail.com>2019-12-13 08:50:14 +0100
commitfede32d70d7c8616d5db195fb04f23d33bbac3ca (patch)
tree167d05e35201549c986f32afb8bcf40bc40adb94 /tenant-cd
parentb0098c4d582e071dae1957d38ce4dc2b915e5184 (diff)
Random fixes in currently unused test metrics code
Diffstat (limited to 'tenant-cd')
-rw-r--r--tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Metric.java4
-rw-r--r--tenant-cd/src/main/java/ai/vespa/hosted/cd/metric/Statistic.java7
2 files changed, 9 insertions, 2 deletions
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
index cb3c8e77a9a..cc9d5d82b2c 100644
--- 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
@@ -7,6 +7,7 @@ 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;
/**
@@ -58,7 +59,8 @@ public class Metric {
/** Returns a collapsed version of this, with all statistics aggregated. This does not preserve last, 95 and 99 percentile values. */
public Metric collapse() {
- return collapse(statistics.keySet().iterator().next().keySet());
+ 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. */
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
index fc52900bdac..f1cb89641b3 100644
--- 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
@@ -1,6 +1,7 @@
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;
@@ -22,6 +23,10 @@ public class Statistic {
}
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));
}
@@ -40,7 +45,7 @@ public class Statistic {
Statistic mergedWith(Statistic other) {
if (data.keySet().equals(other.data.keySet()))
- throw new IllegalArgumentException("Incompatible key sets '" + data.keySet() + "' and '" + 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);