From c1d18d9980f18c98ecdfa3842507f11f0c721d29 Mon Sep 17 00:00:00 2001 From: Weny Xu Date: Wed, 26 Feb 2025 22:40:09 +0900 Subject: [PATCH] fix(prom): preserve the order of series in `PromQueryResult` (#5601) fix(prom): keep the order of tags --- Cargo.lock | 51 ++++++++++--------- src/servers/Cargo.toml | 1 + .../src/http/result/prometheus_resp.rs | 7 ++- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 60b4f794a2c..2356c7e5232 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -432,7 +432,7 @@ dependencies = [ "arrow-schema", "chrono", "half", - "indexmap 2.6.0", + "indexmap 2.7.1", "lexical-core", "num", "serde", @@ -1475,7 +1475,7 @@ version = "0.13.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6026d8cd82ada8bbcfe337805dd1eb6afdc9e80fa4d57e977b3a36315e0c5525" dependencies = [ - "indexmap 2.6.0", + "indexmap 2.7.1", "lazy_static", "num-traits", "regex", @@ -2976,7 +2976,7 @@ dependencies = [ "chrono", "half", "hashbrown 0.14.5", - "indexmap 2.6.0", + "indexmap 2.7.1", "libc", "object_store", "parquet", @@ -3036,7 +3036,7 @@ dependencies = [ "datafusion-functions-aggregate-common", "datafusion-functions-window-common", "datafusion-physical-expr-common", - "indexmap 2.6.0", + "indexmap 2.7.1", "paste", "recursive", "serde_json", @@ -3158,7 +3158,7 @@ dependencies = [ "datafusion-physical-expr-common", "datafusion-physical-plan", "half", - "indexmap 2.6.0", + "indexmap 2.7.1", "log", "parking_lot 0.12.3", "paste", @@ -3209,7 +3209,7 @@ dependencies = [ "datafusion-common", "datafusion-expr", "datafusion-physical-expr", - "indexmap 2.6.0", + "indexmap 2.7.1", "itertools 0.13.0", "log", "recursive", @@ -3234,7 +3234,7 @@ dependencies = [ "datafusion-physical-expr-common", "half", "hashbrown 0.14.5", - "indexmap 2.6.0", + "indexmap 2.7.1", "itertools 0.13.0", "log", "paste", @@ -3293,7 +3293,7 @@ dependencies = [ "futures", "half", "hashbrown 0.14.5", - "indexmap 2.6.0", + "indexmap 2.7.1", "itertools 0.13.0", "log", "once_cell", @@ -3313,7 +3313,7 @@ dependencies = [ "arrow-schema", "datafusion-common", "datafusion-expr", - "indexmap 2.6.0", + "indexmap 2.7.1", "log", "recursive", "regex", @@ -4722,7 +4722,7 @@ dependencies = [ "futures-sink", "futures-util", "http 0.2.12", - "indexmap 2.6.0", + "indexmap 2.7.1", "slab", "tokio", "tokio-util", @@ -4741,7 +4741,7 @@ dependencies = [ "futures-core", "futures-sink", "http 1.1.0", - "indexmap 2.6.0", + "indexmap 2.7.1", "slab", "tokio", "tokio-util", @@ -5588,9 +5588,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.6.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652" dependencies = [ "equivalent", "hashbrown 0.15.2", @@ -5604,7 +5604,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "232929e1d75fe899576a3d5c7416ad0d88dbfbb3c3d6aa00873a7408a50ddb88" dependencies = [ "ahash 0.8.11", - "indexmap 2.6.0", + "indexmap 2.7.1", "is-terminal", "itoa", "log", @@ -5951,7 +5951,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ee7893dab2e44ae5f9d0173f26ff4aa327c10b01b06a72b52dd9405b628640d" dependencies = [ - "indexmap 2.6.0", + "indexmap 2.7.1", ] [[package]] @@ -6434,7 +6434,7 @@ dependencies = [ "cactus", "cfgrammar", "filetime", - "indexmap 2.6.0", + "indexmap 2.7.1", "lazy_static", "lrtable", "num-traits", @@ -7675,7 +7675,7 @@ checksum = "1e32339a5dc40459130b3bd269e9892439f55b33e772d2a9d402a789baaf4e8a" dependencies = [ "futures-core", "futures-sink", - "indexmap 2.6.0", + "indexmap 2.7.1", "js-sys", "once_cell", "pin-project-lite", @@ -8247,7 +8247,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.6.0", + "indexmap 2.7.1", ] [[package]] @@ -10338,7 +10338,7 @@ version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "930cfb6e6abf99298aaad7d29abbef7a9999a9a8806a40088f55f0dcec03146b" dependencies = [ - "indexmap 2.6.0", + "indexmap 2.7.1", "itoa", "memchr", "ryu", @@ -10409,7 +10409,7 @@ dependencies = [ "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.6.0", + "indexmap 2.7.1", "serde", "serde_derive", "serde_json", @@ -10435,7 +10435,7 @@ version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ - "indexmap 2.6.0", + "indexmap 2.7.1", "itoa", "ryu", "serde", @@ -10496,6 +10496,7 @@ dependencies = [ "humantime", "humantime-serde", "hyper 1.4.1", + "indexmap 2.7.1", "influxdb_line_protocol", "itertools 0.10.5", "json5", @@ -11037,7 +11038,7 @@ dependencies = [ "futures-util", "hashbrown 0.15.2", "hashlink", - "indexmap 2.6.0", + "indexmap 2.7.1", "log", "memchr", "once_cell", @@ -12333,7 +12334,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.6.0", + "indexmap 2.7.1", "toml_datetime", "winnow 0.5.40", ] @@ -12344,7 +12345,7 @@ version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ - "indexmap 2.6.0", + "indexmap 2.7.1", "serde", "serde_spanned", "toml_datetime", @@ -12482,7 +12483,7 @@ dependencies = [ "futures-core", "futures-util", "hdrhistogram", - "indexmap 2.6.0", + "indexmap 2.7.1", "pin-project-lite", "slab", "sync_wrapper 1.0.1", diff --git a/src/servers/Cargo.toml b/src/servers/Cargo.toml index 840f8e86bbf..329c97c27e7 100644 --- a/src/servers/Cargo.toml +++ b/src/servers/Cargo.toml @@ -65,6 +65,7 @@ http-body = "1" humantime.workspace = true humantime-serde.workspace = true hyper = { workspace = true, features = ["full"] } +indexmap = "2.7" influxdb_line_protocol = { git = "https://github.com/evenyag/influxdb_iox", branch = "feat/line-protocol" } itertools.workspace = true jsonb.workspace = true diff --git a/src/servers/src/http/result/prometheus_resp.rs b/src/servers/src/http/result/prometheus_resp.rs index d35ef8ce97e..dd395c0e86a 100644 --- a/src/servers/src/http/result/prometheus_resp.rs +++ b/src/servers/src/http/result/prometheus_resp.rs @@ -13,7 +13,7 @@ // limitations under the License. //! prom supply the prometheus HTTP API Server compliance -use std::collections::{BTreeMap, HashMap}; +use std::collections::HashMap; use axum::http::HeaderValue; use axum::response::{IntoResponse, Response}; @@ -25,6 +25,7 @@ use common_recordbatch::RecordBatches; use datatypes::prelude::ConcreteDataType; use datatypes::scalars::ScalarVector; use datatypes::vectors::{Float64Vector, StringVector, TimestampMillisecondVector}; +use indexmap::IndexMap; use promql_parser::label::METRIC_NAME; use promql_parser::parser::value::ValueType; use serde::{Deserialize, Serialize}; @@ -229,7 +230,9 @@ impl PrometheusJsonResponse { })?; let metric_name = (METRIC_NAME, metric_name.as_str()); - let mut buffer = BTreeMap::, Vec<(f64, String)>>::new(); + // Preserves the order of output tags. + // Tag order matters, e.g., after sorc and sort_desc, the output order must be kept. + let mut buffer = IndexMap::, Vec<(f64, String)>>::new(); let schema = batches.schema(); for batch in batches.iter() {