diff --git a/metrics-exporter-prometheus/Cargo.toml b/metrics-exporter-prometheus/Cargo.toml index f1717c1..a18079c 100644 --- a/metrics-exporter-prometheus/Cargo.toml +++ b/metrics-exporter-prometheus/Cargo.toml @@ -20,8 +20,8 @@ default = ["tokio-exporter"] tokio-exporter = ["hyper", "tokio"] [dependencies] -metrics = { version = "0.13.0-alpha.1", path="../metrics" } -metrics-util = { version = "0.4.0-alpha.1", path="../metrics-util" } +metrics = { version = "0.13.0-alpha.1", path = "../metrics" } +metrics-util = { version = "0.4.0-alpha.1", path = "../metrics-util" } hdrhistogram = "7.1" parking_lot = "0.11" thiserror = "1.0" diff --git a/metrics-exporter-prometheus/src/lib.rs b/metrics-exporter-prometheus/src/lib.rs index ea4723b..ffeeda7 100644 --- a/metrics-exporter-prometheus/src/lib.rs +++ b/metrics-exporter-prometheus/src/lib.rs @@ -26,6 +26,9 @@ 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 { @@ -65,7 +68,8 @@ struct Snapshot { pub distributions: HashMap, Distribution>>, } -struct Inner { +/// Inner contains all of the data stored by the Prometheus Recorder. +pub struct Inner { registry: PrometheusRegistry, distributions: RwLock, Distribution>>>, quantiles: Vec, @@ -75,6 +79,7 @@ struct Inner { } impl Inner { + /// Returns a reference to the [`PrometheusRegistry`] this struct uses. pub fn registry(&self) -> &PrometheusRegistry { &self.registry } @@ -165,6 +170,7 @@ impl Inner { } } + /// Returns the metrics in Prometheus accepted String format. pub fn render(&self) -> String { let mut sorted_overrides = self .buckets_by_name @@ -334,9 +340,9 @@ pub struct PrometheusRecorder { } impl PrometheusRecorder { - /// Renders the Prometheus metrics in string format. - pub fn render(&self) -> String { - self.inner.render() + ///Returns a [`PrometheusHandle`] from the inner struct of this recorder. + pub fn handle(&self) -> PrometheusHandle { + self.inner.clone() } fn add_description_if_missing(&self, key: &Key, description: Option<&'static str>) {