From 80072e4f112012d3a566c953873373a6cf9f7fed Mon Sep 17 00:00:00 2001 From: Guillaume Lagrange Date: Fri, 20 Nov 2026 15:53:41 +0100 Subject: [PATCH] feat: report the macro runner configuration in the upload metadata CodSpeed Macro Runners write a JSON object describing their configuration to /etc/codspeed/macro-runner-config.json (agent version, image build ids, runtime isolation). The CLI reads that file and forwards the object as is under runner.macroRunnerConfig. Changes to a runner's configuration can shift benchmark results, so CodSpeed needs it to tell them apart from code changes. The object is not interpreted here, so the runner can add fields without a new CLI release. A missing file means the job is not on a macro runner, and a file that cannot be read or is not a JSON object is ignored with a warning rather than failing the upload. The field is omitted when absent, so other uploads and their metadata hash are unchanged; the hash test now sets it, and the upload endpoint computes the same hash for that payload. Refs COD-3931 Co-Authored-By: Claude --- src/run_environment/provider.rs | 47 +++++++++++++++++++ src/upload/interfaces.rs | 4 ++ ..._metadata__tests__get_metadata_hash-2.snap | 8 ++++ src/upload/upload_metadata.rs | 12 ++++- 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/run_environment/provider.rs b/src/run_environment/provider.rs index 31b3328a9..3b41bedf2 100644 --- a/src/run_environment/provider.rs +++ b/src/run_environment/provider.rs @@ -3,6 +3,7 @@ use git2::Repository; use serde_json::Value; use simplelog::SharedLogger; use std::collections::BTreeMap; +use std::path::Path; use crate::api_client::CodSpeedAPIClient; use crate::executor::{ExecutorConfig, ExecutorName}; @@ -145,6 +146,7 @@ pub trait RunEnvironmentProvider { instruments: config.instruments.get_active_instrument_names(), executor: executor_name, exclude_allocations: config.exclude_allocations, + macro_runner_config: read_macro_runner_config(Path::new(MACRO_RUNNER_CONFIG_PATH)), system_info: system_info.clone(), }, run_environment: self.get_run_environment(), @@ -158,6 +160,29 @@ pub trait RunEnvironmentProvider { } } +/// Where a CodSpeed Macro Runner writes the JSON object describing its configuration. +const MACRO_RUNNER_CONFIG_PATH: &str = "/etc/codspeed/macro-runner-config.json"; + +/// The JSON object at `path`, or `None` outside a macro runner. An unreadable or malformed file is +/// ignored so it never fails the upload. +fn read_macro_runner_config(path: &Path) -> Option> { + let raw = match std::fs::read_to_string(path) { + Ok(raw) => raw, + Err(error) if error.kind() == std::io::ErrorKind::NotFound => return None, + Err(error) => { + warn!("Ignoring {}, could not read it: {error}", path.display()); + return None; + } + }; + match serde_json::from_str(&raw) { + Ok(config) => Some(config), + Err(error) => { + warn!("Ignoring {}, not a JSON object: {error}", path.display()); + None + } + } +} + 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 +207,26 @@ mod tests { // ensure that the commit hash is correct, thus it has 40 characters assert_eq!(commit_hash.len(), 40); } + + #[test] + fn test_read_macro_runner_config() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join("macro-runner-config.json"); + assert_eq!(read_macro_runner_config(&path), None); + assert_eq!(read_macro_runner_config(dir.path()), None); + + std::fs::write( + &path, + r#"{"macroAgentVersion":"0.4.0","runtimeConfig":{"isolation":"strict"}}"#, + ) + .unwrap(); + let config = read_macro_runner_config(&path).unwrap(); + assert_eq!(config["macroAgentVersion"], "0.4.0"); + assert_eq!(config["runtimeConfig"]["isolation"], "strict"); + + for malformed in ["", "not json", r#"["0.4.0"]"#, r#""0.4.0""#] { + std::fs::write(&path, malformed).unwrap(); + assert_eq!(read_macro_runner_config(&path), None); + } + } } diff --git a/src/upload/interfaces.rs b/src/upload/interfaces.rs index c03f72620..b019abd1b 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, + /// Configuration of the CodSpeed Macro Runner executing the job, as the JSON object the + /// machine writes to `/etc/codspeed/macro-runner-config.json`. Forwarded as is. + #[serde(skip_serializing_if = "Option::is_none")] + pub macro_runner_config: Option>, #[serde(flatten)] pub system_info: SystemInfo, } diff --git a/src/upload/snapshots/codspeed_runner__upload__upload_metadata__tests__get_metadata_hash-2.snap b/src/upload/snapshots/codspeed_runner__upload__upload_metadata__tests__get_metadata_hash-2.snap index eb03ece8f..5e6a7a6fe 100644 --- a/src/upload/snapshots/codspeed_runner__upload__upload_metadata__tests__get_metadata_hash-2.snap +++ b/src/upload/snapshots/codspeed_runner__upload__upload_metadata__tests__get_metadata_hash-2.snap @@ -24,6 +24,14 @@ expression: upload_metadata "MongoDB" ], "executor": "valgrind", + "macroRunnerConfig": { + "macroAgentVersion": "0.4.0", + "hostImageName": "packer-ubuntu24-x86-post-20261120093416", + "guestImageName": "packer-ubuntu24-x86-post-20261120093416", + "runtimeConfig": { + "isolation": "strict" + } + }, "os": "ubuntu", "osVersion": "20.04", "arch": "x86_64", diff --git a/src/upload/upload_metadata.rs b/src/upload/upload_metadata.rs index 533dc1144..7edc1d472 100644 --- a/src/upload/upload_metadata.rs +++ b/src/upload/upload_metadata.rs @@ -52,6 +52,14 @@ mod tests { instruments: vec![InstrumentName::MongoDB], executor: ExecutorName::Valgrind, exclude_allocations: false, + macro_runner_config: json!({ + "macroAgentVersion": "0.4.0", + "hostImageName": "packer-ubuntu24-x86-post-20261120093416", + "guestImageName": "packer-ubuntu24-x86-post-20261120093416", + "runtimeConfig": { "isolation": "strict" }, + }) + .as_object() + .cloned(), system_info: SystemInfo::test(), }, run_environment: RunEnvironment::GithubActions, @@ -87,7 +95,7 @@ mod tests { hash, // Caution: when changing this value, we need to ensure that // the related backend snapshot remains the same - @"75a9b81695bbea8934d88e221dd3dd98392170904d4775a84145767117555a60" + @"cd04217a89681d057c73e78a651ac8e7dba5f01133679df0637f4f68022d0223" ); assert_json_snapshot!(upload_metadata); } @@ -104,6 +112,7 @@ mod tests { instruments: instruments.get_active_instrument_names(), executor: get_executor_from_mode(&RunnerMode::Telemetry, None).name(), exclude_allocations: false, + macro_runner_config: None, system_info: SystemInfo::test(), }; @@ -131,6 +140,7 @@ mod tests { instruments: vec![], executor: ExecutorName::Valgrind, exclude_allocations: false, + macro_runner_config: None, system_info: SystemInfo { os: crate::system::SupportedOs::Linux( crate::system::LinuxDistribution::Other {