mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-23 21:26:26 +00:00
Make commands common
This commit is contained in:
@ -2,17 +2,18 @@ use std::collections::BTreeMap;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use anyhow::{bail, Context as _};
|
use anyhow::{bail, Context as _};
|
||||||
use tokio::process::Command;
|
use tokio::process::Command as TokioCommand;
|
||||||
use tokio::time;
|
use tokio::time;
|
||||||
|
|
||||||
use super::workload::BenchWorkload;
|
use super::workload::BenchWorkload;
|
||||||
use crate::common::assets::Asset;
|
use crate::common::assets::Asset;
|
||||||
use crate::common::client::Client;
|
use crate::common::client::Client;
|
||||||
|
use crate::common::command::{run as run_command, Command, SyncMode};
|
||||||
|
|
||||||
pub async fn kill(mut meilisearch: tokio::process::Child) {
|
pub async fn kill(mut meilisearch: tokio::process::Child) {
|
||||||
let Some(id) = meilisearch.id() else { return };
|
let Some(id) = meilisearch.id() else { return };
|
||||||
|
|
||||||
match Command::new("kill").args(["--signal=TERM", &id.to_string()]).spawn() {
|
match TokioCommand::new("kill").args(["--signal=TERM", &id.to_string()]).spawn() {
|
||||||
Ok(mut cmd) => {
|
Ok(mut cmd) => {
|
||||||
let Err(error) = cmd.wait().await else { return };
|
let Err(error) = cmd.wait().await else { return };
|
||||||
tracing::warn!(
|
tracing::warn!(
|
||||||
@ -50,7 +51,7 @@ pub async fn kill(mut meilisearch: tokio::process::Child) {
|
|||||||
|
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn build() -> anyhow::Result<()> {
|
pub async fn build() -> anyhow::Result<()> {
|
||||||
let mut command = Command::new("cargo");
|
let mut command = TokioCommand::new("cargo");
|
||||||
command.arg("build").arg("--release").arg("-p").arg("meilisearch");
|
command.arg("build").arg("--release").arg("-p").arg("meilisearch");
|
||||||
|
|
||||||
command.kill_on_drop(true);
|
command.kill_on_drop(true);
|
||||||
@ -70,7 +71,7 @@ pub async fn start(
|
|||||||
master_key: Option<&str>,
|
master_key: Option<&str>,
|
||||||
workload: &BenchWorkload,
|
workload: &BenchWorkload,
|
||||||
asset_folder: &str,
|
asset_folder: &str,
|
||||||
mut command: Command,
|
mut command: TokioCommand,
|
||||||
) -> anyhow::Result<tokio::process::Child> {
|
) -> anyhow::Result<tokio::process::Child> {
|
||||||
command.arg("--db-path").arg("./_xtask_benchmark.ms");
|
command.arg("--db-path").arg("./_xtask_benchmark.ms");
|
||||||
if let Some(master_key) = master_key {
|
if let Some(master_key) = master_key {
|
||||||
@ -98,7 +99,7 @@ async fn wait_for_health(
|
|||||||
asset_folder: &str,
|
asset_folder: &str,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
for i in 0..100 {
|
for i in 0..100 {
|
||||||
let res = super::command::run(client.clone(), health_command(), assets, asset_folder).await;
|
let res = run_command(client.clone(), health_command(), assets, asset_folder).await;
|
||||||
if res.is_ok() {
|
if res.is_ok() {
|
||||||
// check that this is actually the current Meilisearch instance that answered us
|
// check that this is actually the current Meilisearch instance that answered us
|
||||||
if let Some(exit_code) =
|
if let Some(exit_code) =
|
||||||
@ -122,12 +123,12 @@ async fn wait_for_health(
|
|||||||
bail!("meilisearch is not responding")
|
bail!("meilisearch is not responding")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn health_command() -> super::command::Command {
|
fn health_command() -> Command {
|
||||||
super::command::Command {
|
Command {
|
||||||
route: "/health".into(),
|
route: "/health".into(),
|
||||||
method: crate::common::client::Method::Get,
|
method: crate::common::client::Method::Get,
|
||||||
body: Default::default(),
|
body: Default::default(),
|
||||||
synchronous: super::command::SyncMode::WaitForResponse,
|
synchronous: SyncMode::WaitForResponse,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
mod command;
|
|
||||||
mod dashboard;
|
mod dashboard;
|
||||||
mod env_info;
|
mod env_info;
|
||||||
mod meili_process;
|
mod meili_process;
|
||||||
|
@ -10,12 +10,12 @@ use serde_json::json;
|
|||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use super::command::SyncMode;
|
|
||||||
use super::dashboard::DashboardClient;
|
use super::dashboard::DashboardClient;
|
||||||
use super::BenchDeriveArgs;
|
use super::BenchDeriveArgs;
|
||||||
use crate::bench::meili_process;
|
use crate::bench::meili_process;
|
||||||
use crate::common::assets::{self, Asset};
|
use crate::common::assets::{self, Asset};
|
||||||
use crate::common::client::Client;
|
use crate::common::client::Client;
|
||||||
|
use crate::common::command::{run_batch as run_command_batch, Command, SyncMode};
|
||||||
|
|
||||||
/// A bench workload.
|
/// A bench workload.
|
||||||
/// Not to be confused with [a test workload](crate::test::workload::Workload).
|
/// Not to be confused with [a test workload](crate::test::workload::Workload).
|
||||||
@ -28,8 +28,8 @@ pub struct BenchWorkload {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub target: String,
|
pub target: String,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub precommands: Vec<super::command::Command>,
|
pub precommands: Vec<Command>,
|
||||||
pub commands: Vec<super::command::Command>,
|
pub commands: Vec<Command>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_commands(
|
async fn run_commands(
|
||||||
@ -49,8 +49,7 @@ async fn run_commands(
|
|||||||
.as_slice()
|
.as_slice()
|
||||||
.split_inclusive(|command| !matches!(command.synchronous, SyncMode::DontWait))
|
.split_inclusive(|command| !matches!(command.synchronous, SyncMode::DontWait))
|
||||||
{
|
{
|
||||||
super::command::run_batch(meili_client, batch, &workload.assets, &args.common.asset_folder)
|
run_command_batch(meili_client, batch, &workload.assets, &args.common.asset_folder).await?;
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::fs::create_dir_all(report_folder)
|
std::fs::create_dir_all(report_folder)
|
||||||
@ -66,8 +65,7 @@ async fn run_commands(
|
|||||||
.as_slice()
|
.as_slice()
|
||||||
.split_inclusive(|command| !matches!(command.synchronous, SyncMode::DontWait))
|
.split_inclusive(|command| !matches!(command.synchronous, SyncMode::DontWait))
|
||||||
{
|
{
|
||||||
super::command::run_batch(meili_client, batch, &workload.assets, &args.common.asset_folder)
|
run_command_batch(meili_client, batch, &workload.assets, &args.common.asset_folder).await?;
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let processor =
|
let processor =
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
pub mod args;
|
pub mod args;
|
||||||
pub mod assets;
|
pub mod assets;
|
||||||
pub mod client;
|
pub mod client;
|
||||||
|
pub mod command;
|
||||||
pub mod logs;
|
pub mod logs;
|
||||||
pub mod workload;
|
pub mod workload;
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
use cargo_metadata::semver::Version;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::common::{args::CommonArgs, logs::setup_logs};
|
use crate::common::command::Command;
|
||||||
|
use crate::common::{args::CommonArgs, client::Client, logs::setup_logs};
|
||||||
|
|
||||||
mod workload;
|
mod workload;
|
||||||
|
|
||||||
@ -12,10 +15,26 @@ pub struct TestDeriveArgs {
|
|||||||
/// Common arguments shared with other commands
|
/// Common arguments shared with other commands
|
||||||
#[command(flatten)]
|
#[command(flatten)]
|
||||||
common: CommonArgs,
|
common: CommonArgs,
|
||||||
|
|
||||||
|
initial_version: Version,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum CommandOrUpgrade {
|
||||||
|
Command(Command),
|
||||||
|
Upgrade { upgrade: Version },
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(args: TestDeriveArgs) -> anyhow::Result<()> {
|
pub fn run(args: TestDeriveArgs) -> anyhow::Result<()> {
|
||||||
setup_logs(&args.common.log_filter)?;
|
setup_logs(&args.common.log_filter)?;
|
||||||
|
|
||||||
|
// setup clients
|
||||||
|
let assets_client = Client::new(
|
||||||
|
None,
|
||||||
|
args.common.assets_key.as_deref(),
|
||||||
|
Some(std::time::Duration::from_secs(3600)), // 1h
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user