Skip to content

Commit

Permalink
add test to prometheus module
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Oct 23, 2023
1 parent 9099d69 commit cce12b3
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/svc/telemetry/prometheus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,62 @@ fn replace_dots_with_underscores(str: &str) -> String {
str.replace('.', "_")
}

#[cfg(test)]
mod test {
use std::collections::BTreeMap;

use sozu_command_lib::proto::command::{
filtered_metrics::Inner, AggregatedMetrics, ClusterMetrics, FilteredMetrics, WorkerMetrics,
};

use super::*;

#[test]

fn encode_one_counter() {
let cluster_id = "http://my-cluster-id.com/api?param=value".to_string();

let metric_name = "http_response_status";
let one_filtered_metric = FilteredMetrics {
inner: Some(Inner::Gauge(3)),
};
let mut cluster = BTreeMap::new();
cluster.insert(metric_name.to_owned(), one_filtered_metric);

let cluster_metrics = ClusterMetrics {
cluster,
backends: Vec::new(),
};

let mut clusters = BTreeMap::new();
clusters.insert(cluster_id, cluster_metrics);

let worker_metrics = WorkerMetrics {
proxy: BTreeMap::new(),
clusters,
};

let mut workers = BTreeMap::new();
workers.insert("WORKER-01".to_string(), worker_metrics);


let aggregated_metrics = AggregatedMetrics {
main: BTreeMap::new(),
workers,
};



let prometheus_metrics = convert_metrics_to_prometheus(aggregated_metrics);

let expected = r#"# TYPE http_response_status gauge
http_response_status{cluster_id="http%3A%2F%2Fmy-cluster-id.com%2Fapi%3Fparam%3Dvalue"} 3
"#;

assert_eq!(expected.to_string(), prometheus_metrics);
}
}

/* this is all false
/// convert a Sōzu Percentiles struct into prometheus histogram lines:
Expand Down

0 comments on commit cce12b3

Please sign in to comment.