Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullify noLabels in StatefulMetric during clear() to prevent no-label inc to stop working #972

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}