prometheus / prometheus/client_rust
Counter and Family encode empty LabelSet differently
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 606
- Forks
- 113
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 8
Description
If you create a Family, the empty label set will encode like metric{} 2. If you use a raw Counter, it will encode like counter 2.
This seems like an unintended difference
use std::fmt::Error;
use prometheus_client::encoding::EncodeLabelSet;
use prometheus_client::encoding::text::encode;
use prometheus_client::metrics::counter::Counter;
use prometheus_client::metrics::family::Family;
use prometheus_client::registry::Registry;
#[test]
fn test_counter_vs_family() {
let mut registry = Registry::default();
let family: Family::<EmptyLabels, Counter> = Family::default();
let ctr: Counter = Counter::default();
registry.register("family", "", family.clone());
registry.register("counter", "", ctr.clone());
#[derive(Eq, PartialEq, Hash, Debug, Clone)]
struct EmptyLabels {}
impl EncodeLabelSet for EmptyLabels {
fn encode(&self, _encoder: &mut prometheus_client::encoding::LabelSetEncoder) -> Result<(), Error> {
Ok(())
}
}
family.get_or_create(&EmptyLabels {}).inc();
ctr.inc();
let mut encoded = String::new();
encode(&mut encoded, ®istry).unwrap();
println!("{}", encoded);
}
# HELP family .
# TYPE family counter
family_total{} 1
# HELP counter .
# TYPE counter counter
counter_total 1
# EOF
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 with the provided test using prometheus_client::encoding::text::encode and compare the Counter and Family outputs shown in the issue. Trace the encoding entry points for Counter and Family, then confirm that the completed work makes empty label sets encode consistently and that the test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- observability-sre
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100