Skip to content

Commit fec69e4

Browse files
committed
feat(clusters): add margin per pool
1 parent 78b6466 commit fec69e4

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

packages/common/config/src/config/server/rivet/cluster_provision.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use url::Url;
88
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
99
#[serde(rename_all = "snake_case", deny_unknown_fields)]
1010
pub struct ClusterProvision {
11-
/// Configuration for server pools that use a margin for scaling.
11+
/// Configuration for server pools.
1212
pub pools: ClusterPools,
1313

1414
#[schemars(with = "Option<String>")]
@@ -53,7 +53,6 @@ pub struct ClusterPools {
5353
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
5454
#[serde(rename_all = "snake_case", deny_unknown_fields)]
5555
pub struct ClusterPoolJob {
56-
pub autoscale_margin: u32,
5756
// All other properties are read from Pegboard since they're identical
5857
}
5958

@@ -62,8 +61,6 @@ pub struct ClusterPoolJob {
6261
#[derive(Debug, Serialize, Deserialize, Clone, Default, JsonSchema)]
6362
#[serde(rename_all = "snake_case", deny_unknown_fields)]
6463
pub struct ClusterPoolPegboard {
65-
pub autoscale_margin: u32,
66-
6764
pub vlan_addr_range_min: Option<Ipv4Addr>,
6865
pub vlan_addr_range_max: Option<Ipv4Addr>,
6966

@@ -134,8 +131,6 @@ impl ClusterPoolPegboard {
134131
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
135132
#[serde(rename_all = "snake_case", deny_unknown_fields)]
136133
pub struct ClusterPoolGg {
137-
pub autoscale_margin: u32,
138-
139134
#[schemars(with = "Option<String>")]
140135
pub vlan_ip_net: Option<Ipv4Net>,
141136
pub firewall_rules: Option<Vec<FirewallRule>>,
@@ -217,8 +212,6 @@ impl ClusterPoolGg {
217212
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
218213
#[serde(rename_all = "snake_case", deny_unknown_fields)]
219214
pub struct ClusterPoolAts {
220-
pub autoscale_margin: u32,
221-
222215
#[schemars(with = "Option<String>")]
223216
pub vlan_ip_net: Option<Ipv4Net>,
224217
pub firewall_rules: Option<Vec<FirewallRule>>,
@@ -263,8 +256,6 @@ impl ClusterPoolFdb {
263256
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
264257
#[serde(rename_all = "snake_case", deny_unknown_fields)]
265258
pub struct ClusterPoolWorker {
266-
pub autoscale_margin: u32,
267-
268259
#[schemars(with = "Option<String>")]
269260
pub vlan_ip_net: Option<Ipv4Net>,
270261
pub firewall_rules: Option<Vec<FirewallRule>>,
@@ -287,8 +278,6 @@ impl ClusterPoolWorker {
287278
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
288279
#[serde(rename_all = "snake_case", deny_unknown_fields)]
289280
pub struct ClusterPoolNats {
290-
pub autoscale_margin: u32,
291-
292281
#[schemars(with = "Option<String>")]
293282
pub vlan_ip_net: Option<Ipv4Net>,
294283
pub firewall_rules: Option<Vec<FirewallRule>>,
@@ -311,8 +300,6 @@ impl ClusterPoolNats {
311300
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
312301
#[serde(rename_all = "snake_case", deny_unknown_fields)]
313302
pub struct ClusterPoolGuard {
314-
pub autoscale_margin: u32,
315-
316303
#[schemars(with = "Option<String>")]
317304
pub vlan_ip_net: Option<Ipv4Net>,
318305
pub firewall_rules: Option<Vec<FirewallRule>>,

packages/core/services/cluster/src/types.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ pub struct Pool {
4949
pub min_count: u32,
5050
pub max_count: u32,
5151
pub drain_timeout: u64,
52+
#[serde(default)]
53+
pub margin: u32,
5254
}
5355

5456
// Backwards compatibility
@@ -69,6 +71,7 @@ impl TryFrom<backend::cluster::Pool> for Pool {
6971
min_count: value.min_count,
7072
max_count: value.max_count,
7173
drain_timeout: value.drain_timeout,
74+
margin: 0,
7275
})
7376
}
7477
}
@@ -119,6 +122,7 @@ pub struct PoolUpdate {
119122
pub min_count: Option<u32>,
120123
pub max_count: Option<u32>,
121124
pub drain_timeout: Option<u64>,
125+
pub margin: Option<u32>,
122126
}
123127

124128
#[derive(Serialize, Deserialize, Hash, Debug, Clone, Copy, PartialEq, Eq, FromRepr)]

packages/core/services/cluster/src/workflows/datacenter/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,26 +316,29 @@ async fn update_db(ctx: &ActivityCtx, input: &UpdateDbInput) -> GlobalResult<()>
316316
if let Some(drain_timeout) = pool.drain_timeout {
317317
current_pool.drain_timeout = drain_timeout;
318318
}
319+
if let Some(margin) = pool.margin {
320+
current_pool.margin = margin;
321+
}
319322
} else {
320323
tracing::info!(pool_type=?pool.pool_type, "creating new pool");
321324

322325
if pool.hardware.is_empty() {
323-
tracing::warn!("must define hardware when creating new pool");
326+
tracing::error!("must define hardware when creating new pool");
324327
return Ok(());
325328
}
326329

327330
let Some(min_count) = pool.min_count else {
328-
tracing::warn!("must have `min_count` when creating a new pool");
331+
tracing::error!("must have `min_count` when creating a new pool");
329332
return Ok(());
330333
};
331334

332335
let Some(max_count) = pool.max_count else {
333-
tracing::warn!("must have `max_count` when creating a new pool");
336+
tracing::error!("must have `max_count` when creating a new pool");
334337
return Ok(());
335338
};
336339

337340
let Some(drain_timeout) = pool.drain_timeout else {
338-
tracing::warn!("must have `max_count` when creating a new pool");
341+
tracing::error!("must have `max_count` when creating a new pool");
339342
return Ok(());
340343
};
341344

@@ -346,6 +349,7 @@ async fn update_db(ctx: &ActivityCtx, input: &UpdateDbInput) -> GlobalResult<()>
346349
min_count,
347350
max_count,
348351
drain_timeout,
352+
margin: 0,
349353
});
350354
};
351355
}

0 commit comments

Comments
 (0)