From 9a15f08b3a1dd7db6408fbc6928a47a2f8e43917 Mon Sep 17 00:00:00 2001 From: mountford Date: Fri, 3 Mar 2017 07:58:03 -0800 Subject: [PATCH] Add Truth subjects for incrementable and event metrics This CL adds Truth framework subjects to some metrics in the Stackdriver metrics library, in a contrib subpackage. It doesn't deal with gauge metrics, and for event metrics, the assertions can only be that a metric has or does not have a distribution for a particular set of label values. Asserting more fine-grained propositions regarding the distribution will require a distribution subject. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=149112692 --- .../registry/monitoring/metrics/MetricPoint.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/java/google/registry/monitoring/metrics/MetricPoint.java b/java/google/registry/monitoring/metrics/MetricPoint.java index 811f74114..faf454f71 100644 --- a/java/google/registry/monitoring/metrics/MetricPoint.java +++ b/java/google/registry/monitoring/metrics/MetricPoint.java @@ -25,7 +25,7 @@ import org.joda.time.Interval; * time {@link Interval}. */ @AutoValue -public abstract class MetricPoint { +public abstract class MetricPoint implements Comparable> { /** * Returns a new {@link MetricPoint} representing a value at a specific {@link Instant}. @@ -69,4 +69,17 @@ public abstract class MetricPoint { public abstract Interval interval(); public abstract V value(); + + @Override + public int compareTo(MetricPoint other) { + int minLength = Math.min(this.labelValues().size(), other.labelValues().size()); + for (int index = 0; index < minLength; index++) { + int comparisonResult = + this.labelValues().get(index).compareTo(other.labelValues().get(index)); + if (comparisonResult != 0) { + return comparisonResult; + } + } + return Integer.compare(this.labelValues().size(), other.labelValues().size()); + } }