mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-23 16:30:39 +00:00
refactor(otlp_metric): make otlp metric compatible with promql (#6543)
* chore: tmp save Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: minor update * chore: remove metric metadata and introduce shared attrs Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: replace . with _ in metric name Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: minor update & fix tests Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: add legacy mode param to otlp metrics Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: update test Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: update test & fix Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: add automatically legacy check for otlp metrics Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: fix clippy Signed-off-by: shuiyisong <xixing.sys@gmail.com> * fix: typos Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: insert table options in compat mode & add test Signed-off-by: shuiyisong <xixing.sys@gmail.com> * fix: check table options consistency Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: update test and add comments Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: minor tags update Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: minor update about scope labeling Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: update opts using header & update test Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: minor code refactor Signed-off-by: shuiyisong <xixing.sys@gmail.com> * chore: fix cr issue Signed-off-by: shuiyisong <xixing.sys@gmail.com> --------- Signed-off-by: shuiyisong <xixing.sys@gmail.com>
This commit is contained in:
@@ -31,6 +31,7 @@ use common_time::Timezone;
|
||||
use derive_builder::Builder;
|
||||
use sql::dialect::{Dialect, GenericDialect, GreptimeDbDialect, MySqlDialect, PostgreSqlDialect};
|
||||
|
||||
use crate::protocol_ctx::ProtocolCtx;
|
||||
use crate::session_config::{PGByteaOutputValue, PGDateOrder, PGDateTimeStyle};
|
||||
use crate::{MutableInner, ReadPreference};
|
||||
|
||||
@@ -70,6 +71,9 @@ pub struct QueryContext {
|
||||
/// Connection information
|
||||
#[builder(default)]
|
||||
conn_info: ConnInfo,
|
||||
/// Protocol specific context
|
||||
#[builder(default)]
|
||||
protocol_ctx: ProtocolCtx,
|
||||
}
|
||||
|
||||
/// This fields hold data that is only valid to current query context
|
||||
@@ -447,6 +451,14 @@ impl QueryContext {
|
||||
pub fn conn_info(&self) -> &ConnInfo {
|
||||
&self.conn_info
|
||||
}
|
||||
|
||||
pub fn protocol_ctx(&self) -> &ProtocolCtx {
|
||||
&self.protocol_ctx
|
||||
}
|
||||
|
||||
pub fn set_protocol_ctx(&mut self, protocol_ctx: ProtocolCtx) {
|
||||
self.protocol_ctx = protocol_ctx;
|
||||
}
|
||||
}
|
||||
|
||||
impl QueryContextBuilder {
|
||||
@@ -470,6 +482,7 @@ impl QueryContextBuilder {
|
||||
channel,
|
||||
process_id: self.process_id.unwrap_or_default(),
|
||||
conn_info: self.conn_info.unwrap_or_default(),
|
||||
protocol_ctx: self.protocol_ctx.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
pub mod context;
|
||||
pub mod hints;
|
||||
pub mod protocol_ctx;
|
||||
pub mod session_config;
|
||||
pub mod table_name;
|
||||
|
||||
|
||||
39
src/session/src/protocol_ctx.rs
Normal file
39
src/session/src/protocol_ctx.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 2023 Greptime Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/// Protocol specific context
|
||||
/// for carrying options(like HTTP header options) within the query context
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub enum ProtocolCtx {
|
||||
#[default]
|
||||
None,
|
||||
OtlpMetric(OtlpMetricCtx),
|
||||
}
|
||||
|
||||
impl ProtocolCtx {
|
||||
pub fn get_otlp_metric_ctx(&self) -> Option<&OtlpMetricCtx> {
|
||||
match self {
|
||||
ProtocolCtx::None => None,
|
||||
ProtocolCtx::OtlpMetric(opt) => Some(opt),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct OtlpMetricCtx {
|
||||
pub promote_all_resource_attrs: bool,
|
||||
pub promote_scope_attrs: bool,
|
||||
pub with_metric_engine: bool,
|
||||
pub is_legacy: bool,
|
||||
}
|
||||
Reference in New Issue
Block a user