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

Const label and metric labels can cause duplicate labels without errors #444

Open
mattiekat opened this issue May 31, 2022 · 0 comments
Open

Comments

@mattiekat
Copy link

mattiekat commented May 31, 2022

Describe the bug
Currently if you define const labels and then accidentally add a label with one of the names of the const labels it will get added twice without any errors.

To Reproduce
Steps to reproduce the behavior:

let const_labels: HashMap<String, String> = labels! {
  "label_1" => "some_value",
  "label_2" => "other_value",
};
let const_labels_ref = const_labels
  .iter()
  .map(|(k, v)| (k.as_str(), v.as_str()))
  .collect::<HashMap<_, _>>();

let my_metric = register_int_counter_vec_with_registry!(
  opts!(
    "my_metric",
    "A basic metric",
    const_labels_ref
  ),
  &["label_2", "label_3"],
  registry
)?;

my_metric.with_label_values(&["other_value", "foobar"]).inc();

End result is that using my metric yields an entry such as

# HELP my_metric A basic metric
# TYPE my_metric counter
my_metric{label_1="some_value",label_2="other_value","label_2"="other_value",label_3="foobar"} 1

Expected behavior
Creating the metric with a label that is already defined by the const labels should return an error instead of including it twice in the output.

Additional context
I mean, this is certainly user error, but since the scraper seems to handle it by just ignoring the metrics with duplicate labels it took a while to debug and I definitely would have expected an error.

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

No branches or pull requests

1 participant