BucketedCallback: fix prune() to remove unset sub-metrics from registry
BucketedCallback enables defining compound metrics having a set of sub-metrics along a dimension. This is used e.g. in CallbackMetric1 where the additional type parameter F1 defines the type of this dimension. For each of the values of this dimension present in the current dataset of the compound metric BucketedCallback registers a corresponding metric in DropWizard's metric registry which isn't aware of the relationship between a compount metric in Gerrit and the corresponding sub-metrics. If another measurement yields a new metric dataset which no longer contains some of the earlier registered sub-metrics doPrune() did remove these stale sub-metrics from the "cells" collection but missed to remove them from DropWizard's metric registry. This had the effect that such stale metrics no longer present in the current dataset were still reported via the used metrics reporter plugin albeit the underlying monitoring dataset didn't contain that data anymore. Fix this by removing the stale sub-metrics also from the DropWizard metric registry. Change-Id: I767530f57883379c976614705241cbd1d1597541
This commit is contained in:
@@ -22,6 +22,7 @@ import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.metrics.Description;
|
||||
import com.google.gerrit.metrics.Field;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/** Abstract callback metric broken down into buckets. */
|
||||
@@ -66,7 +67,13 @@ abstract class BucketedCallback<V> implements BucketedMetric {
|
||||
}
|
||||
|
||||
void doPrune() {
|
||||
cells.entrySet().removeIf(objectValueGaugeEntry -> !objectValueGaugeEntry.getValue().set);
|
||||
Set<Map.Entry<Object, BucketedCallback<V>.ValueGauge>> entries = cells.entrySet();
|
||||
for (Map.Entry<Object, ValueGauge> e : entries) {
|
||||
if (!e.getValue().set) {
|
||||
entries.remove(e);
|
||||
registry.remove(submetric(e.getKey()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void doEndSet() {
|
||||
|
||||
Reference in New Issue
Block a user