metrics-exporter-prometheus: switch methods to gain access to the inner data of the recorder (using a type alias)

This commit is contained in:
kilpatty 2020-10-29 16:18:13 -05:00
parent 10fc3736c4
commit 1b852b32a4
No known key found for this signature in database
GPG Key ID: 2346BDEEAEF0F2D3
2 changed files with 12 additions and 6 deletions

View File

@ -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"

View File

@ -26,6 +26,9 @@ use tokio::{pin, runtime, select};
type PrometheusRegistry = Registry<CompositeKey, Handle>;
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.
#[derive(ThisError, Debug)]
pub enum Error {
@ -65,7 +68,8 @@ struct Snapshot {
pub distributions: HashMap<String, HashMap<Vec<String>, Distribution>>,
}
struct Inner {
/// Inner contains all of the data stored by the Prometheus Recorder.
pub struct Inner {
registry: PrometheusRegistry,
distributions: RwLock<HashMap<String, HashMap<Vec<String>, Distribution>>>,
quantiles: Vec<Quantile>,
@ -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>) {