#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum TextProfile {
PrometheusV0_0_4,
PrometheusV1_0_0 {
escaping_scheme: EscapingScheme,
},
OpenMetricsV0_0_1,
OpenMetricsV1_0_0 {
escaping_scheme: EscapingScheme,
},
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
#[non_exhaustive]
pub enum EscapingScheme {
AllowUtf8,
#[default]
Underscores,
Dots,
Values,
}
impl Default for TextProfile {
fn default() -> Self {
Self::OpenMetricsV1_0_0 { escaping_scheme: EscapingScheme::default() }
}
}
macro_rules! text_v1_content_type {
($base:literal, $escaping_scheme:expr) => {
match $escaping_scheme {
EscapingScheme::AllowUtf8 => concat!($base, "; escaping=allow-utf-8"),
EscapingScheme::Underscores => concat!($base, "; escaping=underscores"),
EscapingScheme::Dots => concat!($base, "; escaping=dots"),
EscapingScheme::Values => concat!($base, "; escaping=values"),
}
};
}
impl TextProfile {
pub const fn content_type(self) -> &'static str {
match self {
Self::PrometheusV0_0_4 => "text/plain; version=0.0.4; charset=utf-8",
Self::PrometheusV1_0_0 { escaping_scheme } => {
text_v1_content_type!("text/plain; version=1.0.0; charset=utf-8", escaping_scheme)
},
Self::OpenMetricsV0_0_1 => "application/openmetrics-text; version=0.0.1; charset=utf-8",
Self::OpenMetricsV1_0_0 { escaping_scheme } => {
text_v1_content_type!(
"application/openmetrics-text; version=1.0.0; charset=utf-8",
escaping_scheme
)
},
}
}
}
impl TextProfile {
pub const fn escaping_scheme(self) -> Option<EscapingScheme> {
match self {
Self::PrometheusV0_0_4 | Self::OpenMetricsV0_0_1 => None,
Self::PrometheusV1_0_0 { escaping_scheme }
| Self::OpenMetricsV1_0_0 { escaping_scheme } => Some(escaping_scheme),
}
}
}
#[cfg(any(feature = "prost", feature = "protobuf"))]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
#[non_exhaustive]
pub enum ProtobufProfile {
#[default]
Prometheus,
OpenMetrics1,
}
#[cfg(any(feature = "prost", feature = "protobuf"))]
impl ProtobufProfile {
pub const fn content_type(self) -> &'static str {
match self {
Self::Prometheus => {
"application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited"
},
Self::OpenMetrics1 => {
"application/openmetrics-protobuf; version=1.0.0; proto=openmetrics.MetricSet"
},
}
}
}