use std::collections::HashMap;
use crate::distribution::Distribution;
use crate::formatting::sanitize_metric_name;
use indexmap::IndexMap;
use metrics::SetRecorderError;
use thiserror::Error;
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum Matcher {
Full(String),
Prefix(String),
Suffix(String),
}
impl Matcher {
pub fn matches(&self, key: &str) -> bool {
match self {
Matcher::Prefix(prefix) => key.starts_with(prefix),
Matcher::Suffix(suffix) => key.ends_with(suffix),
Matcher::Full(full) => key == full,
}
}
pub(crate) fn sanitized(self) -> Matcher {
match self {
Matcher::Prefix(prefix) => Matcher::Prefix(sanitize_metric_name(prefix.as_str())),
Matcher::Suffix(suffix) => Matcher::Suffix(sanitize_metric_name(suffix.as_str())),
Matcher::Full(full) => Matcher::Full(sanitize_metric_name(full.as_str())),
}
}
}
#[derive(Debug, Error)]
pub enum BuildError {
#[error("failed to create Tokio runtime for exporter: {0}")]
FailedToCreateRuntime(String),
#[error("failed to create HTTP listener: {0}")]
FailedToCreateHTTPListener(String),
#[error("failed to install exporter as global recorder: {0}")]
FailedToSetGlobalRecorder(#[from] SetRecorderError),
#[error("failed to parse address as a valid IP address/subnet: {0}")]
InvalidAllowlistAddress(String),
#[error("push gateway endpoint is not valid: {0}")]
InvalidPushGatewayEndpoint(String),
#[error("attempted to build exporter with no exporters enabled; did you disable default features and forget to enable either the `http-listener` or `push-gateway` features?")]
MissingExporterConfiguration,
#[error("bucket bounds/quantiles cannot be empty")]
EmptyBucketsOrQuantiles,
}
pub struct Snapshot {
pub counters: HashMap<String, HashMap<Vec<String>, u64>>,
pub gauges: HashMap<String, HashMap<Vec<String>, f64>>,
pub distributions: HashMap<String, IndexMap<Vec<String>, Distribution>>,
}