From bab13a35e1086154e17674380dbfd42e13b55c29 Mon Sep 17 00:00:00 2001 From: shuiyisong Date: Sat, 11 Jul 2026 15:31:20 +0800 Subject: [PATCH] fix: prefix name Signed-off-by: shuiyisong --- src/common/query/src/native_histogram.rs | 5 +++-- src/common/query/src/prelude.rs | 22 +++++++++++++++++++ src/metric-engine/src/engine/create.rs | 6 ++--- src/metric-engine/src/engine/put.rs | 7 +++--- src/operator/src/insert.rs | 6 ++--- src/query/src/promql/planner.rs | 5 ++--- src/servers/src/http/prometheus.rs | 3 ++- .../src/http/result/prometheus_resp.rs | 10 ++++----- src/servers/src/prom_remote_write/v2.rs | 16 +++++++------- src/servers/tests/http/prom_store_test.rs | 7 +++--- .../tests/prom_remote_write_v2_test.rs | 8 +++---- 11 files changed, 59 insertions(+), 36 deletions(-) diff --git a/src/common/query/src/native_histogram.rs b/src/common/query/src/native_histogram.rs index 70b6a4e24f..9689d70f4d 100644 --- a/src/common/query/src/native_histogram.rs +++ b/src/common/query/src/native_histogram.rs @@ -34,7 +34,8 @@ use datatypes::data_type::{ConcreteDataType, DataType}; use datatypes::types::{StructField, StructType}; use once_cell::sync::Lazy; -pub const NATIVE_HISTOGRAM_FIELD: &str = "greptime_native_histogram"; +use crate::prelude::greptime_native_histogram; + pub const SCHEMA_FIELD: &str = "schema"; pub const ZERO_THRESHOLD_FIELD: &str = "zero_threshold"; pub const SUM_FIELD: &str = "sum"; @@ -122,7 +123,7 @@ pub fn is_native_histogram_value_type(data_type: &ConcreteDataType) -> bool { } pub fn is_native_histogram_value_schema(name: &str, data_type: &ConcreteDataType) -> bool { - name == NATIVE_HISTOGRAM_FIELD && is_native_histogram_value_type(data_type) + name == greptime_native_histogram() && is_native_histogram_value_type(data_type) } pub const CUSTOM_BUCKETS_SCHEMA: i32 = -53; diff --git a/src/common/query/src/prelude.rs b/src/common/query/src/prelude.rs index 50668bbbb1..59dcf00399 100644 --- a/src/common/query/src/prelude.rs +++ b/src/common/query/src/prelude.rs @@ -26,6 +26,9 @@ static GREPTIME_TIMESTAMP_CELL: OnceCell = OnceCell::new(); /// Default value column name. static GREPTIME_VALUE_CELL: OnceCell = OnceCell::new(); +/// Default native histogram column name. +static GREPTIME_NATIVE_HISTOGRAM_CELL: OnceCell = OnceCell::new(); + pub fn set_default_prefix(prefix: Option<&str>) -> Result<()> { // Strip surrounding double quotes as a defensive measure against upstream // sources (scripts, CI, template engines, incorrect shell escaping) that may @@ -41,11 +44,13 @@ pub fn set_default_prefix(prefix: Option<&str>) -> Result<()> { // use default greptime prefix GREPTIME_TIMESTAMP_CELL.get_or_init(|| GREPTIME_TIMESTAMP.to_string()); GREPTIME_VALUE_CELL.get_or_init(|| GREPTIME_VALUE.to_string()); + GREPTIME_NATIVE_HISTOGRAM_CELL.get_or_init(|| GREPTIME_NATIVE_HISTOGRAM.to_string()); } Some(s) if s.trim().is_empty() => { // use "" to disable prefix GREPTIME_TIMESTAMP_CELL.get_or_init(|| "timestamp".to_string()); GREPTIME_VALUE_CELL.get_or_init(|| "value".to_string()); + GREPTIME_NATIVE_HISTOGRAM_CELL.get_or_init(|| "native_histogram".to_string()); } Some(x) => { ensure!( @@ -54,6 +59,7 @@ pub fn set_default_prefix(prefix: Option<&str>) -> Result<()> { ); GREPTIME_TIMESTAMP_CELL.get_or_init(|| format!("{}_timestamp", x)); GREPTIME_VALUE_CELL.get_or_init(|| format!("{}_value", x)); + GREPTIME_NATIVE_HISTOGRAM_CELL.get_or_init(|| format!("{}_native_histogram", x)); } } Ok(()) @@ -71,10 +77,18 @@ pub fn greptime_value() -> &'static str { GREPTIME_VALUE_CELL.get_or_init(|| GREPTIME_VALUE.to_string()) } +/// Get the default native histogram column name. +/// Returns the configured value, or `greptime_native_histogram` if not set. +pub fn greptime_native_histogram() -> &'static str { + GREPTIME_NATIVE_HISTOGRAM_CELL.get_or_init(|| GREPTIME_NATIVE_HISTOGRAM.to_string()) +} + /// Default timestamp column name constant for backward compatibility. const GREPTIME_TIMESTAMP: &str = "greptime_timestamp"; /// Default value column name constant for backward compatibility. const GREPTIME_VALUE: &str = "greptime_value"; +/// Default native histogram column name. +const GREPTIME_NATIVE_HISTOGRAM: &str = "greptime_native_histogram"; /// Default counter column name for OTLP metrics (legacy mode). pub const GREPTIME_COUNT: &str = "greptime_count"; /// Default physical table name @@ -92,6 +106,7 @@ mod tests { set_default_prefix(None).unwrap(); assert_eq!(greptime_timestamp(), "greptime_timestamp"); assert_eq!(greptime_value(), "greptime_value"); + assert_eq!(greptime_native_histogram(), "greptime_native_histogram"); } #[test] @@ -99,6 +114,7 @@ mod tests { set_default_prefix(Some("")).unwrap(); assert_eq!(greptime_timestamp(), "timestamp"); assert_eq!(greptime_value(), "value"); + assert_eq!(greptime_native_histogram(), "native_histogram"); } #[test] @@ -107,6 +123,7 @@ mod tests { set_default_prefix(Some("\"\"")).unwrap(); assert_eq!(greptime_timestamp(), "timestamp"); assert_eq!(greptime_value(), "value"); + assert_eq!(greptime_native_histogram(), "native_histogram"); } #[test] @@ -114,6 +131,11 @@ mod tests { set_default_prefix(Some("mydb")).unwrap(); assert_eq!(greptime_timestamp(), "mydb_timestamp"); assert_eq!(greptime_value(), "mydb_value"); + assert_eq!(greptime_native_histogram(), "mydb_native_histogram"); + assert!(crate::native_histogram::is_native_histogram_value_schema( + greptime_native_histogram(), + crate::native_histogram::native_histogram_value_type(), + )); } #[test] diff --git a/src/metric-engine/src/engine/create.rs b/src/metric-engine/src/engine/create.rs index a9b5e16bab..accb7caaa8 100644 --- a/src/metric-engine/src/engine/create.rs +++ b/src/metric-engine/src/engine/create.rs @@ -660,8 +660,8 @@ pub(crate) fn region_options_for_metadata_region( mod test { use common_meta::ddl::test_util::assert_column_name_and_id; use common_meta::ddl::utils::{parse_column_metadatas, parse_manifest_infos_from_extensions}; - use common_query::native_histogram::{NATIVE_HISTOGRAM_FIELD, native_histogram_value_type}; - use common_query::prelude::{greptime_timestamp, greptime_value}; + use common_query::native_histogram::native_histogram_value_type; + use common_query::prelude::{greptime_native_histogram, greptime_timestamp, greptime_value}; use store_api::metric_engine_consts::{METRIC_ENGINE_NAME, PHYSICAL_TABLE_METADATA_KEY}; use store_api::region_request::{BatchRegionDdlRequest, RegionRequirements}; @@ -874,7 +874,7 @@ mod test { column_id: 2, semantic_type: SemanticType::Field, column_schema: ColumnSchema::new( - NATIVE_HISTOGRAM_FIELD, + greptime_native_histogram(), native_histogram_value_type().clone(), true, ), diff --git a/src/metric-engine/src/engine/put.rs b/src/metric-engine/src/engine/put.rs index 21865ecdbb..96ed2c3e60 100644 --- a/src/metric-engine/src/engine/put.rs +++ b/src/metric-engine/src/engine/put.rs @@ -767,8 +767,7 @@ mod tests { use common_error::ext::ErrorExt; use common_error::status_code::StatusCode; use common_function::utils::partition_expr_version; - use common_query::native_histogram::NATIVE_HISTOGRAM_FIELD; - use common_query::prelude::{greptime_timestamp, greptime_value}; + use common_query::prelude::{greptime_native_histogram, greptime_timestamp, greptime_value}; use common_recordbatch::RecordBatches; use datatypes::prelude::ConcreteDataType; use datatypes::schema::{ColumnDefaultConstraint, ColumnSchema}; @@ -1014,7 +1013,7 @@ mod tests { options: None, }; let histogram = PbColumnSchema { - column_name: NATIVE_HISTOGRAM_FIELD.to_string(), + column_name: greptime_native_histogram().to_string(), datatype: ColumnDataType::Struct as i32, semantic_type: SemanticType::Field as _, datatype_extension: None, @@ -1066,7 +1065,7 @@ mod tests { }; let value_idx = column_index(&merged_request, greptime_value()); - let histogram_idx = column_index(&merged_request, NATIVE_HISTOGRAM_FIELD); + let histogram_idx = column_index(&merged_request, greptime_native_histogram()); assert!(matches!( merged_request.rows[0].values[value_idx].value_data, Some(ValueData::F64Value(_)) diff --git a/src/operator/src/insert.rs b/src/operator/src/insert.rs index c3e924eaef..837fad59e8 100644 --- a/src/operator/src/insert.rs +++ b/src/operator/src/insert.rs @@ -38,9 +38,9 @@ use common_meta::node_manager::{AffectedRows, NodeManagerRef}; use common_meta::peer::Peer; use common_query::Output; use common_query::native_histogram::{ - NATIVE_HISTOGRAM_FIELD, is_native_histogram_value_schema, native_histogram_value_type, + is_native_histogram_value_schema, native_histogram_value_type, }; -use common_query::prelude::{greptime_timestamp, greptime_value}; +use common_query::prelude::{greptime_native_histogram, greptime_timestamp, greptime_value}; use common_telemetry::tracing_context::TracingContext; use common_telemetry::{error, info, warn}; use datatypes::schema::SkippingIndexOptions; @@ -1143,7 +1143,7 @@ fn request_is_native_histogram(request_schema: &[ColumnSchema]) -> bool { }; fields.next().is_none() - && col.column_name == NATIVE_HISTOGRAM_FIELD + && col.column_name == greptime_native_histogram() && api::helper::is_column_type_value_eq( col.datatype, col.datatype_extension.clone(), diff --git a/src/query/src/promql/planner.rs b/src/query/src/promql/planner.rs index 419cd794dd..1a21d84914 100644 --- a/src/query/src/promql/planner.rs +++ b/src/query/src/promql/planner.rs @@ -5591,8 +5591,7 @@ mod test { use catalog::memory::{MemoryCatalogManager, new_memory_catalog_manager}; use common_base::Plugins; use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME}; - use common_query::native_histogram::NATIVE_HISTOGRAM_FIELD; - use common_query::prelude::greptime_timestamp; + use common_query::prelude::{greptime_native_histogram, greptime_timestamp}; use common_query::test_util::DummyDecoder; use datafusion::arrow::array::{ Array, Float64Array, Int64Array, StringArray, TimestampMillisecondArray, @@ -6081,7 +6080,7 @@ mod test { ) .with_time_index(true), ColumnSchema::new( - NATIVE_HISTOGRAM_FIELD.to_string(), + greptime_native_histogram().to_string(), native_histogram_value_type().clone(), true, ), diff --git a/src/servers/src/http/prometheus.rs b/src/servers/src/http/prometheus.rs index 0db5872302..449daf0d16 100644 --- a/src/servers/src/http/prometheus.rs +++ b/src/servers/src/http/prometheus.rs @@ -2286,6 +2286,7 @@ mod tests { use catalog::{RegisterSchemaRequest, RegisterTableRequest}; use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME}; use common_query::native_histogram::native_histogram_value_type; + use common_query::prelude::greptime_native_histogram; use datatypes::prelude::ConcreteDataType; use datatypes::schema::{ColumnSchema, Schema}; use promql_parser::parser::value::ValueType; @@ -3268,7 +3269,7 @@ mod tests { let schema = Arc::new(Schema::new(vec![ ColumnSchema::new("host", ConcreteDataType::string_datatype(), false), ColumnSchema::new( - "greptime_native_histogram", + greptime_native_histogram(), native_histogram_value_type().clone(), true, ), diff --git a/src/servers/src/http/result/prometheus_resp.rs b/src/servers/src/http/result/prometheus_resp.rs index 70a3e1aa8a..f110ddb973 100644 --- a/src/servers/src/http/result/prometheus_resp.rs +++ b/src/servers/src/http/result/prometheus_resp.rs @@ -456,9 +456,9 @@ mod tests { use std::sync::Arc; use common_query::native_histogram::{ - NATIVE_HISTOGRAM_FIELD, NativeHistogram, Span, build_histogram_array, - native_histogram_value_type, + NativeHistogram, Span, build_histogram_array, native_histogram_value_type, }; + use common_query::prelude::greptime_native_histogram; use common_query::{Output, OutputData, OutputMeta}; use common_recordbatch::{RecordBatch, RecordBatches}; use datatypes::data_type::ConcreteDataType; @@ -636,7 +636,7 @@ mod tests { ColumnSchema::new("job", ConcreteDataType::string_datatype(), false), ColumnSchema::new("value", ConcreteDataType::float64_datatype(), true), ColumnSchema::new( - NATIVE_HISTOGRAM_FIELD, + greptime_native_histogram(), native_histogram_value_type().clone(), true, ), @@ -682,7 +682,7 @@ mod tests { ColumnSchema::new("job", ConcreteDataType::string_datatype(), false), ColumnSchema::new("value", ConcreteDataType::float64_datatype(), true), ColumnSchema::new( - NATIVE_HISTOGRAM_FIELD, + greptime_native_histogram(), native_histogram_value_type().clone(), true, ), @@ -728,7 +728,7 @@ mod tests { .with_time_index(true), ColumnSchema::new("job", ConcreteDataType::string_datatype(), false), ColumnSchema::new( - NATIVE_HISTOGRAM_FIELD, + greptime_native_histogram(), native_histogram_value_type().clone(), true, ), diff --git a/src/servers/src/prom_remote_write/v2.rs b/src/servers/src/prom_remote_write/v2.rs index 2bb381a0d3..6672c61c3c 100644 --- a/src/servers/src/prom_remote_write/v2.rs +++ b/src/servers/src/prom_remote_write/v2.rs @@ -27,7 +27,7 @@ use api::v1::{ColumnSchema, ListValue, RowInsertRequest, Rows, SemanticType, Val use bytes::Bytes; use common_grpc::precision::Precision; use common_query::native_histogram::*; -use common_query::prelude::{greptime_timestamp, greptime_value}; +use common_query::prelude::{greptime_native_histogram, greptime_timestamp, greptime_value}; use pipeline::{ContextOpt, ContextReq}; use prost::Message; use snafu::{OptionExt, ResultExt, ensure}; @@ -275,7 +275,7 @@ fn native_histogram_column_schema() -> ColumnSchema { .into_parts(); ColumnSchema { - column_name: NATIVE_HISTOGRAM_FIELD.to_string(), + column_name: greptime_native_histogram().to_string(), datatype: datatype as i32, semantic_type: SemanticType::Field as i32, datatype_extension, @@ -631,7 +631,7 @@ fn ensure_no_internal_histogram_labels(tags: &PromTags) -> Result<()> { // The histogram field column is generated from the protobuf payload. for (name, _) in tags { ensure!( - name != NATIVE_HISTOGRAM_FIELD, + name != greptime_native_histogram(), error::InvalidPromRemoteRequestSnafu { msg: format!( "remote write v2 label `{name}` conflicts with an internal native histogram label" @@ -1085,7 +1085,7 @@ mod tests { "internal histogram label on samples", request_with_sample(vec![ (METRIC_NAME_LABEL, "metric"), - (NATIVE_HISTOGRAM_FIELD, "user_value"), + (greptime_native_histogram(), "user_value"), ]), "conflicts with an internal native histogram label", )); @@ -1313,7 +1313,7 @@ mod tests { .iter() .map(|col| col.column_name.as_str()) .collect::>(), - vec![greptime_timestamp(), NATIVE_HISTOGRAM_FIELD] + vec![greptime_timestamp(), greptime_native_histogram()] ); assert_eq!( rows.rows[0].values[0].value_data, @@ -1356,7 +1356,7 @@ mod tests { let mut request = test_util::request_with_labels_and_samples( vec![ (METRIC_NAME_LABEL, "metric"), - (NATIVE_HISTOGRAM_FIELD, "user_value"), + (greptime_native_histogram(), "user_value"), ], vec![], ); @@ -1421,7 +1421,7 @@ mod tests { .iter() .map(|col| col.column_name.as_str()) .collect::>(), - vec![greptime_timestamp(), NATIVE_HISTOGRAM_FIELD] + vec![greptime_timestamp(), greptime_native_histogram()] ); assert_eq!( @@ -1496,7 +1496,7 @@ mod tests { } fn histogram_field_value(rows: &Rows, row_idx: usize, field_name: &str) -> Option { - let histogram_idx = column_index(&rows.schema, NATIVE_HISTOGRAM_FIELD); + let histogram_idx = column_index(&rows.schema, greptime_native_histogram()); let Some(ValueData::StructValue(histogram)) = &rows.rows[row_idx].values[histogram_idx].value_data else { diff --git a/src/servers/tests/http/prom_store_test.rs b/src/servers/tests/http/prom_store_test.rs index 3c4cfbe4e9..2d573a3bfb 100644 --- a/src/servers/tests/http/prom_store_test.rs +++ b/src/servers/tests/http/prom_store_test.rs @@ -28,8 +28,9 @@ use async_trait::async_trait; use axum::Router; use axum::http::HeaderMap; use common_query::Output; -use common_query::native_histogram::NATIVE_HISTOGRAM_FIELD; -use common_query::prelude::{GREPTIME_PHYSICAL_TABLE, greptime_timestamp, greptime_value}; +use common_query::prelude::{ + GREPTIME_PHYSICAL_TABLE, greptime_native_histogram, greptime_timestamp, greptime_value, +}; use common_test_util::ports; use datafusion_expr::LogicalPlan; use prost::Message; @@ -675,7 +676,7 @@ async fn test_prometheus_remote_write_v2_writes_histogram_only_series() { assert!( rows.schema .iter() - .any(|column| column.column_name == NATIVE_HISTOGRAM_FIELD + .any(|column| column.column_name == greptime_native_histogram() && column.datatype == ColumnDataType::Struct as i32) ); assert!(write_rx.try_recv().is_err()); diff --git a/src/servers/tests/prom_remote_write_v2_test.rs b/src/servers/tests/prom_remote_write_v2_test.rs index c06291b437..a44583dccd 100644 --- a/src/servers/tests/prom_remote_write_v2_test.rs +++ b/src/servers/tests/prom_remote_write_v2_test.rs @@ -18,10 +18,10 @@ use api::v1::value::ValueData; use api::v1::{ColumnSchema, Rows}; use bytes::Bytes; use common_query::native_histogram::{ - COUNT_U64_FIELD, NATIVE_HISTOGRAM_FIELD, NATIVE_HISTOGRAM_FIELD_NAMES, - POSITIVE_BUCKETS_F64_FIELD, POSITIVE_BUCKETS_I64_FIELD, POSITIVE_SPAN_OFFSETS_FIELD, - SCHEMA_FIELD, + COUNT_U64_FIELD, NATIVE_HISTOGRAM_FIELD_NAMES, POSITIVE_BUCKETS_F64_FIELD, + POSITIVE_BUCKETS_I64_FIELD, POSITIVE_SPAN_OFFSETS_FIELD, SCHEMA_FIELD, }; +use common_query::prelude::greptime_native_histogram; use servers::prom_remote_write::v2::test_util as remote_write_v2; #[test] @@ -126,7 +126,7 @@ fn column_index(schema: &[ColumnSchema], column_name: &str) -> usize { } fn histogram_field_value(rows: &Rows, row_idx: usize, field_name: &str) -> Option { - let histogram_idx = column_index(&rows.schema, NATIVE_HISTOGRAM_FIELD); + let histogram_idx = column_index(&rows.schema, greptime_native_histogram()); let Some(ValueData::StructValue(histogram)) = &rows.rows[row_idx].values[histogram_idx].value_data else {