mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-30 09:04:59 +08:00
457a473b72
* Fix error code of the "duplicate index found" error * Use the content of the ProcessingTasks in the tasks cancelation system * Change the missing_filters error code into missing_task_filters * WIP Introduce the invalid_task_uid error code * Use more precise error codes/message for the task routes + Allow star operator in delete/cancel tasks + rename originalQuery to originalFilters + Display error/canceled_by in task view even when they are = null + Rename task filter fields by using their plural forms + Prepare an error code for canceledBy filter + Only return global tasks if the API key action `index.*` is there * Add canceledBy task filter * Update tests following task API changes * Rename original_query to original_filters everywhere * Update more insta-snap tests * Make clippy happy They're a happy clip now. * Make rustfmt happy >:-( * Fix Index name parsing error message to fit the specification * Bump milli version to 0.35.1 * Fix the new error messages * fix the error messages and add tests * rename the error codes for the sake of consistency * refactor the way we send the cli informations + add the analytics for the config file and ssl usage * Apply suggestions from code review Co-authored-by: Clément Renault <clement@meilisearch.com> * add a comment over the new infos structure * reformat, sorry @kero * Store analytics for the documents deletions * Add analytics on all the settings * Spawn threads with names * Spawn rayon threads with names * update the distinct attributes to the spec update * update the analytics on the search route * implements the analytics on the health and version routes * Fix task details serialization * Add the question mark to the task deletion query filter * Add the question mark to the task cancelation query filter * Fix tests * add analytics on the task route * Add all the missing fields of the new task query type * Create a new analytics for the task deletion * Create a new analytics for the task creation * batch the tasks seen events * Update the finite pagination analytics * add the analytics of the swap-indexes route * Stop removing the DB when failing to read it * Rename originalFilters into originalFilters * Rename matchedDocuments into providedIds * Add `workflow_dispatch` to flaky.yml * Bump grenad to 0.4.4 * Bump milli to version v0.37.0 * Don't multiply total memory returned by sysinfo anymore sysinfo now returns bytes rather than KB * Add a dispatch to the publish binaries workflow * Fix publish release CI * Don't use gold but the default linker * Always display details for the indexDeletion task * Fix the insta tests * refactorize the whole test suite 1. Make a call to assert_internally_consistent automatically when snapshoting the scheduler. There is no point in snapshoting something broken and expect the dumb humans to notice. 2. Replace every possible call to assert_internally_consistent by a snapshot of the scheduler. It takes as many lines and ensure we never change something without noticing in any tests ever. 3. Name every snapshots: it's easier to debug when something goes wrong and easier to review in general. 4. Stop skipping breakpoints, it's too easy to miss something. Now you must explicitely show which path is the scheduler supposed to use. 5. Add a timeout on the channel.recv, it eases the process of writing tests, now when something file you get a failure instead of a deadlock. * rebase on release-v0.30 * makes clippy happy * update the snapshots after a rebase * try to remove the flakyness of the failing test * Add more analytics on the ranking rules positions * Update the dump test to check for the dumpUid dumpCreation task details * send the ranking rules as a string because amplitude is too dumb to process an array as a single value * Display a null dumpUid until we computed the dump itself on disk * Update tests * Check if the master key is missing before returning an error Co-authored-by: Loïc Lecrenier <loic.lecrenier@me.com> Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com> Co-authored-by: Kerollmops <clement@meilisearch.com> Co-authored-by: ManyTheFish <many@meilisearch.com> Co-authored-by: Tamo <tamo@meilisearch.com> Co-authored-by: Louis Dureuil <louis@meilisearch.com>
205 lines
6.8 KiB
Rust
205 lines
6.8 KiB
Rust
#![allow(dead_code)]
|
|
|
|
use std::path::Path;
|
|
use std::time::Duration;
|
|
|
|
use actix_http::body::MessageBody;
|
|
use actix_web::dev::ServiceResponse;
|
|
use actix_web::http::StatusCode;
|
|
use byte_unit::{Byte, ByteUnit};
|
|
use clap::Parser;
|
|
use meilisearch_http::option::{IndexerOpts, MaxMemory, Opt};
|
|
use meilisearch_http::{analytics, create_app, setup_meilisearch};
|
|
use once_cell::sync::Lazy;
|
|
use serde_json::{json, Value};
|
|
use tempfile::TempDir;
|
|
use tokio::time::sleep;
|
|
|
|
use super::index::Index;
|
|
use super::service::Service;
|
|
use crate::common::encoder::Encoder;
|
|
|
|
pub struct Server {
|
|
pub service: Service,
|
|
// hold ownership to the tempdir while we use the server instance.
|
|
_dir: Option<TempDir>,
|
|
}
|
|
|
|
pub static TEST_TEMP_DIR: Lazy<TempDir> = Lazy::new(|| TempDir::new().unwrap());
|
|
|
|
impl Server {
|
|
pub async fn new() -> Self {
|
|
let dir = TempDir::new().unwrap();
|
|
|
|
if cfg!(windows) {
|
|
std::env::set_var("TMP", TEST_TEMP_DIR.path());
|
|
} else {
|
|
std::env::set_var("TMPDIR", TEST_TEMP_DIR.path());
|
|
}
|
|
|
|
let options = default_settings(dir.path());
|
|
|
|
let (index_scheduler, auth) = setup_meilisearch(&options).unwrap();
|
|
let service = Service { index_scheduler, auth, options, api_key: None };
|
|
|
|
Server { service, _dir: Some(dir) }
|
|
}
|
|
|
|
pub async fn new_auth_with_options(mut options: Opt, dir: TempDir) -> Self {
|
|
if cfg!(windows) {
|
|
std::env::set_var("TMP", TEST_TEMP_DIR.path());
|
|
} else {
|
|
std::env::set_var("TMPDIR", TEST_TEMP_DIR.path());
|
|
}
|
|
|
|
options.master_key = Some("MASTER_KEY".to_string());
|
|
|
|
let (index_scheduler, auth) = setup_meilisearch(&options).unwrap();
|
|
let service = Service { index_scheduler, auth, options, api_key: None };
|
|
|
|
Server { service, _dir: Some(dir) }
|
|
}
|
|
|
|
pub async fn new_auth() -> Self {
|
|
let dir = TempDir::new().unwrap();
|
|
let options = default_settings(dir.path());
|
|
Self::new_auth_with_options(options, dir).await
|
|
}
|
|
|
|
pub async fn new_with_options(options: Opt) -> Result<Self, anyhow::Error> {
|
|
let (index_scheduler, auth) = setup_meilisearch(&options)?;
|
|
let service = Service { index_scheduler, auth, options, api_key: None };
|
|
|
|
Ok(Server { service, _dir: None })
|
|
}
|
|
|
|
pub async fn init_web_app(
|
|
&self,
|
|
) -> impl actix_web::dev::Service<
|
|
actix_http::Request,
|
|
Response = ServiceResponse<impl MessageBody>,
|
|
Error = actix_web::Error,
|
|
> {
|
|
actix_web::test::init_service(create_app(
|
|
self.service.index_scheduler.clone().into(),
|
|
self.service.auth.clone(),
|
|
self.service.options.clone(),
|
|
analytics::MockAnalytics::new(&self.service.options),
|
|
true,
|
|
))
|
|
.await
|
|
}
|
|
|
|
/// Returns a view to an index. There is no guarantee that the index exists.
|
|
pub fn index(&self, uid: impl AsRef<str>) -> Index<'_> {
|
|
self.index_with_encoder(uid, Encoder::Plain)
|
|
}
|
|
|
|
pub fn index_with_encoder(&self, uid: impl AsRef<str>, encoder: Encoder) -> Index<'_> {
|
|
Index { uid: uid.as_ref().to_string(), service: &self.service, encoder }
|
|
}
|
|
|
|
pub async fn list_indexes(
|
|
&self,
|
|
offset: Option<usize>,
|
|
limit: Option<usize>,
|
|
) -> (Value, StatusCode) {
|
|
let (offset, limit) = (
|
|
offset.map(|offset| format!("offset={offset}")),
|
|
limit.map(|limit| format!("limit={limit}")),
|
|
);
|
|
let query_parameter = offset
|
|
.as_ref()
|
|
.zip(limit.as_ref())
|
|
.map(|(offset, limit)| format!("{offset}&{limit}"))
|
|
.or_else(|| offset.xor(limit));
|
|
if let Some(query_parameter) = query_parameter {
|
|
self.service.get(format!("/indexes?{query_parameter}")).await
|
|
} else {
|
|
self.service.get("/indexes").await
|
|
}
|
|
}
|
|
|
|
pub async fn version(&self) -> (Value, StatusCode) {
|
|
self.service.get("/version").await
|
|
}
|
|
|
|
pub async fn stats(&self) -> (Value, StatusCode) {
|
|
self.service.get("/stats").await
|
|
}
|
|
|
|
pub async fn tasks(&self) -> (Value, StatusCode) {
|
|
self.service.get("/tasks").await
|
|
}
|
|
|
|
pub async fn tasks_filter(&self, filter: Value) -> (Value, StatusCode) {
|
|
self.service.get(format!("/tasks?{}", yaup::to_string(&filter).unwrap())).await
|
|
}
|
|
|
|
pub async fn get_dump_status(&self, uid: &str) -> (Value, StatusCode) {
|
|
self.service.get(format!("/dumps/{}/status", uid)).await
|
|
}
|
|
|
|
pub async fn create_dump(&self) -> (Value, StatusCode) {
|
|
self.service.post("/dumps", json!(null)).await
|
|
}
|
|
|
|
pub async fn index_swap(&self, value: Value) -> (Value, StatusCode) {
|
|
self.service.post("/swap-indexes", value).await
|
|
}
|
|
|
|
pub async fn cancel_tasks(&self, value: Value) -> (Value, StatusCode) {
|
|
self.service
|
|
.post(format!("/tasks/cancel?{}", yaup::to_string(&value).unwrap()), json!(null))
|
|
.await
|
|
}
|
|
|
|
pub async fn delete_tasks(&self, value: Value) -> (Value, StatusCode) {
|
|
self.service.delete(format!("/tasks?{}", yaup::to_string(&value).unwrap())).await
|
|
}
|
|
|
|
pub async fn wait_task(&self, update_id: u64) -> Value {
|
|
// try several times to get status, or panic to not wait forever
|
|
let url = format!("/tasks/{}", update_id);
|
|
for _ in 0..100 {
|
|
let (response, status_code) = self.service.get(&url).await;
|
|
assert_eq!(200, status_code, "response: {}", response);
|
|
|
|
if response["status"] == "succeeded" || response["status"] == "failed" {
|
|
return response;
|
|
}
|
|
|
|
// wait 0.5 second.
|
|
sleep(Duration::from_millis(500)).await;
|
|
}
|
|
panic!("Timeout waiting for update id");
|
|
}
|
|
|
|
pub async fn get_task(&self, update_id: u64) -> (Value, StatusCode) {
|
|
let url = format!("/tasks/{}", update_id);
|
|
self.service.get(url).await
|
|
}
|
|
}
|
|
|
|
pub fn default_settings(dir: impl AsRef<Path>) -> Opt {
|
|
Opt {
|
|
db_path: dir.as_ref().join("db"),
|
|
dumps_dir: dir.as_ref().join("dump"),
|
|
env: "development".to_owned(),
|
|
#[cfg(all(not(debug_assertions), feature = "analytics"))]
|
|
no_analytics: true,
|
|
max_index_size: Byte::from_unit(100.0, ByteUnit::MiB).unwrap(),
|
|
max_task_db_size: Byte::from_unit(1.0, ByteUnit::GiB).unwrap(),
|
|
http_payload_size_limit: Byte::from_unit(10.0, ByteUnit::MiB).unwrap(),
|
|
snapshot_dir: ".".into(),
|
|
indexer_options: IndexerOpts {
|
|
// memory has to be unlimited because several meilisearch are running in test context.
|
|
max_indexing_memory: MaxMemory::unlimited(),
|
|
..Parser::parse_from(None as Option<&str>)
|
|
},
|
|
#[cfg(feature = "metrics")]
|
|
enable_metrics_route: true,
|
|
..Parser::parse_from(None as Option<&str>)
|
|
}
|
|
}
|