Skip to content

Commit

Permalink
Merge pull request #15 from appsignal/avoid-cloning-metrics-into-keys
Browse files Browse the repository at this point in the history
Avoid cloning metrics into keys
  • Loading branch information
unflxw authored Oct 17, 2024
2 parents 6a440c8 + da83b7f commit 8624b26
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Empty file removed Makefile
Empty file.
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ impl AppsignalMetric {
})
}

pub fn to_key(&self) -> AppsignalMetricKey {
AppsignalMetricKey(self.clone())
pub fn into_key(self) -> AppsignalMetricKey {
AppsignalMetricKey(self)
}
}

Expand Down Expand Up @@ -156,7 +156,7 @@ fn extract_volume_metrics(results: &Value, pod_name: &str, out: &mut HashSet<App
tags.insert("volume".to_owned(), volume_name.to_owned());

if let Some(metric) = AppsignalMetric::new(metric_name, tags, metric_value) {
out.insert(metric.to_key());
out.insert(metric.into_key());
}
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ fn extract_pod_metrics(
tags.insert("pod".to_owned(), pod_name.to_owned());

if let Some(metric) = AppsignalMetric::new(metric_name, tags, metric_value) {
out.insert(metric.to_key());
out.insert(metric.into_key());
}
}

Expand Down Expand Up @@ -280,7 +280,7 @@ fn extract_node_metrics(node_results: &Value, out: &mut HashSet<AppsignalMetricK
tags.insert("node".to_owned(), node_name.to_owned());

if let Some(metric) = AppsignalMetric::new(metric_name, tags, metric_value) {
out.insert(metric.to_key());
out.insert(metric.into_key());
}
}
}
Expand All @@ -291,7 +291,7 @@ mod tests {
use serde_json::json;

fn assert_contains_metric(out: &HashSet<AppsignalMetricKey>, metric: AppsignalMetric) {
if let Some(out_metric) = out.get(&metric.clone().to_key()) {
if let Some(out_metric) = out.get(&metric.clone().into_key()) {
assert_eq!(out_metric.0, metric);
} else {
panic!("Metric not found: {:?}", &metric);
Expand Down Expand Up @@ -603,7 +603,7 @@ mod tests {
&json!(123456789),
)
.expect("Could not create metric")
.to_key(),
.into_key(),
);

let json = serde_json::to_string(&out).expect("Could not serialize JSON");
Expand Down

0 comments on commit 8624b26

Please sign in to comment.