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

Naming conventions: _total vs. _count #2465

Open
Yogu opened this issue May 21, 2024 · 3 comments
Open

Naming conventions: _total vs. _count #2465

Yogu opened this issue May 21, 2024 · 3 comments

Comments

@Yogu
Copy link

Yogu commented May 21, 2024

The Metric and label naming documentation page states that "an accumulating count has a total as a suffix".

The Histograms and summaries best practice page however uses _count as the suffix for a counter.

Are these two recommendations not contradictory? Is the count+sum pair an exception to the general counter case, and thus warrants its own suffix? (If that's the case, it would probably make sense to mention that in the "Metric and label naming" page).

@beorn7
Copy link
Member

beorn7 commented Jun 4, 2024

You should generally avoid naming a metric with a _count suffix. This suffix is a "magic" one that summaries and (classic) histograms auto-generate when ingested (or when represented in the text format). It's IMHO a bad practice, and native histograms avoid that.

Not sure if it is more confusing than useful to explain that on the "Metric and label naming" page.

Maybe we should just list suffixes to avoid (_count, _sum, _bucket, and also _total for non-counters). I'll change the title accordingly.

@Yogu
Copy link
Author

Yogu commented Jun 12, 2024

Thank you for the clarification!

Good to know that _count is to be avoided outside of the histogram context. So regular gauges that tell you the current count of something (e.g. the number of busy workers, number of open tasks etc.) should just not have any suffix at all (e.g. busy_workers, open_tasks), right?

What would you use if you currently only want sum + count (because a metric for the average is enough for the moment), but might want to introduce a histogram in the future? If you start with "_sum" and "_count", you could keep using them if you switch to a histogram later. Or are there subtle differences about a "naive"/manual count metric implemented as a counter and the "_count" metric published as part of a histogram?

@beorn7
Copy link
Member

beorn7 commented Jun 12, 2024

If you just have sum + count, I would use a summary without quantiles. That's the most canonical way of representing it.
If you want a histogram later, so be it. You have to change the metric type then. (In principle, you could also create a bucket-less classic histogram, but in the future, you want native histograms anyway. Another reason to use a summary for as long as you just want sum + count.)

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

No branches or pull requests

2 participants