diff --git a/src/run_environment/provider.rs b/src/run_environment/provider.rs index 31b3328a9..12d9200dd 100644 --- a/src/run_environment/provider.rs +++ b/src/run_environment/provider.rs @@ -145,6 +145,7 @@ pub trait RunEnvironmentProvider { instruments: config.instruments.get_active_instrument_names(), executor: executor_name, exclude_allocations: config.exclude_allocations, + isolation: get_runner_isolation(), system_info: system_info.clone(), }, run_environment: self.get_run_environment(), @@ -158,6 +159,13 @@ pub trait RunEnvironmentProvider { } } +fn get_runner_isolation() -> Option { + std::env::var("CODSPEED_RUNNER_ISOLATION") + .ok() + .map(|value| value.trim().to_string()) + .filter(|value| !value.is_empty()) +} + fn get_commit_hash_default_impl(repository_root_path: &str) -> Result { let repo = Repository::open(repository_root_path).context(format!( "Failed to open repository at path: {repository_root_path}" @@ -182,4 +190,17 @@ mod tests { // ensure that the commit hash is correct, thus it has 40 characters assert_eq!(commit_hash.len(), 40); } + + #[test] + fn test_get_runner_isolation() { + temp_env::with_var("CODSPEED_RUNNER_ISOLATION", Some(" strict "), || { + assert_eq!(get_runner_isolation(), Some("strict".into())); + }); + temp_env::with_var("CODSPEED_RUNNER_ISOLATION", Some(" "), || { + assert_eq!(get_runner_isolation(), None); + }); + temp_env::with_var_unset("CODSPEED_RUNNER_ISOLATION", || { + assert_eq!(get_runner_isolation(), None); + }); + } } diff --git a/src/upload/interfaces.rs b/src/upload/interfaces.rs index c03f72620..c3909f28f 100644 --- a/src/upload/interfaces.rs +++ b/src/upload/interfaces.rs @@ -55,6 +55,10 @@ pub struct Runner { /// byte-identical to legacy runs that predate this field. #[serde(skip_serializing_if = "std::ops::Not::not")] pub exclude_allocations: bool, + /// Isolation level of the machine running the benchmarks, as reported by + /// the environment through `CODSPEED_RUNNER_ISOLATION`. + #[serde(skip_serializing_if = "Option::is_none")] + pub isolation: Option, #[serde(flatten)] pub system_info: SystemInfo, } diff --git a/src/upload/upload_metadata.rs b/src/upload/upload_metadata.rs index 5d3c8945b..d031500b5 100644 --- a/src/upload/upload_metadata.rs +++ b/src/upload/upload_metadata.rs @@ -49,6 +49,7 @@ mod tests { instruments: vec![InstrumentName::MongoDB], executor: ExecutorName::Valgrind, exclude_allocations: false, + isolation: None, system_info: SystemInfo::test(), }, run_environment: RunEnvironment::GithubActions, @@ -108,6 +109,7 @@ mod tests { instruments: vec![], executor: ExecutorName::Valgrind, exclude_allocations: false, + isolation: None, system_info: SystemInfo { os: crate::system::SupportedOs::Linux( crate::system::LinuxDistribution::Other {