metrics-exporter-prometheus: switch methods to gain access to the inner data of the recorder (using a type alias)
This commit is contained in:
parent
10fc3736c4
commit
1b852b32a4
|
@ -20,8 +20,8 @@ default = ["tokio-exporter"]
|
||||||
tokio-exporter = ["hyper", "tokio"]
|
tokio-exporter = ["hyper", "tokio"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
metrics = { version = "0.13.0-alpha.1", path="../metrics" }
|
metrics = { version = "0.13.0-alpha.1", path = "../metrics" }
|
||||||
metrics-util = { version = "0.4.0-alpha.1", path="../metrics-util" }
|
metrics-util = { version = "0.4.0-alpha.1", path = "../metrics-util" }
|
||||||
hdrhistogram = "7.1"
|
hdrhistogram = "7.1"
|
||||||
parking_lot = "0.11"
|
parking_lot = "0.11"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
|
|
@ -26,6 +26,9 @@ 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 {
|
||||||
|
@ -65,7 +68,8 @@ struct Snapshot {
|
||||||
pub distributions: HashMap<String, HashMap<Vec<String>, Distribution>>,
|
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,
|
registry: PrometheusRegistry,
|
||||||
distributions: RwLock<HashMap<String, HashMap<Vec<String>, Distribution>>>,
|
distributions: RwLock<HashMap<String, HashMap<Vec<String>, Distribution>>>,
|
||||||
quantiles: Vec<Quantile>,
|
quantiles: Vec<Quantile>,
|
||||||
|
@ -75,6 +79,7 @@ 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
|
||||||
}
|
}
|
||||||
|
@ -165,6 +170,7 @@ 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
|
||||||
|
@ -334,9 +340,9 @@ pub struct PrometheusRecorder {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrometheusRecorder {
|
impl PrometheusRecorder {
|
||||||
/// Renders the Prometheus metrics in string format.
|
///Returns a [`PrometheusHandle`] from the inner struct of this recorder.
|
||||||
pub fn render(&self) -> String {
|
pub fn handle(&self) -> PrometheusHandle {
|
||||||
self.inner.render()
|
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>) {
|
||||||
|
|
Loading…
Reference in New Issue