fix: leave draining workers out of the autoscaling count (#12739)

* [ee] fix: leave draining workers out of the autoscaling count

Pins the EE fix and adds a regression test that drives
apply_all_autoscaling against planted worker_ping rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: cover a worker group restarting in place

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: cover a scale-in during a partial in-place restart

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: update ee-repo-ref to 23291f201b34b6f3d8e08b11783413a22a43a15f

This commit updates the EE repository reference after PR #1024 was merged in windmill-ee-private.

Previous ee-repo-ref: 331be09b5e61c55b4f3823c76cd5233b3878ac91

New ee-repo-ref: 23291f201b34b6f3d8e08b11783413a22a43a15f

Automated by sync-ee-ref workflow.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
This commit is contained in:
Ruben Fiszel
2026-11-29 10:23:54 +01:00
committed by GitHub
co-authored by Claude Opus 5.5 windmill-internal-app[bot]
parent 3b333380fd
commit dd206df8e3
2 changed files with 137 additions and 1 deletions
+1 -1
View File
@@ -1 +1 @@
b012f1c9ecd42a6f99808cad65c519e2a3bc35c1
23291f201b34b6f3d8e08b11783413a22a43a15f
+136
View File
@@ -0,0 +1,136 @@
//! The worker count autoscaling decides from, driven through `apply_all_autoscaling` with a
//! dry-run integration against planted `worker_ping` rows.
#![cfg(all(feature = "enterprise", feature = "private"))]
use sqlx::{Pool, Postgres};
use windmill_autoscaling::apply_all_autoscaling;
async fn setup(db: &Pool<Postgres>) -> anyhow::Result<()> {
let updated = sqlx::query(
r#"UPDATE config SET config = config || '{"autoscaling": {"enabled": true, "min_workers": 2,
"max_workers": 12, "integration": {"type": "dryrun"}}}'::jsonb
WHERE name = 'worker__default'"#,
)
.execute(db)
.await?
.rows_affected();
assert_eq!(updated, 1, "the default worker group config is seeded");
Ok(())
}
async fn plant_workers(db: &Pool<Postgres>, n: i32, draining: bool) -> anyhow::Result<()> {
sqlx::query(
"INSERT INTO worker_ping (worker, worker_instance, worker_group, started_at, draining)
SELECT 'wk-' || $2::text || '-' || i, 'pod-' || $2::text || '-' || i, 'default',
now() - interval '1 hour', $2
FROM generate_series(1, $1) AS i",
)
.bind(n)
.bind(draining)
.execute(db)
.await?;
Ok(())
}
/// `apply_all_autoscaling` runs only for the holder of a 15s lock, so each tick backdates it.
async fn tick(db: &Pool<Postgres>) -> anyhow::Result<()> {
sqlx::query(
"INSERT INTO concurrency_locks (id, last_locked_at) VALUES ('autoscaling', now() - interval '1 hour')
ON CONFLICT (id) DO UPDATE SET last_locked_at = EXCLUDED.last_locked_at",
)
.execute(db)
.await?;
apply_all_autoscaling(db).await
}
async fn events(db: &Pool<Postgres>) -> anyhow::Result<Vec<(i32, String)>> {
Ok(sqlx::query_as(
"SELECT desired_workers, reason FROM autoscaling_event WHERE worker_group = 'default' ORDER BY id",
)
.fetch_all(db)
.await?)
}
#[sqlx::test(migrations = "./migrations")]
async fn draining_workers_are_not_counted(db: Pool<Postgres>) -> anyhow::Result<()> {
setup(&db).await?;
plant_workers(&db, 12, false).await?;
plant_workers(&db, 2, true).await?;
tick(&db).await?;
assert_eq!(events(&db).await?, vec![]);
Ok(())
}
#[sqlx::test(migrations = "./migrations")]
async fn above_max_applies_max_once_per_cooldown(db: Pool<Postgres>) -> anyhow::Result<()> {
setup(&db).await?;
plant_workers(&db, 14, false).await?;
tick(&db).await?;
tick(&db).await?;
let events = events(&db).await?;
assert_eq!(events.len(), 1, "{events:?}");
assert_eq!(events[0].0, 12);
sqlx::query("UPDATE autoscaling_event SET applied_at = applied_at - interval '10 minutes'")
.execute(&db)
.await?;
tick(&db).await?;
assert_eq!(self::events(&db).await?.len(), 2);
Ok(())
}
/// A group restarting in place marks every worker draining while its pods remain replicas.
#[sqlx::test(migrations = "./migrations")]
async fn restarting_group_is_not_scaled_below_last_applied(db: Pool<Postgres>) -> anyhow::Result<()> {
setup(&db).await?;
sqlx::query(
"INSERT INTO autoscaling_event (worker_group, event_type, desired_workers, reason)
VALUES ('default', 'scaleout', 10, 'planted')",
)
.execute(&db)
.await?;
plant_workers(&db, 1, false).await?;
plant_workers(&db, 9, true).await?;
tick(&db).await?;
assert_eq!(events(&db).await?.len(), 1);
sqlx::query("UPDATE autoscaling_event SET applied_at = applied_at - interval '10 minutes'")
.execute(&db)
.await?;
tick(&db).await?;
let events = events(&db).await?;
assert_eq!(events.last().map(|e| e.0), Some(10), "{events:?}");
Ok(())
}
/// Idle restarted workers beside ones still draining must not make one scale-in remove the
/// draining pods too.
#[sqlx::test(migrations = "./migrations")]
async fn partially_restarted_group_scales_in_one_step(db: Pool<Postgres>) -> anyhow::Result<()> {
setup(&db).await?;
sqlx::query(
"INSERT INTO autoscaling_event (worker_group, event_type, desired_workers, reason, applied_at)
VALUES ('default', 'scaleout', 10, 'planted', now() - interval '10 minutes')",
)
.execute(&db)
.await?;
plant_workers(&db, 4, false).await?;
plant_workers(&db, 6, true).await?;
sqlx::query(
"UPDATE worker_ping SET occupancy_rate_15s = 0, occupancy_rate_5m = 0, occupancy_rate_30m = 0",
)
.execute(&db)
.await?;
tick(&db).await?;
let events = events(&db).await?;
assert_eq!(events.last().map(|e| e.0), Some(8), "{events:?}");
Ok(())
}