diff --git a/src/integrations/mongo_tracer.rs b/src/integrations/mongo_tracer.rs index 66fd4b3..9fb338b 100644 --- a/src/integrations/mongo_tracer.rs +++ b/src/integrations/mongo_tracer.rs @@ -17,6 +17,7 @@ pub struct MongoTracer { profile_folder: PathBuf, proxy_host_port: String, destination_host_port: String, + uri_env_name: String, } impl MongoTracer { @@ -25,14 +26,16 @@ impl MongoTracer { "Retrieving the value of {} to patch the MongoDB URI", mongodb_config.uri_env_name ); - let proxy_host_port = get_env_variable(mongodb_config.uri_env_name.as_str())?; + let destination_host_port = get_env_variable(mongodb_config.uri_env_name.as_str())?; Ok(Self { process: None, server_address: "0.0.0.0:55581".into(), profile_folder: profile_folder.into(), - destination_host_port: "localhost:27018".into(), - proxy_host_port, + // TODO: later choose a random available port dynamically, and/or make it configurable + proxy_host_port: "mongodb://localhost:27018".into(), + destination_host_port, + uri_env_name: mongodb_config.uri_env_name.clone(), }) } @@ -52,6 +55,11 @@ impl MongoTracer { self.destination_host_port.as_str(), ), ]); + debug!("Start the MongoDB tracer: {:?}", command); + debug!( + "Proxy MongoDB from {} to {}", + self.proxy_host_port, self.destination_host_port + ); let process = command.spawn()?; self.process = Some(process); @@ -83,4 +91,16 @@ impl MongoTracer { Ok(()) } + + /// Applies the necessary transformations to the command to run the benchmark + /// TODO: move this to a `Instrument` trait, refactor and implement it for valgring as well + pub fn apply_run_command_transformations(&self, command: &mut Command) { + command.envs(vec![ + ( + "CODSPEED_MONGO_INSTR_SERVER_ADDRESS", + self.server_address.as_str(), + ), + (self.uri_env_name.as_str(), self.proxy_host_port.as_str()), + ]); + } } diff --git a/src/runner/run.rs b/src/runner/run.rs index 22c9a67..6913213 100644 --- a/src/runner/run.rs +++ b/src/runner/run.rs @@ -34,7 +34,7 @@ pub async fn run(config: &Config, integrations: &Integrations) -> Result None, }; - valgrind::measure(config, &profile_folder)?; + valgrind::measure(config, &profile_folder, &mongo_tracer)?; harvest_perf_maps(&profile_folder)?; if let Some(mut mongo_tracer) = mongo_tracer { mongo_tracer.stop().await?; diff --git a/src/runner/valgrind.rs b/src/runner/valgrind.rs index a57b5ad..5e44847 100644 --- a/src/runner/valgrind.rs +++ b/src/runner/valgrind.rs @@ -1,4 +1,5 @@ use crate::config::Config; +use crate::integrations::mongo_tracer::MongoTracer; use crate::prelude::*; use crate::runner::helpers::ignored_objects_path::get_objects_path_to_ignore; use crate::runner::helpers::introspected_node::setup_introspected_node; @@ -53,7 +54,11 @@ fn get_bench_command(config: &Config) -> String { .replace("cargo codspeed", "cargo-codspeed") } -pub fn measure(config: &Config, profile_folder: &Path) -> Result<()> { +pub fn measure( + config: &Config, + profile_folder: &Path, + mongo_tracer: &Option, +) -> Result<()> { debug!("profile dir: {}", profile_folder.display()); // Create the command @@ -91,6 +96,11 @@ pub fn measure(config: &Config, profile_folder: &Path) -> Result<()> { // Set the command to execute cmd.args(["sh", "-c", get_bench_command(config).as_str()]); + // TODO: refactor and move this to the `Instrumentation` trait + if let Some(mongo_tracer) = mongo_tracer { + mongo_tracer.apply_run_command_transformations(&mut cmd); + } + debug!("cmd: {:?}", cmd); let status = cmd .status()