Skip to content

Commit a711e65

Browse files
committed
feat: add a global setup command to preinstall executors
1 parent bebfdac commit a711e65

13 files changed

Lines changed: 81 additions & 80 deletions

File tree

src/app.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{
22
api_client::CodSpeedAPIClient, auth, local_logger::CODSPEED_U8_COLOR_CODE, prelude::*, run,
3+
setup,
34
};
45
use clap::{
56
builder::{styling, Styles},
@@ -37,8 +38,10 @@ pub struct Cli {
3738
enum Commands {
3839
/// Run the bench command and upload the results to CodSpeed
3940
Run(run::RunArgs),
40-
/// Commands related to authentication with CodSpeed
41+
/// Manage the CLI authentication state
4142
Auth(auth::AuthArgs),
43+
/// Pre-install the codspeed executors
44+
Setup,
4245
}
4346

4447
pub async fn run() -> Result<()> {
@@ -48,6 +51,7 @@ pub async fn run() -> Result<()> {
4851
match cli.command {
4952
Commands::Run(args) => run::run(args, &api_client).await?,
5053
Commands::Auth(args) => auth::run(args, &api_client).await?,
54+
Commands::Setup => setup::setup().await?,
5155
}
5256
Ok(())
5357
}

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod logger;
77
mod prelude;
88
mod request_client;
99
mod run;
10+
mod setup;
1011

1112
use console::style;
1213
use lazy_static::lazy_static;
File renamed without changes.

src/run/helpers/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
mod download_file;
12
mod find_repository_root;
23
mod get_env_var;
34
mod parse_git_remote;
45

6+
pub use download_file::download_file;
57
pub use find_repository_root::find_repository_root;
68
pub use get_env_var::get_env_variable;
79
pub use parse_git_remote::*;

src/run/instruments/mongo_tracer.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
env,
23
io::Read,
34
path::{Path, PathBuf},
45
process::{Child, Command, Stdio},
@@ -10,8 +11,8 @@ use reqwest::Client;
1011
use tokio::fs;
1112
use url::Url;
1213

13-
use crate::prelude::*;
14-
use crate::run::helpers::get_env_variable;
14+
use crate::{prelude::*, run::helpers::download_file};
15+
use crate::{run::helpers::get_env_variable, MONGODB_TRACER_VERSION};
1516

1617
use super::MongoDBConfig;
1718

@@ -228,6 +229,31 @@ impl MongoTracer {
228229
}
229230
}
230231

232+
pub async fn install_mongodb_tracer() -> Result<()> {
233+
debug!("Installing mongodb-tracer");
234+
// TODO: release the tracer and update this url
235+
let installer_url = format!("https://codspeed-public-assets.s3.eu-west-1.amazonaws.com/mongo-tracer/{MONGODB_TRACER_VERSION}/cs-mongo-tracer-installer.sh");
236+
let installer_path = env::temp_dir().join("cs-mongo-tracer-installer.sh");
237+
download_file(
238+
&Url::parse(installer_url.as_str()).unwrap(),
239+
&installer_path,
240+
)
241+
.await?;
242+
243+
let output = Command::new("bash")
244+
.arg(installer_path.to_str().unwrap())
245+
.stdout(Stdio::piped())
246+
.output()
247+
.map_err(|_| anyhow!("Failed to install mongo-tracer"))?;
248+
249+
if !output.status.success() {
250+
info!("stdout: {}", String::from_utf8_lossy(&output.stdout));
251+
error!("stderr: {}", String::from_utf8_lossy(&output.stderr));
252+
bail!("Failed to install mongo-tracer");
253+
}
254+
Ok(())
255+
}
256+
231257
#[cfg(test)]
232258
mod tests {
233259
use std::ffi::OsStr;

src/run/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ use crate::run::{config::Config, logger::Logger};
55
use crate::VERSION;
66
use check_system::SystemInfo;
77
use clap::Args;
8-
use instruments::mongo_tracer::MongoTracer;
8+
use instruments::mongo_tracer::{install_mongodb_tracer, MongoTracer};
99
use run_environment::interfaces::RunEnvironment;
1010
use runner::get_run_data;
1111

12-
mod check_system;
13-
mod helpers;
12+
pub mod check_system;
13+
pub mod helpers;
1414
mod instruments;
1515
mod poll_results;
1616
pub mod run_environment;
17-
mod runner;
17+
pub mod runner;
1818
mod uploader;
1919

2020
pub mod config;
@@ -120,14 +120,19 @@ pub async fn run(args: RunArgs, api_client: &CodSpeedAPIClient) -> Result<()> {
120120
let mode = runner::get_mode()?;
121121
let executor = runner::get_executor_from_mode(mode);
122122

123-
let run_data = get_run_data()?;
124-
125123
if !config.skip_setup {
126124
start_group!("Preparing the environment");
127-
executor.setup(&config, &system_info, &run_data).await?;
125+
executor.setup(&system_info).await?;
126+
// TODO: refactor and move directly in the Instruments struct as a `setup` method
127+
if config.instruments.is_mongodb_enabled() {
128+
install_mongodb_tracer().await?;
129+
}
130+
info!("Environment ready");
128131
end_group!();
129132
}
130133

134+
let run_data = get_run_data()?;
135+
131136
start_opened_group!("Running the benchmarks");
132137

133138
// TODO: refactor and move directly in the Instruments struct as a `start` method

src/run/runner/executor.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ use async_trait::async_trait;
88
pub trait Executor {
99
fn name(&self) -> ExecutorName;
1010

11-
async fn setup(
12-
&self,
13-
config: &Config,
14-
system_info: &SystemInfo,
15-
run_data: &RunData,
16-
) -> Result<()>;
11+
async fn setup(&self, _system_info: &SystemInfo) -> Result<()> {
12+
Ok(())
13+
}
1714

1815
/// Runs the executor
1916
async fn run(

src/run/runner/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ pub fn get_executor_from_mode(mode: RunnerMode) -> Box<dyn Executor> {
6060
}
6161
}
6262

63+
pub fn get_all_executors() -> Vec<Box<dyn Executor>> {
64+
vec![Box::new(ValgrindExecutor), Box::new(WallTimeExecutor)]
65+
}
66+
6367
pub fn get_run_data() -> Result<RunData> {
6468
let profile_folder = create_profile_folder()?;
6569
Ok(RunData { profile_folder })

src/run/runner/valgrind/executor.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use crate::run::runner::executor::Executor;
66
use crate::run::runner::{ExecutorName, RunData};
77
use crate::run::{check_system::SystemInfo, config::Config};
88

9-
use super::{helpers::perf_maps::harvest_perf_maps, measure, setup::setup};
9+
use super::setup::install_valgrind;
10+
use super::{helpers::perf_maps::harvest_perf_maps, measure};
1011

1112
pub struct ValgrindExecutor;
1213

@@ -16,14 +17,8 @@ impl Executor for ValgrindExecutor {
1617
ExecutorName::Valgrind
1718
}
1819

19-
async fn setup(
20-
&self,
21-
config: &Config,
22-
system_info: &SystemInfo,
23-
_run_data: &RunData,
24-
) -> Result<()> {
25-
setup(system_info, config).await?;
26-
20+
async fn setup(&self, system_info: &SystemInfo) -> Result<()> {
21+
install_valgrind(system_info).await?;
2722
Ok(())
2823
}
2924

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
pub mod download_file;
21
pub mod ignored_objects_path;
32
pub mod introspected_nodejs;
43
pub mod perf_maps;

0 commit comments

Comments
 (0)