mirror of
https://github.com/google/nomulus
synced 2026-01-09 23:47:49 +00:00
Enforce monotonicity for IncrementableMetrics
This change enforces that IncrementableMetrics should only monotonically increase in value, and adds a new increment() method to increment by one, which is slightly faster than incrementBy (due to a lack of non-negative checking) in the common case that the counter should only be incremented by one. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=130578421
This commit is contained in:
@@ -49,17 +49,25 @@ public final class Counter extends AbstractMetric<Long>
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void incrementBy(Number offset, ImmutableList<String> labelValues) {
|
||||
values.addAndGet(labelValues, offset.longValue());
|
||||
void incrementBy(long offset, ImmutableList<String> labelValues) {
|
||||
values.addAndGet(labelValues, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void incrementBy(long offset, String... labelValues) {
|
||||
checkArgument(labelValues.length == this.getMetricSchema().labels().size(), LABEL_COUNT_ERROR);
|
||||
checkArgument(offset >= 0, "The offset provided must be non-negative");
|
||||
|
||||
incrementBy(offset, ImmutableList.copyOf(labelValues));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void increment(String... labelValues) {
|
||||
checkArgument(labelValues.length == this.getMetricSchema().labels().size(), LABEL_COUNT_ERROR);
|
||||
|
||||
incrementBy(1L, ImmutableList.copyOf(labelValues));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a snapshot of the metric's values. The timestamp of each {@link MetricPoint} will be
|
||||
* the last modification time for that tuple of label values.
|
||||
|
||||
Reference in New Issue
Block a user