From 25dbdaa4fd20ddda33f528f58f27227a30d0b4c9 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Mon, 3 Aug 2026 09:58:54 +0200 Subject: [PATCH 1/5] Add global metrics labels env var Co-authored-by: Cursor --- docs/reference/metrics.md | 10 +++++++ quickwit/quickwit-metrics/src/inner.rs | 40 +++++++++++++++++++++++++- quickwit/quickwit-metrics/src/lib.rs | 5 +++- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/docs/reference/metrics.md b/docs/reference/metrics.md index e75121f08f3..f740287c242 100644 --- a/docs/reference/metrics.md +++ b/docs/reference/metrics.md @@ -91,3 +91,13 @@ PostgreSQL-backed metastores also expose connection pool gauges: | `quickwit_storage` | `object_storage_puts_total` | Number of objects uploaded. May differ from object_storage_requests_parts due to multipart upload | `counter` | | `quickwit_storage` | `object_storage_puts_parts` | Number of object parts uploaded | `counter` | | `quickwit_storage` | `object_storage_download_num_bytes` | Amount of data downloaded from an object storage | `counter` | + +## Global labels + +You can attach the same labels to every Quickwit metric by setting the `QW_METRICS_LABELS` environment variable. Specify labels as a comma-separated list of `name=value` pairs: + +```bash +QW_METRICS_LABELS="environment=production,region=us-east-1" quickwit run +``` + +The environment variable is read once, when the first metric is initialized. Set it before starting Quickwit; changing it while Quickwit is running has no effect. diff --git a/quickwit/quickwit-metrics/src/inner.rs b/quickwit/quickwit-metrics/src/inner.rs index 69f0858a971..93c5374dffc 100644 --- a/quickwit/quickwit-metrics/src/inner.rs +++ b/quickwit/quickwit-metrics/src/inner.rs @@ -19,12 +19,40 @@ //! items via `$crate::`. **Do not use directly.** use std::hash::{Hash, Hasher}; +use std::sync::LazyLock; #[doc(hidden)] pub use const_format::concatcp as __concatcp; +use metrics::Label; use rustc_hash::FxHasher; +static METRICS_LABELS_ENV_VAR: LazyLock> = LazyLock::new(|| + // quickwit-common defines common helpers for getting environment variables. + // However, we need to use the `std::env::var` function directly here because + // quickwit-common depends on quickwit-metrics and it would cause a circular dependency. + + // The format of the environment variable is: + // QW_METRICS_LABELS="environment=test,region=us-east-1,foo=bar" + match std::env::var(super::METRICS_LABELS_ENV_VAR_NAME) { + Ok(labels) => { + let labels: Vec