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
This commit is contained in:
mountford 2017-03-03 07:58:03 -08:00 committed by Ben McIlwain
parent 5614760d53
commit 9a15f08b3a

View file

@ -25,7 +25,7 @@ import org.joda.time.Interval;
* time {@link Interval}.
*/
@AutoValue
public abstract class MetricPoint<V> {
public abstract class MetricPoint<V> implements Comparable<MetricPoint<V>> {
/**
* Returns a new {@link MetricPoint} representing a value at a specific {@link Instant}.
@ -69,4 +69,17 @@ public abstract class MetricPoint<V> {
public abstract Interval interval();
public abstract V value();
@Override
public int compareTo(MetricPoint<V> 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());
}
}