From fec69e4373c90affb41aa9822ebb3c78f6cce7e3 Mon Sep 17 00:00:00 2001 From: MasterPtato Date: Wed, 4 Jun 2025 21:45:52 +0000 Subject: [PATCH] feat(clusters): add margin per pool --- .../src/config/server/rivet/cluster_provision.rs | 15 +-------------- packages/core/services/cluster/src/types.rs | 4 ++++ .../cluster/src/workflows/datacenter/mod.rs | 12 ++++++++---- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/packages/common/config/src/config/server/rivet/cluster_provision.rs b/packages/common/config/src/config/server/rivet/cluster_provision.rs index 93c8049cd4..112d1c7737 100644 --- a/packages/common/config/src/config/server/rivet/cluster_provision.rs +++ b/packages/common/config/src/config/server/rivet/cluster_provision.rs @@ -8,7 +8,7 @@ use url::Url; #[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct ClusterProvision { - /// Configuration for server pools that use a margin for scaling. + /// Configuration for server pools. pub pools: ClusterPools, #[schemars(with = "Option")] @@ -53,7 +53,6 @@ pub struct ClusterPools { #[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct ClusterPoolJob { - pub autoscale_margin: u32, // All other properties are read from Pegboard since they're identical } @@ -62,8 +61,6 @@ pub struct ClusterPoolJob { #[derive(Debug, Serialize, Deserialize, Clone, Default, JsonSchema)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct ClusterPoolPegboard { - pub autoscale_margin: u32, - pub vlan_addr_range_min: Option, pub vlan_addr_range_max: Option, @@ -134,8 +131,6 @@ impl ClusterPoolPegboard { #[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct ClusterPoolGg { - pub autoscale_margin: u32, - #[schemars(with = "Option")] pub vlan_ip_net: Option, pub firewall_rules: Option>, @@ -217,8 +212,6 @@ impl ClusterPoolGg { #[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct ClusterPoolAts { - pub autoscale_margin: u32, - #[schemars(with = "Option")] pub vlan_ip_net: Option, pub firewall_rules: Option>, @@ -263,8 +256,6 @@ impl ClusterPoolFdb { #[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct ClusterPoolWorker { - pub autoscale_margin: u32, - #[schemars(with = "Option")] pub vlan_ip_net: Option, pub firewall_rules: Option>, @@ -287,8 +278,6 @@ impl ClusterPoolWorker { #[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct ClusterPoolNats { - pub autoscale_margin: u32, - #[schemars(with = "Option")] pub vlan_ip_net: Option, pub firewall_rules: Option>, @@ -311,8 +300,6 @@ impl ClusterPoolNats { #[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct ClusterPoolGuard { - pub autoscale_margin: u32, - #[schemars(with = "Option")] pub vlan_ip_net: Option, pub firewall_rules: Option>, diff --git a/packages/core/services/cluster/src/types.rs b/packages/core/services/cluster/src/types.rs index e554d113b1..ca74c26248 100644 --- a/packages/core/services/cluster/src/types.rs +++ b/packages/core/services/cluster/src/types.rs @@ -49,6 +49,8 @@ pub struct Pool { pub min_count: u32, pub max_count: u32, pub drain_timeout: u64, + #[serde(default)] + pub margin: u32, } // Backwards compatibility @@ -69,6 +71,7 @@ impl TryFrom for Pool { min_count: value.min_count, max_count: value.max_count, drain_timeout: value.drain_timeout, + margin: 0, }) } } @@ -119,6 +122,7 @@ pub struct PoolUpdate { pub min_count: Option, pub max_count: Option, pub drain_timeout: Option, + pub margin: Option, } #[derive(Serialize, Deserialize, Hash, Debug, Clone, Copy, PartialEq, Eq, FromRepr)] diff --git a/packages/core/services/cluster/src/workflows/datacenter/mod.rs b/packages/core/services/cluster/src/workflows/datacenter/mod.rs index c08505a0ba..025cab686e 100644 --- a/packages/core/services/cluster/src/workflows/datacenter/mod.rs +++ b/packages/core/services/cluster/src/workflows/datacenter/mod.rs @@ -316,26 +316,29 @@ async fn update_db(ctx: &ActivityCtx, input: &UpdateDbInput) -> GlobalResult<()> if let Some(drain_timeout) = pool.drain_timeout { current_pool.drain_timeout = drain_timeout; } + if let Some(margin) = pool.margin { + current_pool.margin = margin; + } } else { tracing::info!(pool_type=?pool.pool_type, "creating new pool"); if pool.hardware.is_empty() { - tracing::warn!("must define hardware when creating new pool"); + tracing::error!("must define hardware when creating new pool"); return Ok(()); } let Some(min_count) = pool.min_count else { - tracing::warn!("must have `min_count` when creating a new pool"); + tracing::error!("must have `min_count` when creating a new pool"); return Ok(()); }; let Some(max_count) = pool.max_count else { - tracing::warn!("must have `max_count` when creating a new pool"); + tracing::error!("must have `max_count` when creating a new pool"); return Ok(()); }; let Some(drain_timeout) = pool.drain_timeout else { - tracing::warn!("must have `max_count` when creating a new pool"); + tracing::error!("must have `max_count` when creating a new pool"); return Ok(()); }; @@ -346,6 +349,7 @@ async fn update_db(ctx: &ActivityCtx, input: &UpdateDbInput) -> GlobalResult<()> min_count, max_count, drain_timeout, + margin: 0, }); }; }