Make metrics reflect autoscaling policies (Refs #137)
CI / checks (push) Successful in 4m49s

This commit is contained in:
2026-10-10 14:48:52 -04:00
parent bd34c3c9e7
commit 33da4482a6
24 changed files with 1264 additions and 370 deletions
+29 -7
View File
@@ -5,12 +5,25 @@ const record = (value: unknown): value is Record<string, unknown> =>
typeof value === 'object' && value !== null && !Array.isArray(value);
const numeric = (value: unknown): value is number =>
typeof value === 'number' && Number.isFinite(value);
const nonnegative = (value: unknown): value is number => numeric(value) && value >= 0;
const timestamp = (value: unknown) => value === null || numeric(value);
const totals = (value: unknown) =>
record(value) &&
['observed', 'active', 'idle', 'unknown', 'playerHours'].every(
(key) => numeric(value[key]) && value[key] >= 0
);
const running = (value: unknown) =>
record(value) &&
(value.average === null || nonnegative(value.average)) &&
nonnegative(value.peak) &&
nonnegative(value.capturedHours);
const policy = (value: unknown) =>
value === null ||
(record(value) &&
typeof value.id === 'string' &&
['off', 'create-destroy'].includes(value.mode as string) &&
['minimum', 'maximum', 'spares'].every((key) => nonnegative(value[key])) &&
(value.pausedReason === null || typeof value.pausedReason === 'string'));
function validReport(value: unknown): value is MetricsData {
if (
@@ -18,7 +31,8 @@ function validReport(value: unknown): value is MetricsData {
![1, 7, 30].includes(value.days as number) ||
!numeric(value.now) ||
!numeric(value.since) ||
!totals(value.summary)
!totals(value.summary) ||
!running(value.running)
)
return false;
if (
@@ -58,6 +72,7 @@ function validReport(value: unknown): value is MetricsData {
numeric(item.at) &&
numeric(item.startAt) &&
numeric(item.endAt) &&
nonnegative(item.capturedHours) &&
typeof item.partial === 'boolean'
)
)
@@ -70,8 +85,14 @@ function validReport(value: unknown): value is MetricsData {
totals(item) &&
typeof item.game === 'string' &&
typeof item.map === 'string' &&
numeric(item.full) &&
numeric(item.capacityObserved)
[
'noEmpty',
'availabilityObserved',
'availabilityUnknown',
'noEmptyAtMaximum',
'noEmptyBelowMaximum'
].every((key) => nonnegative(item[key])) &&
policy(item.policy)
)
)
return false;
@@ -89,6 +110,7 @@ function validReport(value: unknown): value is MetricsData {
if (
!record(value.previous) ||
!totals(value.previous.summary) ||
!running(value.previous.running) ||
!numeric(value.previous.since) ||
!numeric(value.previous.until) ||
!timestamp(value.previous.firstSampleAt) ||
@@ -111,10 +133,10 @@ function validReport(value: unknown): value is MetricsData {
)
return false;
return (
record(value.pooledPressure) &&
(value.pooledPressure.value === null || numeric(value.pooledPressure.value)) &&
['fullMapHours', 'knownMapHours', 'coveredMaps', 'totalMaps'].every((key) =>
numeric((value.pooledPressure as Record<string, unknown>)[key])
record(value.pooledAvailability) &&
(value.pooledAvailability.value === null || nonnegative(value.pooledAvailability.value)) &&
['noEmptyMapHours', 'knownMapHours', 'unknownMapHours', 'coveredMaps', 'totalMaps'].every(
(key) => nonnegative((value.pooledAvailability as Record<string, unknown>)[key])
)
);
}