Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pm-stack/aggregator/src/aa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1092,10 +1092,12 @@ export function aaSectionFromSupabase(
export function isAaSection(v: unknown): v is AaFeedSection {
if (typeof v !== "object" || v === null) return false;
const s = v as Partial<AaSection> & Partial<AaAbsentSection>;
if (s.status === "absent") return typeof s.reason === "string" && typeof s.generatedAt === "string";
if (s.status === "absent")
return typeof s.reason === "string" && typeof s.generatedAt === "string" && Number.isFinite(Date.parse(s.generatedAt));
if (s.status !== "ok") return false;
return (
typeof s.generatedAt === "string" &&
Number.isFinite(Date.parse(s.generatedAt)) &&
typeof s.batch === "string" &&
Array.isArray(s.rankings) &&
s.rankings.length > 0 &&
Expand Down
1 change: 1 addition & 0 deletions pm-stack/aggregator/src/dns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export function isDnsSection(v: unknown): v is DnsSection {
const s = v as Partial<DnsSection>;
return (
typeof s.generatedAt === "string" &&
Number.isFinite(Date.parse(s.generatedAt)) &&
Array.isArray(s.entries) &&
s.entries.length > 0 &&
s.entries.every(
Expand Down
19 changes: 18 additions & 1 deletion pm-stack/aggregator/src/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,24 @@ function feedSections(feed: FleetFeed | null, now: number): FeedSectionHealth[]
if (!feed) return [];
const from = (generatedAt: string | undefined, present: boolean, note?: string): Partial<FeedSectionHealth> => {
const ts = generatedAt ?? feed.generatedAt;
return { present, generatedAt: ts, ageMs: Math.max(0, now - Date.parse(ts)), ...(note ? { note } : {}) };
const parsed = Date.parse(ts);
// Section stamps get the same validation as the top-level one
// (#2242, mirroring #1564): an unparseable stamp must not render
// as ageMs NaN/null, and a stamp beyond the future-skew bound
// must not render as ageMs 0 (maximally fresh) for as long as
// the skew lasts. Either way the section reports absent with a
// legible note instead of a fabricated age.
if (!Number.isFinite(parsed)) {
return { present: false, generatedAt: ts, note: `invalid generatedAt (${ts})` };
}
if (parsed - now > GENERATED_AT_FUTURE_SKEW_MS) {
return {
present: false,
generatedAt: ts,
note: `generatedAt (${ts}) is ${ageMsText(parsed - now)} in the future — never fresh`,
};
}
return { present, generatedAt: ts, ageMs: Math.max(0, now - parsed), ...(note ? { note } : {}) };
};
const aa = feed.aa;
const aaNote =
Expand Down
44 changes: 44 additions & 0 deletions pm-stack/aggregator/test/health.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,50 @@ describe("buildHealth probes", () => {
expect(view.degraded).toBe(true);
});

test("garbage dns/aa section stamps render absent with an invalid-generatedAt note, never NaN (#2242)", async () => {
const { fetcher } = fakeFetcher(allUp);
const feed = feedAt(5 * 60_000);
(feed.dns as { generatedAt: string }).generatedAt = "not-a-date";
(feed as unknown as { aa: unknown }).aa = { status: "ok", generatedAt: "garbage!!", batch: "b", rankings: [], configs: [], testRuns: [] };
const view = await buildHealth(inputs({ feed }), { fetcher, cache: createProbeCache(), now: NOW });
const dns = view.feed.sections.find((x) => x.key === "dns");
expect(dns?.present).toBe(false);
expect(dns?.note).toContain("invalid generatedAt (not-a-date)");
expect(dns?.ageMs).toBeUndefined();
const aa = view.feed.sections.find((x) => x.key === "aa");
expect(aa?.present).toBe(false);
expect(aa?.note).toContain("invalid generatedAt (garbage!!)");
expect(aa?.ageMs).toBeUndefined();
// Untouched sections render exactly as before.
const orch = view.feed.sections.find((x) => x.key === "orchestration");
expect(orch?.present).toBe(true);
expect(orch?.ageMs).toBe(5 * 60_000);
});

test("future dns/aa section stamps render absent with a future note, never age 0 (#2242)", async () => {
const { fetcher } = fakeFetcher(allUp);
const feed = feedAt(5 * 60_000);
const future = new Date(NOW + 3_600_000).toISOString();
(feed.dns as { generatedAt: string }).generatedAt = future;
(feed as unknown as { aa: unknown }).aa = { status: "ok", generatedAt: future, batch: "b", rankings: [], configs: [], testRuns: [] };
const view = await buildHealth(inputs({ feed }), { fetcher, cache: createProbeCache(), now: NOW });
const dns = view.feed.sections.find((x) => x.key === "dns");
expect(dns?.present).toBe(false);
expect(dns?.note).toContain("in the future");
expect(dns?.ageMs).toBeUndefined();
const aa = view.feed.sections.find((x) => x.key === "aa");
expect(aa?.present).toBe(false);
expect(aa?.note).toContain("in the future");
expect(aa?.ageMs).toBeUndefined();
// A stamp inside the 60s skew bound still renders as a live section.
const feed2 = feedAt(5 * 60_000);
(feed2.dns as { generatedAt: string }).generatedAt = new Date(NOW + 30_000).toISOString();
const view2 = await buildHealth(inputs({ feed: feed2 }), { fetcher, cache: createProbeCache(), now: NOW });
const dns2 = view2.feed.sections.find((x) => x.key === "dns");
expect(dns2?.present).toBe(true);
expect(dns2?.ageMs).toBe(0);
});

test("fixtures mode never probes and reports fixtures for every service", async () => {
const { fetcher, calls } = fakeFetcher(allUp);
const view = await buildHealth(
Expand Down