From 5387cf17186dfd977275a5e30fc406d96f1e698b Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Mon, 3 Jul 2023 15:21:58 +0200 Subject: [PATCH] Don't unwrap in case of error/missing last_update field --- meilisearch/src/metrics.rs | 16 ++++++---------- meilisearch/src/routes/metrics.rs | 7 ++++--- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/meilisearch/src/metrics.rs b/meilisearch/src/metrics.rs index 009c3e472..2becdae76 100644 --- a/meilisearch/src/metrics.rs +++ b/meilisearch/src/metrics.rs @@ -50,14 +50,10 @@ lazy_static! { &["kind", "value"] ) .expect("Can't create a metric"); - pub static ref MEILISEARCH_LAST_UPDATE: IntGauge = register_int_gauge!(opts!( - "meilisearch_last_update", - "Meilisearch Last Update" - )) - .expect("Can't create a metric"); - pub static ref MEILISEARCH_IS_INDEXING: IntGauge = register_int_gauge!(opts!( - "meilisearch_is_indexing", - "Meilisearch Is Indexing" - )) - .expect("Can't create a metric"); + pub static ref MEILISEARCH_LAST_UPDATE: IntGauge = + register_int_gauge!(opts!("meilisearch_last_update", "Meilisearch Last Update")) + .expect("Can't create a metric"); + pub static ref MEILISEARCH_IS_INDEXING: IntGauge = + register_int_gauge!(opts!("meilisearch_is_indexing", "Meilisearch Is Indexing")) + .expect("Can't create a metric"); } diff --git a/meilisearch/src/routes/metrics.rs b/meilisearch/src/routes/metrics.rs index 534c0c500..93d07e67c 100644 --- a/meilisearch/src/routes/metrics.rs +++ b/meilisearch/src/routes/metrics.rs @@ -48,9 +48,10 @@ pub async fn get_metrics( } } - crate::metrics::MEILISEARCH_LAST_UPDATE.set(response.last_update.unwrap().unix_timestamp()); - crate::metrics::MEILISEARCH_IS_INDEXING - .set(index_scheduler.is_task_processing().unwrap() as i64); + if let Some(last_update) = response.last_update { + crate::metrics::MEILISEARCH_LAST_UPDATE.set(last_update.unix_timestamp()); + } + crate::metrics::MEILISEARCH_IS_INDEXING.set(index_scheduler.is_task_processing()? as i64); let encoder = TextEncoder::new(); let mut buffer = vec![];