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

StatefulMetric clear() invocation causes noLabels increase to stop reporting on collect() #971

Closed
iaco86 opened this issue Jul 19, 2024 · 0 comments · Fixed by #972
Closed
Assignees

Comments

@iaco86
Copy link
Contributor

iaco86 commented Jul 19, 2024

It looks like the current implementation of the io.prometheus.metrics.core.metrics.StatefulMetric#clear method (see #935) is clearing the data, but not nullifying the io.prometheus.metrics.core.metrics.StatefulMetric#noLabels field, allowing that to be returned by the io.prometheus.metrics.core.metrics.StatefulMetric#getNoLabels method, but preventing it from being correctly collected.

This is easily reproducible in the io.prometheus.metrics.core.metrics.StatefulMetricTest#testClearNoLabels test by adding an inc() call and verification after the first clear:

...
        counter.clear();
        // 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);

        // Now we're testing label-less inc() still works correctly
        counter.inc();
        Assert.assertEquals(1, counter.collect().getDataPoints().size());
        Assert.assertEquals(1.0, counter.collect().getDataPoints().get(0).getValue(), 0.0);

If my understanding of the issue is correct, the io.prometheus.metrics.core.metrics.StatefulMetric#clear should also set noLabels = null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants