table/requests/
semantic.rs1pub const SEMANTIC_PREFIX: &str = "greptime.semantic.";
29
30pub const SEMANTIC_PER_TABLE_INDEX_KEY: &str = "greptime.internal.semantic.per_table_index";
35
36pub const SEMANTIC_SIGNAL_TYPE: &str = "greptime.semantic.signal_type";
41pub const SEMANTIC_SOURCE: &str = "greptime.semantic.source";
43pub const SEMANTIC_SOURCE_VERSION: &str = "greptime.semantic.source_version";
45pub const SEMANTIC_PIPELINE: &str = "greptime.semantic.pipeline";
47
48pub const SEMANTIC_TRACE_CONVENTIONS: &str = "greptime.semantic.trace.conventions";
53pub const SEMANTIC_TRACE_HAS_EVENTS: &str = "greptime.semantic.trace.has_events";
55pub const SEMANTIC_TRACE_HAS_LINKS: &str = "greptime.semantic.trace.has_links";
57
58pub const SEMANTIC_METRIC_TYPE: &str = "greptime.semantic.metric.type";
63pub const SEMANTIC_METRIC_UNIT: &str = "greptime.semantic.metric.unit";
65pub const SEMANTIC_METRIC_TEMPORALITY: &str = "greptime.semantic.metric.temporality";
67pub const SEMANTIC_METRIC_MONOTONIC: &str = "greptime.semantic.metric.monotonic";
69pub const SEMANTIC_METRIC_METADATA_QUALITY: &str = "greptime.semantic.metric.metadata_quality";
72pub const SEMANTIC_METRIC_ORIGINAL_NAME: &str = "greptime.semantic.metric.original_name";
74
75pub const SEMANTIC_LOG_SEVERITY_SCHEME: &str = "greptime.semantic.log.severity_scheme";
79pub const SEMANTIC_LOG_BODY_FORMAT: &str = "greptime.semantic.log.body_format";
81
82pub const SEMANTIC_RESOURCE_ATTRIBUTES_PRESERVED: &str =
86 "greptime.semantic.resource.attributes_preserved";
87pub const SEMANTIC_RESOURCE_ATTRIBUTES_DROPPED: &str =
89 "greptime.semantic.resource.attributes_dropped";
90pub const SEMANTIC_SCOPE_PRESERVED: &str = "greptime.semantic.scope.preserved";
92
93pub const SIGNAL_TYPE_TRACE: &str = "trace";
96pub const SIGNAL_TYPE_LOG: &str = "log";
97pub const SIGNAL_TYPE_METRIC: &str = "metric";
98pub const SIGNAL_TYPE_EVENT: &str = "event";
99
100pub const SOURCE_OPENTELEMETRY: &str = "opentelemetry";
101pub const SOURCE_PROMETHEUS: &str = "prometheus";
102
103pub const METADATA_QUALITY_DECLARED: &str = "declared";
104pub const METADATA_QUALITY_INFERRED: &str = "inferred";
105
106pub const SEMANTIC_VALUE_UNKNOWN: &str = "unknown";
108pub const SEMANTIC_VALUE_MIXED: &str = "mixed";
110
111pub const SEMANTIC_OPTION_KEYS: &[&str] = &[
116 SEMANTIC_SIGNAL_TYPE,
117 SEMANTIC_SOURCE,
118 SEMANTIC_SOURCE_VERSION,
119 SEMANTIC_PIPELINE,
120 SEMANTIC_TRACE_CONVENTIONS,
121 SEMANTIC_TRACE_HAS_EVENTS,
122 SEMANTIC_TRACE_HAS_LINKS,
123 SEMANTIC_METRIC_TYPE,
124 SEMANTIC_METRIC_UNIT,
125 SEMANTIC_METRIC_TEMPORALITY,
126 SEMANTIC_METRIC_MONOTONIC,
127 SEMANTIC_METRIC_METADATA_QUALITY,
128 SEMANTIC_METRIC_ORIGINAL_NAME,
129 SEMANTIC_LOG_SEVERITY_SCHEME,
130 SEMANTIC_LOG_BODY_FORMAT,
131 SEMANTIC_RESOURCE_ATTRIBUTES_PRESERVED,
132 SEMANTIC_RESOURCE_ATTRIBUTES_DROPPED,
133 SEMANTIC_SCOPE_PRESERVED,
134];
135
136pub fn is_semantic_option_key(key: &str) -> bool {
142 SEMANTIC_OPTION_KEYS.contains(&key)
143}
144
145pub fn validate_semantic_option(key: &str, value: &str) -> bool {
153 match key {
154 SEMANTIC_SOURCE_VERSION
155 | SEMANTIC_PIPELINE
156 | SEMANTIC_METRIC_UNIT
157 | SEMANTIC_METRIC_ORIGINAL_NAME
158 | SEMANTIC_TRACE_CONVENTIONS
159 | SEMANTIC_RESOURCE_ATTRIBUTES_PRESERVED => !value.is_empty(),
160
161 SEMANTIC_SIGNAL_TYPE => matches!(value, "trace" | "log" | "metric" | "event" | "unknown"),
162 SEMANTIC_SOURCE => matches!(
163 value,
164 "opentelemetry"
165 | "prometheus"
166 | "elasticsearch"
167 | "loki"
168 | "custom"
169 | "mixed"
170 | "unknown"
171 ),
172 SEMANTIC_METRIC_TYPE => matches!(
173 value,
174 "counter"
175 | "gauge"
176 | "histogram"
177 | "summary"
178 | "updown_counter"
179 | "gauge_histogram"
180 | "info"
181 | "stateset"
182 | "mixed"
183 | "unknown"
184 ),
185 SEMANTIC_METRIC_TEMPORALITY => {
186 matches!(value, "cumulative" | "delta" | "mixed" | "unknown")
187 }
188 SEMANTIC_METRIC_MONOTONIC
189 | SEMANTIC_TRACE_HAS_EVENTS
190 | SEMANTIC_TRACE_HAS_LINKS
191 | SEMANTIC_RESOURCE_ATTRIBUTES_DROPPED
192 | SEMANTIC_SCOPE_PRESERVED => matches!(value, "true" | "false" | "unknown"),
193 SEMANTIC_METRIC_METADATA_QUALITY => matches!(value, "declared" | "inferred" | "unknown"),
194 SEMANTIC_LOG_SEVERITY_SCHEME => matches!(value, "otlp" | "syslog" | "custom" | "unknown"),
195 SEMANTIC_LOG_BODY_FORMAT => matches!(value, "string" | "json" | "mixed" | "unknown"),
196
197 _ => false,
198 }
199}
200
201#[cfg(test)]
202mod tests {
203 use super::*;
204
205 #[test]
206 fn test_is_semantic_option_key() {
207 assert!(is_semantic_option_key(SEMANTIC_SIGNAL_TYPE));
208 assert!(is_semantic_option_key(SEMANTIC_METRIC_TYPE));
209
210 assert!(!is_semantic_option_key("greptime.semantic.future.key"));
212 assert!(!is_semantic_option_key("greptime.semantic.unknown_key"));
213 assert!(!is_semantic_option_key("greptime.semanticx"));
215 assert!(!is_semantic_option_key("semantic.signal_type"));
216 assert!(!is_semantic_option_key("table_data_model"));
217 assert!(!is_semantic_option_key(SEMANTIC_PER_TABLE_INDEX_KEY));
219 }
220
221 #[test]
222 fn test_validate_semantic_option() {
223 assert!(validate_semantic_option(SEMANTIC_SIGNAL_TYPE, "metric"));
225 assert!(!validate_semantic_option(SEMANTIC_SIGNAL_TYPE, "spans"));
226 assert!(validate_semantic_option(SEMANTIC_METRIC_TYPE, "counter"));
227 assert!(validate_semantic_option(SEMANTIC_METRIC_TYPE, "mixed"));
228 assert!(!validate_semantic_option(SEMANTIC_METRIC_TYPE, "bogus"));
229
230 assert!(validate_semantic_option(SEMANTIC_TRACE_HAS_EVENTS, "true"));
232 assert!(!validate_semantic_option(SEMANTIC_TRACE_HAS_EVENTS, "yes"));
233 assert!(validate_semantic_option(
234 SEMANTIC_METRIC_TEMPORALITY,
235 "unknown"
236 ));
237 assert!(validate_semantic_option(SEMANTIC_METRIC_UNIT, "By"));
238 assert!(!validate_semantic_option(SEMANTIC_METRIC_UNIT, ""));
239
240 assert!(!validate_semantic_option(
242 "greptime.semantic.future.key",
243 "x"
244 ));
245
246 assert!(validate_semantic_option(
248 SEMANTIC_SIGNAL_TYPE,
249 SIGNAL_TYPE_TRACE
250 ));
251 assert!(validate_semantic_option(
252 SEMANTIC_SIGNAL_TYPE,
253 SIGNAL_TYPE_METRIC
254 ));
255 assert!(validate_semantic_option(
256 SEMANTIC_SIGNAL_TYPE,
257 SIGNAL_TYPE_LOG
258 ));
259 assert!(validate_semantic_option(
260 SEMANTIC_SOURCE,
261 SOURCE_OPENTELEMETRY
262 ));
263 assert!(validate_semantic_option(SEMANTIC_SOURCE, SOURCE_PROMETHEUS));
264 assert!(validate_semantic_option(
265 SEMANTIC_METRIC_METADATA_QUALITY,
266 METADATA_QUALITY_INFERRED
267 ));
268 assert!(validate_semantic_option(
269 SEMANTIC_TRACE_CONVENTIONS,
270 SEMANTIC_VALUE_UNKNOWN
271 ));
272 for key in SEMANTIC_OPTION_KEYS {
274 assert!(
275 !validate_semantic_option(key, ""),
276 "empty value should never validate for {key}"
277 );
278 }
279 }
280}