prometheus / prometheus/client_rust
Undeterministic order in output
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 606
- Forks
- 113
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 8
Description
The output or encode() is non-deterministic when creating multiple metrics of the same type.
So basically:
pub fn repro() -> String {
let mut registry = <prometheus_client::registry::Registry>::default();
let gauge = Family::<MyLabels, Gauge<f64, AtomicU64>>::default();
registry.register("test", "help", gauge.clone());
gauge
.get_or_create(&MyLabels {
label: "one".into(),
})
.set(0.1);
gauge
.get_or_create(&MyLabels {
label: "two".into(),
})
.set(0.2);
let mut buffer = String::new();
encode(&mut buffer, ®istry).unwrap();
buffer
}
This will sometimes return this:
HELP test help.
# TYPE test gauge
test{label="one"} 0.1
test{label="two"} 0.2
# EOF
And sometimes this:
HELP test help.
# TYPE test gauge
test{label="two"} 0.2
test{label="one"} 0.1
# EOF
I would expect the metrics to be somehow sorted deterministically.
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
Start at encode and trace how the Registry and Family values are iterated when multiple metrics share a type. Use the provided repro to observe the ordering, then verify that repeated encodes produce the same metric order and match the expected deterministic output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100