Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prometheus exporter sanitizes valid metric names #289

Closed
goller opened this issue Mar 17, 2022 · 1 comment · Fixed by #290
Closed

prometheus exporter sanitizes valid metric names #289

goller opened this issue Mar 17, 2022 · 1 comment · Fixed by #290

Comments

@goller
Copy link

goller commented Mar 17, 2022

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:

pub fn sanitize_metric_name(name: &str) -> String {
// The first character must be [a-zA-Z_:], and all subsequent characters must be [a-zA-Z0-9_:].
name.replacen(invalid_metric_name_start_character, "_", 1)
.replace(invalid_metric_name_character, "_")
}

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

@tobz
Copy link
Member

tobz commented Mar 20, 2022

Yep, you're definitely right.

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

@tobz tobz closed this as completed in #290 Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants