metrics-exporter-prometheus: move PrometheusHandle to struct. Eliminate now useless pub function doc comments

This commit is contained in:
kilpatty 2020-10-30 08:49:48 -05:00
parent 1b852b32a4
commit e2ba57bfa6
No known key found for this signature in database
GPG Key ID: 2346BDEEAEF0F2D3
1 changed files with 16 additions and 8 deletions

View File

@ -26,9 +26,6 @@ use tokio::{pin, runtime, select};
type PrometheusRegistry = Registry<CompositeKey, Handle>; type PrometheusRegistry = Registry<CompositeKey, Handle>;
type HdrHistogram = hdrhistogram::Histogram<u64>; type HdrHistogram = hdrhistogram::Histogram<u64>;
/// A type wrapper around the Inner struct of the Prometheus recorder.
pub type PrometheusHandle = Arc<Inner>;
/// Errors that could occur while installing a Prometheus recorder/exporter. /// Errors that could occur while installing a Prometheus recorder/exporter.
#[derive(ThisError, Debug)] #[derive(ThisError, Debug)]
pub enum Error { pub enum Error {
@ -68,8 +65,7 @@ struct Snapshot {
pub distributions: HashMap<String, HashMap<Vec<String>, Distribution>>, pub distributions: HashMap<String, HashMap<Vec<String>, Distribution>>,
} }
/// Inner contains all of the data stored by the Prometheus Recorder. struct Inner {
pub struct Inner {
registry: PrometheusRegistry, registry: PrometheusRegistry,
distributions: RwLock<HashMap<String, HashMap<Vec<String>, Distribution>>>, distributions: RwLock<HashMap<String, HashMap<Vec<String>, Distribution>>>,
quantiles: Vec<Quantile>, quantiles: Vec<Quantile>,
@ -79,7 +75,6 @@ pub struct Inner {
} }
impl Inner { impl Inner {
/// Returns a reference to the [`PrometheusRegistry`] this struct uses.
pub fn registry(&self) -> &PrometheusRegistry { pub fn registry(&self) -> &PrometheusRegistry {
&self.registry &self.registry
} }
@ -170,7 +165,6 @@ impl Inner {
} }
} }
/// Returns the metrics in Prometheus accepted String format.
pub fn render(&self) -> String { pub fn render(&self) -> String {
let mut sorted_overrides = self let mut sorted_overrides = self
.buckets_by_name .buckets_by_name
@ -342,7 +336,9 @@ pub struct PrometheusRecorder {
impl PrometheusRecorder { impl PrometheusRecorder {
///Returns a [`PrometheusHandle`] from the inner struct of this recorder. ///Returns a [`PrometheusHandle`] from the inner struct of this recorder.
pub fn handle(&self) -> PrometheusHandle { 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>) { 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<Inner>,
}
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. /// Builder for creating and installing a Prometheus recorder/exporter.
pub struct PrometheusBuilder { pub struct PrometheusBuilder {
listen_address: SocketAddr, listen_address: SocketAddr,