prometheus / prometheus/client_rust
Registering a metric multiple times - foot-gun
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 606
- Forks
- 113
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 8
Description
My pattern when instrumenting an application is to pass a registry around and register the metrics close to their usage. This becomes more important for larger applications in order to reduce what is passed around.
I think there's a potential foot-gun given that registering a metric internally pushes it on to a vector. This means that if a metric is registered more than once (possible, in the absence of the API stating otherwise), then a dynamic situation could result in the process running out of memory. For example, if a task was started for each connection, and that connection registered the metric each time, then memory would grow.
In terms of a solution, I think the API should document that registering a metric more than once is an error and panic. Or, use a set rather than a vector internally, and allow metrics to be registered multiple times.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file, test, or entry point is identified in the issue. Begin by locating metric registration and its internal storage in client_rust, then resolve whether duplicate registration should panic or be deduplicated and add coverage for the chosen behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- observability
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100