From a17e45c38d802aa518f344bb2b92b1b2c6951259 Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Mon, 11 Mar 2024 18:04:13 +0900 Subject: [PATCH] Added a metric for number of indexes --- quickwit/quickwit-control-plane/src/metrics.rs | 4 +++- quickwit/quickwit-control-plane/src/model/mod.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/quickwit/quickwit-control-plane/src/metrics.rs b/quickwit/quickwit-control-plane/src/metrics.rs index 69a1caa5c51..54d05e0a9ff 100644 --- a/quickwit/quickwit-control-plane/src/metrics.rs +++ b/quickwit/quickwit-control-plane/src/metrics.rs @@ -18,9 +18,10 @@ // along with this program. If not, see . use once_cell::sync::Lazy; -use quickwit_common::metrics::{new_counter, new_gauge_vec, IntCounter, IntGaugeVec}; +use quickwit_common::metrics::{new_counter, new_gauge, new_gauge_vec, IntCounter, IntGaugeVec}; pub struct ControlPlaneMetrics { + pub indexes_total: IntGauge, pub restart_total: IntCounter, pub schedule_total: IntCounter, pub metastore_error_aborted: IntCounter, @@ -31,6 +32,7 @@ pub struct ControlPlaneMetrics { impl Default for ControlPlaneMetrics { fn default() -> Self { ControlPlaneMetrics { + indexes_total: new_gauge("indexes_total", "Number of indexes.", "control_plane", &[]), restart_total: new_counter( "restart_total", "Number of control plane restart.", diff --git a/quickwit/quickwit-control-plane/src/model/mod.rs b/quickwit/quickwit-control-plane/src/model/mod.rs index 9602cb814b6..86dbf578198 100644 --- a/quickwit/quickwit-control-plane/src/model/mod.rs +++ b/quickwit/quickwit-control-plane/src/model/mod.rs @@ -152,6 +152,12 @@ impl ControlPlaneModel { self.index_uid_table.get(index_id).cloned() } + fn update_metrics(&self) { + crate::metrics::CONTROL_PLANE_METRICS + .indexes_total + .set(self.index_table.len() as i64); + } + pub(crate) fn source_configs(&self) -> impl Iterator + '_ { self.index_table.values().flat_map(|index_metadata| { index_metadata @@ -181,12 +187,14 @@ impl ControlPlaneModel { } } self.index_table.insert(index_uid, index_metadata); + self.update_metrics(); } pub(crate) fn delete_index(&mut self, index_uid: &IndexUid) { self.index_table.remove(index_uid); self.index_uid_table.remove(&index_uid.index_id); self.shard_table.delete_index(&index_uid.index_id); + self.update_metrics(); } /// Adds a source to a given index. Returns an error if the source already