use std::sync::Arc;
use prometheus_client::metrics::family::MetricConstructor;
use prometheus_client::metrics::histogram::Histogram as ClientHistogram;
#[derive(Debug, Clone)]
pub(crate) struct HistogramConstructor {
buckets: Option<Arc<Vec<f64>>>,
}
impl HistogramConstructor {
pub(crate) fn new(buckets: Option<Vec<f64>>) -> Self {
Self {
buckets: buckets.map(Arc::new),
}
}
}
impl MetricConstructor<ClientHistogram> for HistogramConstructor {
fn new_metric(&self) -> ClientHistogram {
match self.buckets.as_ref() {
Some(buckets) => ClientHistogram::new(buckets.iter().copied()),
None => ClientHistogram::new([]),
}
}
}