feat(ingestion): configurable time index unit for auto-created physical metric tables (#10189)

* feat(ingestion): configurable time index unit for auto-created physical metric tables

Auto-created physical metric tables hardcoded a millisecond time index.
Add an `auto_create_physical_table_timestamp_unit` option (frontend and
standalone configs, default "Millisecond") that selects the time index
unit for physical metric tables created by auto table creation. New
logical tables created under such a physical table inherit its unit, so
Prometheus remote write, OTLP metrics, and other metric-engine ingestion
paths write timestamps in the configured unit.

The option threads through all auto-create sites: the operator inserter's
`create_physical_table_on_demand`, the frontend instance's batched
logical-table flush path (`create_metric_physical_table_if_missing`),
the logical-table batcher's unit alignment fallback, and the OTLP metric
preflight validation unit. Millisecond remains the default, so existing
behavior is unchanged unless configured.

Signed-off-by: Ning Sun <sunning@greptime.com>

* fix(otlp): match default physical schema to configured timestamp unit

Signed-off-by: Ning Sun <sunning@greptime.com>

---------

Signed-off-by: Ning Sun <sunning@greptime.com>
This commit is contained in:
Ning Sun
2026-11-16 17:00:51 +00:00
committed by GitHub
parent 7e76d28908
commit c679ca5fdc
20 changed files with 389 additions and 19 deletions
+15 -1
View File
@@ -120,6 +120,11 @@ pub struct Inserter {
/// When `false`, missing tables are never auto-created regardless of the
/// per-request `auto_create_table` hint. When `true`, the hint still applies.
auto_create_table: bool,
/// Time index unit for physical metric tables created by auto table creation.
/// New logical tables created under such a physical table inherit its unit,
/// so all metric-engine ingestion paths write timestamps in this unit.
/// Defaults to milliseconds for compatibility.
auto_create_physical_table_timestamp_unit: TimeUnit,
pending_rows_batcher: Option<Arc<dyn PendingRowsBatcher>>,
/// Rows handed to detached flow mirror tasks that have not finished yet.
/// Bounds how much row data in-flight mirror writes may keep alive, see
@@ -342,11 +347,18 @@ impl Inserter {
node_manager,
table_flownode_set_cache,
auto_create_table,
auto_create_physical_table_timestamp_unit: TimeUnit::Millisecond,
pending_rows_batcher: None,
mirror_pending_rows: Arc::new(AtomicU64::new(0)),
}
}
/// Sets the time index unit for auto-created physical metric tables.
pub fn with_auto_create_physical_table_timestamp_unit(mut self, unit: TimeUnit) -> Self {
self.auto_create_physical_table_timestamp_unit = unit;
self
}
/// Installs the shared dispatcher used by direct writes and batch flushes.
pub fn with_write_dispatcher(mut self, dispatcher: WriteDispatcherRef) -> Self {
self.write_dispatcher = dispatcher;
@@ -1868,7 +1880,9 @@ impl Inserter {
let default_schema = vec![
ColumnSchema {
column_name: greptime_timestamp().to_string(),
datatype: ColumnDataType::TimestampMillisecond as _,
datatype: api::helper::timestamp_datatype(
self.auto_create_physical_table_timestamp_unit,
) as _,
semantic_type: SemanticType::Timestamp as _,
datatype_extension: None,
options: None,
+11 -12
View File
@@ -118,12 +118,9 @@ impl Inserter {
tables.insert(backing.clone(), table);
}
physical_columns.entry(backing.as_str()).or_insert_with(|| {
PhysicalColumns::new(
tables[backing]
.as_ref()
.map(table_columns)
.unwrap_or_else(default_physical_columns),
)
PhysicalColumns::new(tables[backing].as_ref().map(table_columns).unwrap_or_else(
|| default_physical_columns(self.auto_create_physical_table_timestamp_unit),
))
});
}
// Match ordinary insertion: impure defaults are evaluated once per table
@@ -176,7 +173,9 @@ impl Inserter {
let unit = target
.and_then(table_time_index_unit)
.or_else(|| physical.and_then(table_time_index_unit))
.unwrap_or(TimeUnit::Millisecond);
// The physical table will be auto-created in the configured
// unit, so validate its rows in that unit as well.
.unwrap_or(self.auto_create_physical_table_timestamp_unit);
if let Some(rows) = &mut request.rows {
convert_rows_time_unit(rows, unit)?;
}
@@ -378,13 +377,13 @@ fn table_columns(table: &TableRef) -> Vec<(DataColumn, SemanticType)> {
.collect()
}
fn default_physical_columns() -> Vec<(DataColumn, SemanticType)> {
fn default_physical_columns(unit: TimeUnit) -> Vec<(DataColumn, SemanticType)> {
use datatypes::prelude::ConcreteDataType;
vec![
(
DataColumn::new(
greptime_timestamp(),
ConcreteDataType::timestamp_millisecond_datatype(),
ConcreteDataType::timestamp_datatype(unit),
false,
)
.with_time_index(true),
@@ -698,7 +697,7 @@ mod tests {
#[test]
fn test_preflight_omissions_defaults_and_explicit_nulls() {
let mut columns = default_physical_columns();
let mut columns = default_physical_columns(TimeUnit::Millisecond);
columns.push((
DataColumn::new("host", ConcreteDataType::string_datatype(), false)
.with_default_constraint(Some(ColumnDefaultConstraint::Value(DataValue::String(
@@ -739,7 +738,7 @@ mod tests {
#[test]
fn test_preflight_existing_columns_and_physical_definitions() {
let columns = default_physical_columns();
let columns = default_physical_columns(TimeUnit::Millisecond);
let mut rows = Rows {
schema: vec![ColumnSchema {
column_name: greptime_timestamp().into(),
@@ -805,7 +804,7 @@ mod tests {
(defaulted, None),
(impure, Some("impure default for physical field `impure`")),
] {
let mut columns = default_physical_columns();
let mut columns = default_physical_columns(TimeUnit::Millisecond);
columns.extend((0..1024).map(|index| {
(
DataColumn::new(