Skip to content

Commit

Permalink
Added a metric for number of indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
fulmicoton committed Mar 11, 2024
1 parent 81e4f1b commit a17e45c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion quickwit/quickwit-control-plane/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

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,
Expand All @@ -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.",
Expand Down
8 changes: 8 additions & 0 deletions quickwit/quickwit-control-plane/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = (SourceUid, &SourceConfig)> + '_ {
self.index_table.values().flat_map(|index_metadata| {
index_metadata
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a17e45c

Please sign in to comment.