feat(chat): update metrics name

This commit is contained in:
nicolasvienot
2025-07-30 17:55:02 +02:00
parent d4c88f28f3
commit 41262b008b
2 changed files with 16 additions and 16 deletions

View File

@ -15,30 +15,30 @@ lazy_static! {
"Meilisearch number of degraded search requests" "Meilisearch number of degraded search requests"
)) ))
.expect("Can't create a metric"); .expect("Can't create a metric");
pub static ref MEILISEARCH_CHAT_SEARCH_REQUESTS: IntCounterVec = register_int_counter_vec!( pub static ref MEILISEARCH_CHAT_SEARCHES_TOTAL: IntCounterVec = register_int_counter_vec!(
opts!( opts!(
"meilisearch_chat_search_requests", "meilisearch_chat_searches_total",
"Meilisearch number of search requests performed by the chat route itself" "Total number of searches performed by the chat route"
), ),
&["type"] &["type"]
) )
.expect("Can't create a metric"); .expect("Can't create a metric");
pub static ref MEILISEARCH_CHAT_PROMPT_TOKENS_USAGE: IntCounterVec = register_int_counter_vec!( pub static ref MEILISEARCH_CHAT_PROMPT_TOKENS_TOTAL: IntCounterVec = register_int_counter_vec!(
opts!("meilisearch_chat_prompt_tokens_usage", "Meilisearch Chat Prompt Tokens Usage"), opts!("meilisearch_chat_prompt_tokens_total", "Total number of prompt tokens consumed"),
&["workspace", "model"] &["workspace", "model"]
) )
.expect("Can't create a metric"); .expect("Can't create a metric");
pub static ref MEILISEARCH_CHAT_COMPLETION_TOKENS_USAGE: IntCounterVec = pub static ref MEILISEARCH_CHAT_COMPLETION_TOKENS_TOTAL: IntCounterVec =
register_int_counter_vec!( register_int_counter_vec!(
opts!( opts!(
"meilisearch_chat_completion_tokens_usage", "meilisearch_chat_completion_tokens_total",
"Meilisearch Chat Completion Tokens Usage" "Total number of completion tokens consumed"
), ),
&["workspace", "model"] &["workspace", "model"]
) )
.expect("Can't create a metric"); .expect("Can't create a metric");
pub static ref MEILISEARCH_CHAT_TOTAL_TOKENS_USAGE: IntCounterVec = register_int_counter_vec!( pub static ref MEILISEARCH_CHAT_TOKENS_TOTAL: IntCounterVec = register_int_counter_vec!(
opts!("meilisearch_chat_total_tokens_usage", "Meilisearch Chat Total Tokens Usage"), opts!("meilisearch_chat_tokens_total", "Total number of tokens consumed (prompt + completion)"),
&["workspace", "model"] &["workspace", "model"]
) )
.expect("Can't create a metric"); .expect("Can't create a metric");

View File

@ -50,8 +50,8 @@ use crate::error::MeilisearchHttpError;
use crate::extractors::authentication::policies::ActionPolicy; use crate::extractors::authentication::policies::ActionPolicy;
use crate::extractors::authentication::{extract_token_from_request, GuardedData, Policy as _}; use crate::extractors::authentication::{extract_token_from_request, GuardedData, Policy as _};
use crate::metrics::{ use crate::metrics::{
MEILISEARCH_CHAT_COMPLETION_TOKENS_USAGE, MEILISEARCH_CHAT_PROMPT_TOKENS_USAGE, MEILISEARCH_CHAT_COMPLETION_TOKENS_TOTAL, MEILISEARCH_CHAT_PROMPT_TOKENS_TOTAL,
MEILISEARCH_CHAT_SEARCH_REQUESTS, MEILISEARCH_CHAT_TOTAL_TOKENS_USAGE, MEILISEARCH_CHAT_SEARCHES_TOTAL, MEILISEARCH_CHAT_TOKENS_TOTAL,
MEILISEARCH_DEGRADED_SEARCH_REQUESTS, MEILISEARCH_DEGRADED_SEARCH_REQUESTS,
}; };
use crate::routes::chats::utils::SseEventSender; use crate::routes::chats::utils::SseEventSender;
@ -319,7 +319,7 @@ async fn process_search_request(
}; };
let mut documents = Vec::new(); let mut documents = Vec::new();
if let Ok((ref rtxn, ref search_result)) = output { if let Ok((ref rtxn, ref search_result)) = output {
MEILISEARCH_CHAT_SEARCH_REQUESTS.with_label_values(&["internal"]).inc(); MEILISEARCH_CHAT_SEARCHES_TOTAL.with_label_values(&["internal"]).inc();
if search_result.degraded { if search_result.degraded {
MEILISEARCH_DEGRADED_SEARCH_REQUESTS.inc(); MEILISEARCH_DEGRADED_SEARCH_REQUESTS.inc();
} }
@ -596,13 +596,13 @@ async fn run_conversation<C: async_openai::config::Config>(
match result { match result {
Ok(resp) => { Ok(resp) => {
if let Some(usage) = resp.usage.as_ref() { if let Some(usage) = resp.usage.as_ref() {
MEILISEARCH_CHAT_PROMPT_TOKENS_USAGE MEILISEARCH_CHAT_PROMPT_TOKENS_TOTAL
.with_label_values(&[workspace_uid, &chat_completion.model]) .with_label_values(&[workspace_uid, &chat_completion.model])
.inc_by(usage.prompt_tokens as u64); .inc_by(usage.prompt_tokens as u64);
MEILISEARCH_CHAT_COMPLETION_TOKENS_USAGE MEILISEARCH_CHAT_COMPLETION_TOKENS_TOTAL
.with_label_values(&[workspace_uid, &chat_completion.model]) .with_label_values(&[workspace_uid, &chat_completion.model])
.inc_by(usage.completion_tokens as u64); .inc_by(usage.completion_tokens as u64);
MEILISEARCH_CHAT_TOTAL_TOKENS_USAGE MEILISEARCH_CHAT_TOKENS_TOTAL
.with_label_values(&[workspace_uid, &chat_completion.model]) .with_label_values(&[workspace_uid, &chat_completion.model])
.inc_by(usage.total_tokens as u64); .inc_by(usage.total_tokens as u64);
} }