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

Allow creating a GenericGaugeVec with Vec<String> #399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,21 @@ impl<P: Atomic> GenericGaugeVec<P> {
/// Create a new [`GenericGaugeVec`] based on the provided
/// [`Opts`] and partitioned by the given label names. At least one label name must
/// be provided.
pub fn new(opts: Opts, label_names: &[&str]) -> Result<Self> {
let variable_names = label_names.iter().map(|s| (*s).to_owned()).collect();
let opts = opts.variable_labels(variable_names);
pub fn new_from_vec(opts: Opts, label_names: Vec<String>) -> Result<Self> {
let opts = opts.variable_labels(label_names);
let metric_vec = MetricVec::create(proto::MetricType::GAUGE, GaugeVecBuilder::new(), opts)?;

Ok(metric_vec as Self)
}

/// Create a new [`GenericGaugeVec`] based on the provided
/// [`Opts`] and partitioned by the given label names. At least one label name must
/// be provided.
pub fn new(opts: Opts, label_names: &[&str]) -> Result<Self> {
let variable_names = label_names.iter().map(|s| (*s).to_owned()).collect();

Self::new_from_vec(opts, variable_names)
}
}

#[cfg(test)]
Expand Down