Add autoscaling outcomes to Metrics (Refs #140)
This commit is contained in:
@@ -158,3 +158,45 @@ it('refreshes policy signals after policy edits and global pauses without new sa
|
||||
db().prepare("DELETE FROM autoscaling_policies WHERE id='moon-policy'").run();
|
||||
expect((await metricsReport(query)).maps[0].policy).toBeNull();
|
||||
});
|
||||
|
||||
it('refreshes autoscaling outcomes after completion, source changes and retention without new samples', async () => {
|
||||
const { db } = await import('../../src/lib/server/db/index.js');
|
||||
const { metricsReport } = await import('../../src/lib/server/reports/index.js');
|
||||
const now = Date.UTC(2026, 9, 10, 12);
|
||||
vi.spyOn(Date, 'now').mockReturnValue(now);
|
||||
const query = parseMetricsQuery(new URLSearchParams('days=7'));
|
||||
const report = () => metricsReport(query);
|
||||
expect((await report()).autoscaling.added).toBe(0);
|
||||
db()
|
||||
.prepare(
|
||||
`INSERT INTO server_deployments
|
||||
(id,server,action,state,stage,started_at,triggered_by)
|
||||
VALUES('operation','t5_zombie_moon_1','create','awaiting-health','Waiting',?,'test')`
|
||||
)
|
||||
.run(new Date(now - 72_000).toISOString());
|
||||
db().exec(`INSERT INTO provisioning_sources(operation_id,kind,source_id,server)
|
||||
VALUES('operation','autoscaling','deleted-policy','t5_zombie_moon_1')`);
|
||||
expect((await report()).autoscaling.added).toBe(0);
|
||||
db()
|
||||
.prepare("UPDATE server_deployments SET state='done',finished_at=? WHERE id='operation'")
|
||||
.run(new Date(now).toISOString());
|
||||
expect((await report()).autoscaling).toMatchObject({
|
||||
added: 1,
|
||||
readinessSamples: 1,
|
||||
readinessMeanSeconds: 72,
|
||||
readinessMaxSeconds: 72
|
||||
});
|
||||
db().exec("UPDATE provisioning_sources SET kind='maintenance'");
|
||||
expect((await report()).autoscaling.added).toBe(0);
|
||||
db().exec("UPDATE provisioning_sources SET kind='autoscaling'");
|
||||
expect((await report()).autoscaling.added).toBe(1);
|
||||
db().exec("UPDATE server_deployments SET state='failed'");
|
||||
expect((await report()).autoscaling).toMatchObject({
|
||||
added: 0,
|
||||
failed: 1,
|
||||
readinessSamples: 0
|
||||
});
|
||||
db().exec('DELETE FROM server_deployments');
|
||||
expect((await report()).autoscaling.failed).toBe(0);
|
||||
expect((await report()).scopeOptions.maps).toEqual([]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user