Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
potkae committed Nov 24, 2023
1 parent d340f84 commit 8f2b0cf
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ impl PrometheusMetricsBuilder {

/// Instantiate PrometheusMetrics struct
pub fn build(self) -> Result<PrometheusMetrics, Box<dyn std::error::Error + Send + Sync>> {

let labels_vec = self.metrics_configuration.labels.clone().to_vec();
let labels = &labels_vec.iter().map(|s| s.as_str()).collect::<Vec<&str>>();

Expand All @@ -363,10 +362,7 @@ impl PrometheusMetricsBuilder {
.namespace(&self.namespace)
.const_labels(self.const_labels.clone());

let http_requests_total = IntCounterVec::new(
http_requests_total_opts,
labels
)?;
let http_requests_total = IntCounterVec::new(http_requests_total_opts, labels)?;

let http_requests_duration_seconds_opts = HistogramOpts::new(
self.metrics_configuration
Expand All @@ -378,10 +374,8 @@ impl PrometheusMetricsBuilder {
.buckets(self.buckets.to_vec())
.const_labels(self.const_labels.clone());

let http_requests_duration_seconds = HistogramVec::new(
http_requests_duration_seconds_opts,
labels
)?;
let http_requests_duration_seconds =
HistogramVec::new(http_requests_duration_seconds_opts, labels)?;

self.registry
.register(Box::new(http_requests_total.clone()))?;
Expand All @@ -403,7 +397,6 @@ impl PrometheusMetricsBuilder {
}
}


#[derive(Debug, Clone)]
///Configurations for the labels used in metrics
pub struct LabelsConfiguration {
Expand All @@ -416,7 +409,7 @@ pub struct LabelsConfiguration {
impl LabelsConfiguration {
fn default() -> LabelsConfiguration {
LabelsConfiguration {
endpoint: String::from("endpoint"),
endpoint: String::from("endpoint"),
method: String::from("method"),
status: String::from("status"),
version: None,
Expand All @@ -427,7 +420,7 @@ impl LabelsConfiguration {
let mut labels = vec![self.endpoint, self.method, self.status];
if let Some(version) = self.version {
labels.push(version);
}
}
labels
}

Expand Down Expand Up @@ -456,15 +449,14 @@ impl LabelsConfiguration {
}
}


#[derive(Debug, Clone)]
/// Configuration for the collected metrics
///
/// Stores individual metric configuration objects
pub struct ActixMetricsConfiguration {
http_requests_total_name: String,
http_requests_duration_seconds_name: String,
labels: LabelsConfiguration
labels: LabelsConfiguration,
}

impl ActixMetricsConfiguration {
Expand All @@ -490,7 +482,7 @@ impl ActixMetricsConfiguration {
}

/// Set name for http_requests_duration_seconds metric
pub fn http_requests_duration_seconds_name(mut self, name: &str)-> Self {
pub fn http_requests_duration_seconds_name(mut self, name: &str) -> Self {
self.http_requests_duration_seconds_name = name.to_owned();
self
}
Expand Down Expand Up @@ -829,9 +821,8 @@ actix_web_prom_http_requests_total{endpoint=\"/health_check\",method=\"GET\",sta
let prometheus = PrometheusMetricsBuilder::new("actix_web_prom")
.endpoint("/metrics")
.metrics_configuration(
ActixMetricsConfiguration::default().labels(
LabelsConfiguration::default().version("version")
)
ActixMetricsConfiguration::default()
.labels(LabelsConfiguration::default().version("version")),
)
.build()
.unwrap();
Expand Down

0 comments on commit 8f2b0cf

Please sign in to comment.