From e2ba57bfa63a08ec07a8c94f6fa2d994604a64e9 Mon Sep 17 00:00:00 2001 From: kilpatty Date: Fri, 30 Oct 2020 08:49:48 -0500 Subject: [PATCH] metrics-exporter-prometheus: move PrometheusHandle to struct. Eliminate now useless pub function doc comments --- metrics-exporter-prometheus/src/lib.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/metrics-exporter-prometheus/src/lib.rs b/metrics-exporter-prometheus/src/lib.rs index ffeeda7..22811bc 100644 --- a/metrics-exporter-prometheus/src/lib.rs +++ b/metrics-exporter-prometheus/src/lib.rs @@ -26,9 +26,6 @@ use tokio::{pin, runtime, select}; type PrometheusRegistry = Registry; type HdrHistogram = hdrhistogram::Histogram; -/// A type wrapper around the Inner struct of the Prometheus recorder. -pub type PrometheusHandle = Arc; - /// Errors that could occur while installing a Prometheus recorder/exporter. #[derive(ThisError, Debug)] pub enum Error { @@ -68,8 +65,7 @@ struct Snapshot { pub distributions: HashMap, Distribution>>, } -/// Inner contains all of the data stored by the Prometheus Recorder. -pub struct Inner { +struct Inner { registry: PrometheusRegistry, distributions: RwLock, Distribution>>>, quantiles: Vec, @@ -79,7 +75,6 @@ pub struct Inner { } impl Inner { - /// Returns a reference to the [`PrometheusRegistry`] this struct uses. pub fn registry(&self) -> &PrometheusRegistry { &self.registry } @@ -170,7 +165,6 @@ impl Inner { } } - /// Returns the metrics in Prometheus accepted String format. pub fn render(&self) -> String { let mut sorted_overrides = self .buckets_by_name @@ -342,7 +336,9 @@ pub struct PrometheusRecorder { impl PrometheusRecorder { ///Returns a [`PrometheusHandle`] from the inner struct of this recorder. pub fn handle(&self) -> PrometheusHandle { - self.inner.clone() + PrometheusHandle { + inner: self.inner.clone(), + } } fn add_description_if_missing(&self, key: &Key, description: Option<&'static str>) { @@ -355,6 +351,18 @@ impl PrometheusRecorder { } } +/// A wrapper around the Inner struct of the Prometheus recorder. +pub struct PrometheusHandle { + inner: Arc, +} + +impl PrometheusHandle { + /// Returns the metrics in Prometheus accepted String format. + pub fn render(&self) -> String { + self.inner.render() + } +} + /// Builder for creating and installing a Prometheus recorder/exporter. pub struct PrometheusBuilder { listen_address: SocketAddr,