Skip to content

Commit 7f44ebd

Browse files
committed
chore: correct graph synching code
1 parent bac836f commit 7f44ebd

File tree

1 file changed

+41
-16
lines changed

1 file changed

+41
-16
lines changed

crates/xtask/src/main.rs

+41-16
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,8 @@ impl Xtasks {
12241224
}
12251225

12261226
fn bench(app_settings: GlobalArgs, execute: bool) -> Result<()> {
1227-
// first of all figure out which branch we're on
1228-
// run // git rev-parse --abbrev-ref HEAD
1227+
// // first of all figure out which branch we're on
1228+
// // run // git rev-parse --abbrev-ref HEAD
12291229
let workspace_dir = Self::workspace_dir(&app_settings).unwrap();
12301230
let command = Command::new("git")
12311231
.args(["rev-parse", "--abbrev-ref", "HEAD"])
@@ -1273,8 +1273,8 @@ impl Xtasks {
12731273
.args(["--thresholds-reset"])
12741274
.args(["--err"]);
12751275

1276-
if let Some(token) = github_token {
1277-
bencher_cmd.args(["--github-actions", &token]);
1276+
if let Some(token) = &github_token {
1277+
bencher_cmd.args(["--github-actions", token]);
12781278
}
12791279

12801280
if !is_main || !execute {
@@ -1295,7 +1295,7 @@ impl Xtasks {
12951295
}
12961296

12971297
// if we're on linux and publishing and on main synch graphs
1298-
if os == "linux" && is_main && execute {
1298+
if os == "linux" && is_main && execute && github_token.is_some() {
12991299
Self::synch_bencher_graphs()?;
13001300
}
13011301

@@ -1307,13 +1307,26 @@ impl Xtasks {
13071307
// this produces list of objects each containing a `uuid` and `name`
13081308

13091309
let parse_list_of_dicts = |bytes: Vec<u8>| {
1310-
serde_json::from_slice::<Vec<HashMap<String, String>>>(&bytes)
1310+
if bytes.is_empty() {
1311+
bail!("Empty input");
1312+
}
1313+
serde_json::from_slice::<Vec<HashMap<String, serde_json::Value>>>(&bytes)
1314+
.map(|map| {
1315+
map.into_iter()
1316+
.map(|map| {
1317+
map.into_iter()
1318+
.map(|(k, v)| (k, v.as_str().unwrap_or_default().to_string()))
1319+
.collect::<HashMap<_, _>>()
1320+
})
1321+
.collect::<Vec<_>>()
1322+
})
13111323
.with_context(|| "Could not parse bencher output")
13121324
};
13131325

13141326
let token = std::env::var("BENCHER_API_TOKEN").ok();
13151327
let mut bencher_cmd = Command::new("bencher");
13161328
let benchmarks = bencher_cmd
1329+
.stdout(std::process::Stdio::piped())
13171330
.arg("benchmark")
13181331
.args(["list", "bms"])
13191332
.args(["--token", &token.clone().unwrap_or_default()])
@@ -1324,7 +1337,8 @@ impl Xtasks {
13241337
}
13251338

13261339
// parse teh name and uuid pairs
1327-
let benchmarks = parse_list_of_dicts(benchmarks.stdout)?
1340+
let benchmarks = parse_list_of_dicts(benchmarks.stdout)
1341+
.with_context(|| "Reading benchmarks")?
13281342
.into_iter()
13291343
.map(|p| {
13301344
let name = p.get("name").expect("no name in project");
@@ -1337,7 +1351,7 @@ impl Xtasks {
13371351
// then bencher plot delete bms <uuid>
13381352

13391353
let bencher_cmd = Command::new("bencher")
1340-
.stdout(std::process::Stdio::inherit())
1354+
.stdout(std::process::Stdio::piped())
13411355
.stderr(std::process::Stdio::inherit())
13421356
.args(["plot", "list", "bms"])
13431357
.args(["--token", &token.clone().unwrap_or_default()])
@@ -1348,9 +1362,11 @@ impl Xtasks {
13481362
bail!("Failed to list plots: {:?}", bencher_cmd);
13491363
}
13501364

1351-
let plots = parse_list_of_dicts(bencher_cmd.stdout)?
1365+
let plots = parse_list_of_dicts(bencher_cmd.stdout)
1366+
.with_context(|| "reading plots")?
13521367
.into_iter()
13531368
.map(|p| {
1369+
log::info!("Plot to delete: {:?}", p);
13541370
let uuid = p.get("uuid").expect("no uuid in plot");
13551371
uuid.clone()
13561372
})
@@ -1376,11 +1392,15 @@ impl Xtasks {
13761392
.output()
13771393
.with_context(|| "Could not list testbeds")?;
13781394

1395+
const MAIN_BRANCH_UUID: &str = "1d70a4e3-d416-43fc-91bd-4b1c8f9e9580";
1396+
const LATENCY_MEASURE_UUID: &str = "6820b034-5163-4cdd-95f5-5640dd0ff298";
1397+
13791398
if !testbeds.status.success() {
13801399
bail!("Failed to list testbeds: {:?}", testbeds);
13811400
}
13821401

1383-
let testbeds = parse_list_of_dicts(testbeds.stdout)?
1402+
let testbeds = parse_list_of_dicts(testbeds.stdout)
1403+
.with_context(|| "reading testbeds")?
13841404
.into_iter()
13851405
.map(|p| {
13861406
let name = p.get("name").expect("no name in testbed");
@@ -1409,19 +1429,24 @@ impl Xtasks {
14091429

14101430
let window_months = 12;
14111431
let window_seconds = window_months * 30 * 24 * 60 * 60;
1412-
let bencher_cmd = Command::new("bencher")
1432+
let mut bencher_cmd = Command::new("bencher");
1433+
bencher_cmd
14131434
.stdout(std::process::Stdio::inherit())
14141435
.stderr(std::process::Stdio::inherit())
14151436
.args(["plot", "create", "bms"])
14161437
.args(["--title", &plot_name])
1417-
.arg("--upper-boundary")
14181438
.args(["--x-axis", "date_time"])
14191439
.args(["--window", &window_seconds.to_string()])
1420-
.args(["--branches", "main"])
1440+
.args(["--branches", MAIN_BRANCH_UUID])
14211441
.args(["--testbeds", testbed_uuid])
1422-
.args(["--benchmarks", &uuids.join(",")])
1423-
.args(["--measures", "latency"])
1424-
.args(["--token", &token.clone().unwrap_or_default()])
1442+
.args(["--measures", LATENCY_MEASURE_UUID])
1443+
.args(["--token", &token.clone().unwrap_or_default()]);
1444+
1445+
for benchmark_uuid in &uuids {
1446+
bencher_cmd.arg("--benchmarks").arg(benchmark_uuid);
1447+
}
1448+
1449+
let bencher_cmd = bencher_cmd
14251450
.output()
14261451
.with_context(|| "Could not create plot")?;
14271452

0 commit comments

Comments
 (0)