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
|
@ -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>) {
|
||||
|
|
Loading…
Reference in New Issue