1use ahash::HashSet;
16
17#[derive(Debug, Clone, Default)]
20pub enum ProtocolCtx {
21 #[default]
22 None,
23 OtlpMetric(OtlpMetricCtx),
24}
25
26impl ProtocolCtx {
27 pub fn get_otlp_metric_ctx(&self) -> Option<&OtlpMetricCtx> {
28 match self {
29 ProtocolCtx::None => None,
30 ProtocolCtx::OtlpMetric(opt) => Some(opt),
31 }
32 }
33}
34
35#[derive(Debug, Clone, Default)]
52pub struct OtlpMetricCtx {
53 pub promote_all_resource_attrs: bool,
54 pub resource_attrs: HashSet<String>,
55 pub promote_scope_attrs: bool,
56 pub with_metric_engine: bool,
57 pub experimental_enable_exponential_histogram: bool,
58 pub is_legacy: bool,
59 pub resource_info: bool,
62 pub metric_type: MetricType,
63 pub metric_translation_strategy: OtlpMetricTranslationStrategy,
64}
65
66impl OtlpMetricCtx {
67 pub fn set_metric_type(&mut self, metric_type: MetricType) {
68 self.metric_type = metric_type;
69 }
70}
71
72#[derive(Debug, Clone, Default)]
73pub enum MetricType {
74 #[default]
76 Init,
77 NonMonotonicSum,
78 MonotonicSum,
79 Gauge,
80 Histogram,
81 ExponentialHistogram,
82 Summary,
83}
84
85#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
86pub enum OtlpMetricTranslationStrategy {
87 #[default]
88 UnderscoreEscapingWithSuffixes,
89 UnderscoreEscapingWithoutSuffixes,
90 NoUtf8EscapingWithSuffixes,
91 NoTranslation,
92}
93
94impl OtlpMetricTranslationStrategy {
95 pub const VALUES: [&'static str; 4] = [
96 "UnderscoreEscapingWithSuffixes",
97 "UnderscoreEscapingWithoutSuffixes",
98 "NoUTF8EscapingWithSuffixes",
99 "NoTranslation",
100 ];
101
102 pub fn as_str(self) -> &'static str {
103 match self {
104 Self::UnderscoreEscapingWithSuffixes => "UnderscoreEscapingWithSuffixes",
105 Self::UnderscoreEscapingWithoutSuffixes => "UnderscoreEscapingWithoutSuffixes",
106 Self::NoUtf8EscapingWithSuffixes => "NoUTF8EscapingWithSuffixes",
107 Self::NoTranslation => "NoTranslation",
108 }
109 }
110
111 pub fn should_escape(self) -> bool {
112 matches!(
113 self,
114 Self::UnderscoreEscapingWithSuffixes | Self::UnderscoreEscapingWithoutSuffixes
115 )
116 }
117
118 pub fn should_add_suffixes(self) -> bool {
119 matches!(
120 self,
121 Self::UnderscoreEscapingWithSuffixes | Self::NoUtf8EscapingWithSuffixes
122 )
123 }
124}
125
126impl std::str::FromStr for OtlpMetricTranslationStrategy {
127 type Err = ();
128
129 fn from_str(value: &str) -> Result<Self, Self::Err> {
130 match value {
131 "UnderscoreEscapingWithSuffixes" => Ok(Self::UnderscoreEscapingWithSuffixes),
132 "UnderscoreEscapingWithoutSuffixes" => Ok(Self::UnderscoreEscapingWithoutSuffixes),
133 "NoUTF8EscapingWithSuffixes" => Ok(Self::NoUtf8EscapingWithSuffixes),
134 "NoTranslation" => Ok(Self::NoTranslation),
135 _ => Err(()),
136 }
137 }
138}
139
140impl std::fmt::Display for OtlpMetricTranslationStrategy {
141 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
142 f.write_str(self.as_str())
143 }
144}