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)]
48pub struct OtlpMetricCtx {
49 pub promote_all_resource_attrs: bool,
50 pub resource_attrs: HashSet<String>,
51 pub promote_scope_attrs: bool,
52 pub with_metric_engine: bool,
53 pub resource_info: bool,
56 pub metric_type: MetricType,
57 pub metric_translation_strategy: OtlpMetricTranslationStrategy,
58}
59
60impl OtlpMetricCtx {
61 pub fn set_metric_type(&mut self, metric_type: MetricType) {
62 self.metric_type = metric_type;
63 }
64}
65
66#[derive(Debug, Clone, Default)]
67pub enum MetricType {
68 #[default]
70 Init,
71 NonMonotonicSum,
72 MonotonicSum,
73 Gauge,
74 Histogram,
75 ExponentialHistogram,
76 Summary,
77}
78
79#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
80pub enum OtlpMetricTranslationStrategy {
81 #[default]
82 UnderscoreEscapingWithSuffixes,
83 UnderscoreEscapingWithoutSuffixes,
84 NoUtf8EscapingWithSuffixes,
85 NoTranslation,
86}
87
88impl OtlpMetricTranslationStrategy {
89 pub const VALUES: [&'static str; 4] = [
90 "UnderscoreEscapingWithSuffixes",
91 "UnderscoreEscapingWithoutSuffixes",
92 "NoUTF8EscapingWithSuffixes",
93 "NoTranslation",
94 ];
95
96 pub fn as_str(self) -> &'static str {
97 match self {
98 Self::UnderscoreEscapingWithSuffixes => "UnderscoreEscapingWithSuffixes",
99 Self::UnderscoreEscapingWithoutSuffixes => "UnderscoreEscapingWithoutSuffixes",
100 Self::NoUtf8EscapingWithSuffixes => "NoUTF8EscapingWithSuffixes",
101 Self::NoTranslation => "NoTranslation",
102 }
103 }
104
105 pub fn should_escape(self) -> bool {
106 matches!(
107 self,
108 Self::UnderscoreEscapingWithSuffixes | Self::UnderscoreEscapingWithoutSuffixes
109 )
110 }
111
112 pub fn should_add_suffixes(self) -> bool {
113 matches!(
114 self,
115 Self::UnderscoreEscapingWithSuffixes | Self::NoUtf8EscapingWithSuffixes
116 )
117 }
118}
119
120impl std::str::FromStr for OtlpMetricTranslationStrategy {
121 type Err = ();
122
123 fn from_str(value: &str) -> Result<Self, Self::Err> {
124 match value {
125 "UnderscoreEscapingWithSuffixes" => Ok(Self::UnderscoreEscapingWithSuffixes),
126 "UnderscoreEscapingWithoutSuffixes" => Ok(Self::UnderscoreEscapingWithoutSuffixes),
127 "NoUTF8EscapingWithSuffixes" => Ok(Self::NoUtf8EscapingWithSuffixes),
128 "NoTranslation" => Ok(Self::NoTranslation),
129 _ => Err(()),
130 }
131 }
132}
133
134impl std::fmt::Display for OtlpMetricTranslationStrategy {
135 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
136 f.write_str(self.as_str())
137 }
138}