Skip to content

Commit

Permalink
refactor: remove duplicate code for incrementing counters (#983)
Browse files Browse the repository at this point in the history
From @56quarters in #981

Delegate to count method and use glob import for metric traits

(resubmitting due to github commit signature issues -- jrc)
  • Loading branch information
jrconlin authored Jan 27, 2021
1 parent 3c23fb4 commit d72228b
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions src/server/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,7 @@ impl Metrics {
}

pub fn incr_with_tags(&self, label: &str, tags: Option<Tags>) {
if let Some(client) = self.client.as_ref() {
let mut tagged = client.incr_with_tags(label);
let mut mtags = self.tags.clone().unwrap_or_default();
if let Some(tags) = tags {
mtags.extend(tags.tags);
}
for key in mtags.tags.keys().clone() {
if let Some(val) = mtags.tags.get(key) {
tagged = tagged.with_tag(&key, val.as_ref());
}
}
// Include any "hard coded" tags.
// incr = incr.with_tag("version", env!("CARGO_PKG_VERSION"));
match tagged.try_send() {
Err(e) => {
// eat the metric, but log the error
warn!("⚠️ Metric {} error: {:?} ", label, e; mtags);
}
Ok(v) => trace!("☑️ {:?}", v.as_metric_str()),
}
}
self.count_with_tags(label, 1, tags)
}

pub fn count(&self, label: &str, count: i64) {
Expand Down

0 comments on commit d72228b

Please sign in to comment.