prometheus / client_rust

Prometheus / OpenMetrics client library in Rust
Apache License 2.0
469 stars 73 forks source link

text::DescriptorEncoder writes incorrect metric names #186

Closed olix0r closed 9 months ago

olix0r commented 9 months ago

I have a metric that is reported via the Collector API:

                let clock_ticks = stat.utime + stat.stime;
                let cpu =
                    prom::ConstCounter::new(Duration::from_millis(clock_ticks * mpt).as_secs_f64());
                let cpue = encoder.encode_descriptor(
                    "cpu",
                    "Total user and system CPU time spent in seconds",
                    Some(&prom::Unit::Seconds),
                    prom::metrics::MetricType::Counter,
                )?;
                cpu.encode(cpue)?;

When it is encoded, its name is encoded inconsistently:

# HELP process_cpu_seconds Total user and system CPU time spent in seconds
# TYPE process_cpu_seconds counter
# UNIT process_cpu_seconds seconds
process_cpu_seconds_total 14.29

That is, the _total suffix is not appended via encoding::text::DescriptorEncoder::encode_descriptor. This needs to be updated to have the same write_suffix behavior that MetricEncoder uses to add _total, _info, etc.

olix0r commented 9 months ago

I found this reference that indicates that this is correct. My problem is actually that prometheus-parse doesn't handle this properly.

mxinden commented 7 months ago

Sorry for the delay here. Your second comment is correct, i.e. this is the correct syntax.

Anyways, I appreciate the detailed report. Let me know in case there is anything I can help with @olix0r.