Skip to content

Commit

Permalink
Nullify noLabels in StatefulMetric during clear() to prevent no-label…
Browse files Browse the repository at this point in the history
…s increase to stop working (#972)

Signed-off-by: Iacopo Pace <iaco.pace@gmail.com>
Co-authored-by: Iacopo Pace <iaco.pace@gmail.com>
  • Loading branch information
iaco86 and Iacopo Pace committed Sep 7, 2024
1 parent ec56b2c commit b2db709
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public void remove(String... labelValues) {
*/
public void clear() {
data.clear();
noLabels = null;
}

protected abstract T newDataPoint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,10 @@ public void testClearNoLabels() {
// No labels is always present, but as no value has been observed after clear() the value should be 0.0
Assert.assertEquals(1, counter.collect().getDataPoints().size());
Assert.assertEquals(0.0, counter.collect().getDataPoints().get(0).getValue(), 0.0);

// Making inc() works correctly after clear()
counter.inc();
Assert.assertEquals(1, counter.collect().getDataPoints().size());
Assert.assertEquals(1.0, counter.collect().getDataPoints().get(0).getValue(), 0.0);
}
}

0 comments on commit b2db709

Please sign in to comment.