Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add debug assertion for variable labels and values.
  • Loading branch information
Roman S. Borschel committed Aug 17, 2020
commit 45b734cce4708839bf290c0d872b4cb1d690fd52
1 change: 1 addition & 0 deletions utils/prometheus/src/sourced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl<T: SourcedType, S: MetricSource> Collector for SourcedMetric<T, S> {
}
}

debug_assert_eq!(self.desc.variable_labels.len(), label_values.len());
match self.desc.variable_labels.len().cmp(&label_values.len()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All rust-prometheus methods panic when providing unequal label keys and values. While not the greates UX, I would do the same (at least in debug mode) to stay consistent.

E.g. https://docs.rs/prometheus/0.7.0/prometheus/core/struct.MetricVec.html#method.with_label_values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 45b734c.

Ordering::Greater =>
log::warn!("Missing label values for sourced metric {}", self.desc.fq_name),
Expand Down