From 7bfcd766281da06fe4fce3ed16623249f7f23ff6 Mon Sep 17 00:00:00 2001 From: Nicolas Lamirault Date: Tue, 3 Sep 2024 10:12:08 +0200 Subject: [PATCH] feat(prometheus): add build_info metric Signed-off-by: Nicolas Lamirault --- meilisearch/src/metrics.rs | 7 +++++++ meilisearch/src/routes/metrics.rs | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/meilisearch/src/metrics.rs b/meilisearch/src/metrics.rs index d380e9b96..e349fdc83 100644 --- a/meilisearch/src/metrics.rs +++ b/meilisearch/src/metrics.rs @@ -5,6 +5,13 @@ use prometheus::{ }; lazy_static! { + pub static ref MEILISEARCH_BUILD_INFO: IntGaugeVec = register_int_gauge_vec!( + opts!( + "meilisearch_build_info", + "A metric with a constant '1' value labelled by version from which meilisearch was built"), + & ["revision", "version"] + ) + .expect("Can't create a metric"); pub static ref MEILISEARCH_HTTP_REQUESTS_TOTAL: IntCounterVec = register_int_counter_vec!( opts!("meilisearch_http_requests_total", "Meilisearch HTTP requests total"), &["method", "path", "status"] diff --git a/meilisearch/src/routes/metrics.rs b/meilisearch/src/routes/metrics.rs index 7a13a758f..fd866b64f 100644 --- a/meilisearch/src/routes/metrics.rs +++ b/meilisearch/src/routes/metrics.rs @@ -1,6 +1,7 @@ use actix_web::http::header; use actix_web::web::{self, Data}; use actix_web::HttpResponse; +use build_info; use index_scheduler::IndexScheduler; use meilisearch_auth::AuthController; use meilisearch_types::error::ResponseError; @@ -54,6 +55,11 @@ pub async fn get_metrics( } crate::metrics::MEILISEARCH_IS_INDEXING.set(index_scheduler.is_task_processing()? as i64); + let build_info = build_info::BuildInfo::from_build(); + let commit_sha = build_info.commit_sha1.unwrap_or("unknown").to_string(); + let pkg_version = env!("CARGO_PKG_VERSION").to_string(); + crate::metrics::MEILISEARCH_BUILD_INFO.with_label_values(&[&commit_sha, &pkg_version]).set(1); + let encoder = TextEncoder::new(); let mut buffer = vec![]; encoder.encode(&prometheus::gather(), &mut buffer).expect("Failed to encode metrics");