From 146908f062531f60fb8f0b1f6a4667c67fa239ac Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Wed, 15 Nov 2023 23:06:47 +0100 Subject: [PATCH] Add reports route --- index-scheduler/src/lib.rs | 5 ++++ meilisearch-types/src/error.rs | 2 +- meilisearch/src/error.rs | 3 +++ meilisearch/src/routes/mod.rs | 4 +++- meilisearch/src/routes/reports.rs | 39 +++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 meilisearch/src/routes/reports.rs diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index fe50d21d6..9308d670a 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -55,6 +55,7 @@ use meilisearch_types::milli::update::IndexerConfig; use meilisearch_types::milli::{self, CboRoaringBitmapCodec, Index, RoaringBitmapCodec, BEU32}; use meilisearch_types::tasks::{Kind, KindWithContent, Status, Task}; use panic_hook::PanicReader; +pub use panic_hook::{Panic, Report, ReportRegistry}; use puffin::FrameView; use roaring::RoaringBitmap; use synchronoise::SignalEvent; @@ -1326,6 +1327,10 @@ impl IndexScheduler { } } + pub fn reports(&self) -> Arc> { + self.panic_reader.registry() + } + /// Blocks the thread until the test handle asks to progress to/through this breakpoint. /// /// Two messages are sent through the channel for each breakpoint. diff --git a/meilisearch-types/src/error.rs b/meilisearch-types/src/error.rs index 4b6711601..029c61569 100644 --- a/meilisearch-types/src/error.rs +++ b/meilisearch-types/src/error.rs @@ -88,7 +88,6 @@ pub trait ErrorCode { } } -#[allow(clippy::enum_variant_names)] enum ErrorType { Internal, InvalidRequest, @@ -298,6 +297,7 @@ MissingSwapIndexes , InvalidRequest , BAD_REQUEST ; MissingTaskFilters , InvalidRequest , BAD_REQUEST ; NoSpaceLeftOnDevice , System , UNPROCESSABLE_ENTITY; PayloadTooLarge , InvalidRequest , PAYLOAD_TOO_LARGE ; +ReportNotFound , InvalidRequest , NOT_FOUND ; TaskNotFound , InvalidRequest , NOT_FOUND ; TooManyOpenFiles , System , UNPROCESSABLE_ENTITY ; UnretrievableDocument , Internal , BAD_REQUEST ; diff --git a/meilisearch/src/error.rs b/meilisearch/src/error.rs index ca10c4593..08b25e5ed 100644 --- a/meilisearch/src/error.rs +++ b/meilisearch/src/error.rs @@ -51,6 +51,8 @@ pub enum MeilisearchHttpError { DocumentFormat(#[from] DocumentFormatError), #[error(transparent)] Join(#[from] JoinError), + #[error("Report `{0}` not found. Either its id is incorrect, or it was deleted. To save on memory, only a limited amount of reports are kept.")] + ReportNotFound(uuid::Uuid), } impl ErrorCode for MeilisearchHttpError { @@ -74,6 +76,7 @@ impl ErrorCode for MeilisearchHttpError { MeilisearchHttpError::FileStore(_) => Code::Internal, MeilisearchHttpError::DocumentFormat(e) => e.error_code(), MeilisearchHttpError::Join(_) => Code::Internal, + MeilisearchHttpError::ReportNotFound(_) => Code::ReportNotFound, } } } diff --git a/meilisearch/src/routes/mod.rs b/meilisearch/src/routes/mod.rs index 0e5623b09..d151b5669 100644 --- a/meilisearch/src/routes/mod.rs +++ b/meilisearch/src/routes/mod.rs @@ -24,6 +24,7 @@ pub mod features; pub mod indexes; mod metrics; mod multi_search; +mod reports; mod snapshot; mod swap_indexes; pub mod tasks; @@ -40,7 +41,8 @@ pub fn configure(cfg: &mut web::ServiceConfig) { .service(web::scope("/multi-search").configure(multi_search::configure)) .service(web::scope("/swap-indexes").configure(swap_indexes::configure)) .service(web::scope("/metrics").configure(metrics::configure)) - .service(web::scope("/experimental-features").configure(features::configure)); + .service(web::scope("/experimental-features").configure(features::configure)) + .service(web::scope("/reports").configure(reports::configure)); } #[derive(Debug, Serialize)] diff --git a/meilisearch/src/routes/reports.rs b/meilisearch/src/routes/reports.rs new file mode 100644 index 000000000..d46e8fa1e --- /dev/null +++ b/meilisearch/src/routes/reports.rs @@ -0,0 +1,39 @@ +use actix_web::web::{self, Data}; +use actix_web::HttpResponse; +use index_scheduler::{IndexScheduler, Report}; +use meilisearch_types::error::ResponseError; +use meilisearch_types::keys::actions; + +use crate::extractors::authentication::policies::ActionPolicy; +use crate::extractors::authentication::GuardedData; +use crate::extractors::sequential_extractor::SeqHandler; + +pub fn configure(cfg: &mut web::ServiceConfig) { + cfg.service(web::resource("").route(web::get().to(list_reports))).service( + web::scope("/{report_uid}") + .service(web::resource("").route(web::get().to(SeqHandler(get_report)))), + ); +} + +pub async fn list_reports( + index_scheduler: GuardedData, Data>, +) -> Result { + let reports = &index_scheduler.reports(); + let reports = &reports.read().unwrap(); + let reports: Vec<&Report> = reports.iter().collect(); + + Ok(HttpResponse::Ok().json(reports)) +} + +pub async fn get_report( + index_scheduler: GuardedData, Data>, + report_id: web::Path, +) -> Result { + let reports = &index_scheduler.reports(); + let reports = &reports.read().unwrap(); + let report = reports + .find(*report_id) + .ok_or(crate::error::MeilisearchHttpError::ReportNotFound(*report_id))?; + + Ok(HttpResponse::Ok().json(report)) +}