session/protocol_ctx.rs
1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use ahash::HashSet;
16
17/// Protocol specific context
18/// for carrying options(like HTTP header options) within the query context
19#[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/// The context information for OTLP metrics ingestion.
36/// - `promote_all_resource_attrs`
37/// If true, all resource attributes will be promoted to the final table schema.
38/// - `resource_attrs`
39/// If `promote_all_resource_attrs` is true, then the list is an exclude list from `ignore_resource_attrs`.
40/// If `promote_all_resource_attrs` is false, then this list is a include list from `promote_resource_attrs`.
41/// - `promote_scope_attrs`
42/// If true, all scope attributes will be promoted to the final table schema.
43/// Along with the scope name, scope version and scope schema URL.
44/// - `with_metric_engine`
45/// - `is_legacy`
46/// If the user uses OTLP metrics ingestion before v0.16, it uses the old path.
47/// So we call this path 'legacy'.
48/// After v0.16, we store the OTLP metrics using prometheus compatible format, the new path.
49/// The difference is how we convert the input data into the final table schema.
50#[derive(Debug, Clone, Default)]
51pub struct OtlpMetricCtx {
52 pub promote_all_resource_attrs: bool,
53 pub resource_attrs: HashSet<String>,
54 pub promote_scope_attrs: bool,
55 pub with_metric_engine: bool,
56 pub is_legacy: bool,
57 pub metric_type: MetricType,
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 value when initializing the context
69 #[default]
70 Init,
71 NonMonotonicSum,
72 MonotonicSum,
73 Gauge,
74 Histogram,
75 ExponentialHistogram,
76 Summary,
77}