Skip to content

Commit

Permalink
fix(integrations): add correct env variables to the bench command
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencaccia committed Dec 7, 2023
1 parent 5d46635 commit 8605a92
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
26 changes: 23 additions & 3 deletions src/integrations/mongo_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct MongoTracer {
profile_folder: PathBuf,
proxy_host_port: String,
destination_host_port: String,
uri_env_name: String,
}

impl MongoTracer {
Expand All @@ -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(),
})
}

Expand All @@ -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);
Expand Down Expand Up @@ -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()),
]);
}
}
2 changes: 1 addition & 1 deletion src/runner/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub async fn run(config: &Config, integrations: &Integrations) -> Result<RunData
}
None => 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?;
Expand Down
12 changes: 11 additions & 1 deletion src/runner/valgrind.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<MongoTracer>,
) -> Result<()> {
debug!("profile dir: {}", profile_folder.display());

// Create the command
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8605a92

Please sign in to comment.