From 72e93f96a4358a52f6b1ac5572314477fa38eb26 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Thu, 21 Sep 2023 09:49:17 -0700 Subject: [PATCH 1/2] Categories are now a mapping of architecture to list of hardware categories This allows adding arbitrary categories to supplement others. Tested by panicking before hitting the EM API. --- hardware_categories.json | 77 ++++++++++++++++++++++++++-------------- src/hardware.rs | 36 +++++++++++-------- 2 files changed, 71 insertions(+), 42 deletions(-) diff --git a/hardware_categories.json b/hardware_categories.json index 76bcf71..75eb426 100644 --- a/hardware_categories.json +++ b/hardware_categories.json @@ -1,66 +1,89 @@ { - "category": { - "aarch64-linux": { - "bigparallel": { - "divisor": 2000, - "minimum": 1, + "categories": { + "aarch64-linux": [ + { + "divisor": 5, "maximum": 5, + "minimum": 1, "plans": [ { - "bid": 2.0, + "bid": 2, "netboot_url": "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/c3-large-arm--big-parallel", "plan": "c3.large.arm64" } - ] + ], + "size": "bigparallel" }, - "small": { + { "divisor": 2000, - "minimum": 1, "maximum": 5, + "minimum": 1, + "plans": [ + { + "bid": 2, + "netboot_url": "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/c3-large-arm", + "plan": "c3.large.arm64" + } + ], + "size": "small" + }, + { + "divisor": 5000, + "maximum": 1, + "minimum": 0, "plans": [ { - "bid": 2.0, + "bid": 2.5, "netboot_url": "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/c3-large-arm", "plan": "c3.large.arm64" } - ] + ], + "size": "small" } - }, - "x86_64-linux": { - "bigparallel": { - "divisor": 2000, - "minimum": 1, + ], + "x86_64-linux": [ + { + "divisor": 5, "maximum": 5, + "minimum": 1, "plans": [ { - "bid": 2.0, + "bid": 2, "netboot_url": "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/c3-medium-x86--big-parallel", "plan": "c3.medium.x86" }, { - "bid": 2.0, + "bid": 2, "netboot_url": "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/m3-large-x86--big-parallel", "plan": "m3.large.x86" } - ] + ], + "size": "bigparallel" }, - "small": { + { "divisor": 2000, - "minimum": 1, "maximum": 5, + "minimum": 1, "plans": [ { - "bid": 2.0, + "bid": 2, "netboot_url": "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/c3-medium-x86", "plan": "c3.medium.x86" }, { - "bid": 2.0, + "bid": 2, "netboot_url": "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/m3-large-x86", "plan": "m3.large.x86" } - ] + ], + "size": "small" } - } - } -} \ No newline at end of file + ] + }, + "facilities": [ + "any" + ], + "tags": [ + "hydra" + ] +} diff --git a/src/hardware.rs b/src/hardware.rs index d9da401..2410ab2 100644 --- a/src/hardware.rs +++ b/src/hardware.rs @@ -28,13 +28,14 @@ pub struct HardwarePlan { #[derive(Clone, Debug, Deserialize)] pub struct HardwareCategory { + pub size: JobSize, pub divisor: usize, pub minimum: usize, pub maximum: usize, pub plans: Vec, } -type CategoryMap = HashMap>; +type CategoryMap = HashMap>; #[derive(Deserialize)] pub struct Config { @@ -43,6 +44,7 @@ pub struct Config { facilities: Vec, } +#[derive(Debug)] pub struct DesiredHardwareConfig { pub plans: Vec, pub tags: Vec, @@ -93,21 +95,25 @@ pub async fn get_desired_hardware( let mut desired_hardware: Vec = vec![]; for (system, sizes) in buckets.iter() { for (size, runnable) in sizes.iter() { - if let Some(category) = categories.get(system).and_then(|e| e.get(size)) { - let wanted = min( - category.maximum, - max(category.minimum, runnable / category.divisor), - ); - if category.plans.is_empty() { - println!( - "WARNING: {:?}/{:?}'s hardwarecategory has no plans", - system, size - ); - - continue; + if let Some(size_categories) = categories + .get(system) + .and_then(|cats| Some(cats.iter().filter(|cat| &cat.size == size))) + { + for category in size_categories { + if category.plans.is_empty() { + println!( + "WARNING: {:?}/{:?}'s hardwarecategory has no plans", + system, size + ); + } else { + let wanted = min( + category.maximum, + max(category.minimum, runnable / category.divisor), + ); + desired_hardware + .extend(category.plans.iter().cycle().take(wanted).cloned()); + } } - - desired_hardware.extend(category.plans.iter().cycle().take(wanted).cloned()); } else { println!( "WARNING: {:?}/{:?} has no hardwarecategory in the hardware map", From dbc5fc3ad928dde24f309d0f268f4d0f66cc0f64 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Thu, 21 Sep 2023 10:00:19 -0700 Subject: [PATCH 2/2] Normalize the bids since I'm not copying the comment here See https://github.com/NixOS/nixos-org-configurations/pull/280 for the reason why it was 2.5 and why this PR exists in the first place. --- hardware_categories.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hardware_categories.json b/hardware_categories.json index 75eb426..12a21ca 100644 --- a/hardware_categories.json +++ b/hardware_categories.json @@ -33,7 +33,7 @@ "minimum": 0, "plans": [ { - "bid": 2.5, + "bid": 2, "netboot_url": "https://netboot.nixos.org/dispatch/hydra/hydra.nixos.org/equinix-metal-builders/main/c3-large-arm", "plan": "c3.large.arm64" }