metrics-rs / metrics

A metrics ecosystem for Rust.
MIT License
1.13k stars 158 forks source link

prometheus exporter sanitizes valid metric names #289

Closed goller closed 2 years ago

goller commented 2 years ago

I have a metric compaction_level2_duration_ns that is sanitized into compaction_level__duration_ns. I believe this metric is a valid prometheus name..

Here is a test that shows that it fails:

    #[test]
    fn check_sanitize() {
        let name = "compaction_level2_duration_ns".to_owned();
        let actual = sanitize_metric_name(&name);
        assert_eq!(name, actual);
    }

The sanitize code is here:

https://github.com/metrics-rs/metrics/blob/5f720a0a8f53aaee4bfa9de1d9fc470f1ed6b3c3/metrics-exporter-prometheus/src/formatting.rs#L111-L115

I think it is because it replaces the first n occurrences matching the predicate, regardless of their position.

tobz commented 2 years ago

Yep, you're definitely right.

@gnuvince has graciously submitted a PR to fix this over in #290.