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

Add support for initializing histogram metrics with labels to zero #90

Closed
jnovick opened this issue Mar 2, 2020 · 2 comments
Closed

Comments

@jnovick
Copy link

jnovick commented Mar 2, 2020

I need the ability to use the increase or rate function and see when a metric goes from uninitialized (Which I consider 0) to a non-zero value. According to official docs,

There SHOULD be a way to initialize a given Child with the default value, usually just calling labels(). Metrics without labels MUST always be initialized to avoid problems with missing metrics.

This means, I should be able to specify in advance a metric's labels to set to zero so initial scraping shows that zero value.

There is already a workaround for Counter and Gauge by calling metrics.WithLabels("exampleLabel").Inc(0) substituting in the appropriate labels. There is not a workaround for Histogram that I can find though. This is of course not possible when possible labels are not know in advance, but when they are known in advance, it is very beneficial to be able to specify them.

Similar issue in another Prometheus Library: siimon/prom-client#118

@sanych-sun
Copy link
Member

sanych-sun commented Mar 2, 2020

@jnovick I believe there is functionality to handle your use-case.

If you use MetricFactory to create a metrics there is an option to suppressEmptySamples (which is true by default), try to set it to false while creating the metric. Then the sample should appear in payload once you call WithLabels method. I cannot test the suggestion yet, but I can create a sample for you later.

@jnovick
Copy link
Author

jnovick commented Mar 2, 2020

Thanks you. If I set that to false then simply calling WithLabels initializes the values to zero and accomplishes what I want.

@jnovick jnovick closed this as completed Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants