From 9ca4db6ef0dd24c581f0c55eec4ac1e03e5c1ef7 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Tue, 30 Jan 2024 18:15:53 +0100 Subject: [PATCH] Add cancel log route --- meilisearch/src/routes/logs.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/meilisearch/src/routes/logs.rs b/meilisearch/src/routes/logs.rs index b40a34b91..ca1ca2d2f 100644 --- a/meilisearch/src/routes/logs.rs +++ b/meilisearch/src/routes/logs.rs @@ -13,8 +13,6 @@ use meilisearch_types::deserr::DeserrJsonError; use meilisearch_types::error::deserr_codes::*; use meilisearch_types::error::ResponseError; use tokio::sync::mpsc::{self, UnboundedSender}; -use tracing::instrument::WithSubscriber; -use tracing_subscriber::filter::Targets; use tracing_subscriber::Layer; use crate::error::MeilisearchHttpError; @@ -24,7 +22,11 @@ use crate::extractors::sequential_extractor::SeqHandler; use crate::LogRouteHandle; pub fn configure(cfg: &mut web::ServiceConfig) { - cfg.service(web::resource("").route(web::post().to(SeqHandler(get_logs)))); + cfg.service( + web::resource("") + .route(web::post().to(SeqHandler(get_logs))) + .route(web::delete().to(SeqHandler(cancel_logs))), + ); } #[derive(Debug, Default, Clone, Copy, Deserr)] @@ -189,3 +191,15 @@ pub async fn get_logs( Err(MeilisearchHttpError::AlreadyUsedLogRoute.into()) } } + +pub async fn cancel_logs( + _auth_controller: GuardedData, Data>, + logs: Data, + _req: HttpRequest, +) -> Result { + if let Err(e) = logs.modify(|layer| *layer.inner_mut() = None) { + tracing::error!("Could not free the logs route: {e}"); + } + + Ok(HttpResponse::NoContent().finish()) +}