From 62240b7e19ed56a906a73538dddeedb25820ab1d Mon Sep 17 00:00:00 2001 From: Irevoire Date: Wed, 17 Aug 2022 16:12:26 +0200 Subject: [PATCH] add analytics on the stats routes --- meilisearch-http/src/routes/indexes/mod.rs | 7 +++++++ meilisearch-http/src/routes/mod.rs | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/meilisearch-http/src/routes/indexes/mod.rs b/meilisearch-http/src/routes/indexes/mod.rs index ed6196ebd..9fdd0854c 100644 --- a/meilisearch-http/src/routes/indexes/mod.rs +++ b/meilisearch-http/src/routes/indexes/mod.rs @@ -158,7 +158,14 @@ pub async fn delete_index( pub async fn get_index_stats( meilisearch: GuardedData, MeiliSearch>, path: web::Path, + req: HttpRequest, + analytics: web::Data, ) -> Result { + analytics.publish( + "Stats Seen".to_string(), + json!({ "per_index_uid": true }), + Some(&req), + ); let response = meilisearch.get_index_stats(path.into_inner()).await?; debug!("returns: {:?}", response); diff --git a/meilisearch-http/src/routes/mod.rs b/meilisearch-http/src/routes/mod.rs index f61854c48..6a673f600 100644 --- a/meilisearch-http/src/routes/mod.rs +++ b/meilisearch-http/src/routes/mod.rs @@ -1,7 +1,8 @@ -use actix_web::{web, HttpResponse}; +use actix_web::{web, HttpRequest, HttpResponse}; use log::debug; use serde::{Deserialize, Serialize}; +use serde_json::json; use time::OffsetDateTime; use meilisearch_lib::index::{Settings, Unchecked}; @@ -9,6 +10,7 @@ use meilisearch_lib::MeiliSearch; use meilisearch_types::error::ResponseError; use meilisearch_types::star_or::StarOr; +use crate::analytics::Analytics; use crate::extractors::authentication::{policies::*, GuardedData}; mod api_key; @@ -231,7 +233,14 @@ pub async fn running() -> HttpResponse { async fn get_stats( meilisearch: GuardedData, MeiliSearch>, + req: HttpRequest, + analytics: web::Data, ) -> Result { + analytics.publish( + "Stats Seen".to_string(), + json!({ "per_index_uid": false }), + Some(&req), + ); let search_rules = &meilisearch.filters().search_rules; let response = meilisearch.get_all_stats(search_rules).await?;