Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
Use page component name/description for public monitor display (#2385)
Maximilian Kaske827cc4a64644
diff --git a/apps/workflows/src/checker/private-location.test.ts b/apps/workflows/src/checker/private-location.test.tsindex 6b4c8580d..8ded0d160 100644--- a/apps/workflows/src/checker/private-location.test.ts+++ b/apps/workflows/src/checker/private-location.test.ts@@ -1,6 +1,9 @@import { and, db, eq } from "@openstatus/db";import {+ monitor,+ notification,notificationTrigger,+ notificationsToMonitors,privateLocation,privateLocationMonitorStatus,privateLocationToMonitors,@@ -26,8 +29,12 @@ import { providerToFunction } from "./utils";// biome-ignore lint/suspicious/noExplicitAny: heterogeneous provider stubstype AnyStub = Stub<any>;-const TEST_MONITOR_ID = 1; // seed: workspace 1, active, linked to email notification 1-const INACTIVE_MONITOR_ID = 2; // seed: active = false+// Dedicated fixtures, not seed monitor 1: other suites (api/server maintenance+// tests) put seed monitor 1 under active maintenance on the shared CI database,+// which makes updateStatusPrivate suppress notifications and drop the write.+const TEST_MONITOR_ID = 9101;+const INACTIVE_MONITOR_ID = 9102;+const TEST_NOTIFICATION_ID = 9101;const TEST_LOCATION_ID = 9001;const UNATTACHED_LOCATION_ID = 9002;@@ -74,6 +81,49 @@ describe("updateStatusPrivate", () => {let mockEmailSendDegraded: AnyStub;beforeAll(async () => {+ await db+ .insert(monitor)+ .values([+ {+ id: TEST_MONITOR_ID,+ workspaceId: 1,+ active: true,+ url: "https://private-location.test",+ name: "Private Location Test Monitor",+ periodicity: "1m",+ regions: "ams",+ },+ {+ id: INACTIVE_MONITOR_ID,+ workspaceId: 1,+ active: false,+ url: "https://private-location-inactive.test",+ name: "Private Location Inactive Monitor",+ periodicity: "1m",+ regions: "ams",+ },+ ])+ .onConflictDoNothing()+ .run();+ await db+ .insert(notification)+ .values({+ id: TEST_NOTIFICATION_ID,+ provider: "email",+ name: "private location test notification",+ data: '{"email":"[email protected]"}',+ workspaceId: 1,+ })+ .onConflictDoNothing()+ .run();+ await db+ .insert(notificationsToMonitors)+ .values({+ monitorId: TEST_MONITOR_ID,+ notificationId: TEST_NOTIFICATION_ID,+ })+ .onConflictDoNothing()+ .run();await db.insert(privateLocation).values({@@ -113,6 +163,16 @@ describe("updateStatusPrivate", () => {.delete(privateLocation).where(eq(privateLocation.id, TEST_LOCATION_ID)).run();+ await db+ .delete(notificationsToMonitors)+ .where(eq(notificationsToMonitors.monitorId, TEST_MONITOR_ID))+ .run();+ await db+ .delete(notification)+ .where(eq(notification.id, TEST_NOTIFICATION_ID))+ .run();+ await db.delete(monitor).where(eq(monitor.id, TEST_MONITOR_ID)).run();+ await db.delete(monitor).where(eq(monitor.id, INACTIVE_MONITOR_ID)).run();});beforeEach(() => {diff --git a/packages/api/src/router/statusPage.e2e.test.ts b/packages/api/src/router/statusPage.e2e.test.tsindex 79c611ab2..f65f079cb 100644--- a/packages/api/src/router/statusPage.e2e.test.ts+++ b/packages/api/src/router/statusPage.e2e.test.ts@@ -1057,3 +1057,267 @@ describe("statusPage.get gates incidents by barType (calendar manual mode)", ()expect(monitorIncidents(result)).toEqual([]);});});++describe("statusPage exposes page component names, not internal monitor names", () => {+ const publicNameSlug = "public-component-name-test-page";+ let publicNamePageId: number;+ let publicNameMonitorId: number;+ let publicNameComponentId: number;+ let noDescriptionMonitorId: number;+ let noDescriptionComponentId: number;+ let clearedDescriptionMonitorId: number;+ let clearedDescriptionComponentId: number;++ const internalName = "Internal Monitor Name";+ const internalDescription = "Internal monitor description";+ const legacyExternalName = "Legacy External Name";+ const componentName = "Public Component Name";+ const componentDescription = "Public component description";+ const fallbackDescription = "Monitor description used as fallback";++ async function createCaller() {+ const { edgeRouter } = await import("../edge");+ const { createInnerTRPCContext } = await import("../trpc");+ const ctx = createInnerTRPCContext({+ req: undefined,+ // @ts-expect-error - auth not required for public procedure+ auth: undefined,+ });+ return edgeRouter.createCaller(ctx);+ }++ beforeAll(async () => {+ await db.delete(page).where(eq(page.slug, publicNameSlug));++ const testPage = await db+ .insert(page)+ .values({+ workspaceId: 1,+ title: "Public Component Name Page",+ description: "Verifies public naming in statusPage procedures",+ slug: publicNameSlug,+ customDomain: "",+ })+ .returning()+ .get();+ publicNamePageId = testPage.id;++ // externalName is set on purpose: the legacy `externalName || name`+ // schema transform must not override the page component name.+ const testMonitor = await db+ .insert(monitor)+ .values({+ workspaceId: 1,+ name: internalName,+ externalName: legacyExternalName,+ description: internalDescription,+ periodicity: "1m",+ url: "https://example.com",+ active: true,+ public: true,+ })+ .returning()+ .get();+ publicNameMonitorId = testMonitor.id;++ const testComponent = await db+ .insert(pageComponent)+ .values({+ workspaceId: 1,+ pageId: publicNamePageId,+ type: "monitor",+ monitorId: publicNameMonitorId,+ name: componentName,+ description: componentDescription,+ order: 0,+ })+ .returning()+ .get();+ publicNameComponentId = testComponent.id;++ // mirrors pre-existing components: description was never backfilled (NULL)+ const noDescriptionMonitor = await db+ .insert(monitor)+ .values({+ workspaceId: 1,+ name: "No Description Component Monitor",+ description: fallbackDescription,+ periodicity: "1m",+ url: "https://example.com",+ active: true,+ public: true,+ })+ .returning()+ .get();+ noDescriptionMonitorId = noDescriptionMonitor.id;++ const noDescriptionComponent = await db+ .insert(pageComponent)+ .values({+ workspaceId: 1,+ pageId: publicNamePageId,+ type: "monitor",+ monitorId: noDescriptionMonitorId,+ name: "No Description Component",+ order: 1,+ })+ .returning()+ .get();+ noDescriptionComponentId = noDescriptionComponent.id;++ // mirrors a deliberately cleared field: the dashboard stores ""+ const clearedDescriptionMonitor = await db+ .insert(monitor)+ .values({+ workspaceId: 1,+ name: "Cleared Description Component Monitor",+ description: "Internal description that must stay hidden",+ periodicity: "1m",+ url: "https://example.com",+ active: true,+ public: true,+ })+ .returning()+ .get();+ clearedDescriptionMonitorId = clearedDescriptionMonitor.id;++ const clearedDescriptionComponent = await db+ .insert(pageComponent)+ .values({+ workspaceId: 1,+ pageId: publicNamePageId,+ type: "monitor",+ monitorId: clearedDescriptionMonitorId,+ name: "Cleared Description Component",+ description: "",+ order: 2,+ })+ .returning()+ .get();+ clearedDescriptionComponentId = clearedDescriptionComponent.id;+ });++ afterAll(async () => {+ await db+ .delete(pageComponent)+ .where(eq(pageComponent.id, publicNameComponentId));+ await db+ .delete(pageComponent)+ .where(eq(pageComponent.id, noDescriptionComponentId));+ await db+ .delete(pageComponent)+ .where(eq(pageComponent.id, clearedDescriptionComponentId));+ await db.delete(monitor).where(eq(monitor.id, publicNameMonitorId));+ await db.delete(monitor).where(eq(monitor.id, noDescriptionMonitorId));+ await db.delete(monitor).where(eq(monitor.id, clearedDescriptionMonitorId));+ await db.delete(page).where(eq(page.id, publicNamePageId));+ });++ test("get returns the page component name and description", async () => {+ const caller = await createCaller();+ const result = await caller.statusPage.get({ slug: publicNameSlug });++ const monitorItem = result?.monitors.find(+ (m) => m.id === publicNameMonitorId,+ );++ expect(monitorItem?.name).toBe(componentName);+ expect(monitorItem?.description).toBe(componentDescription);+ expect(monitorItem?.name).not.toBe(internalName);+ expect(monitorItem?.name).not.toBe(legacyExternalName);++ // the nested monitor relation must agree with the flat monitors array+ const component = result?.pageComponents.find(+ (c) => c.monitorId === publicNameMonitorId,+ );+ expect(component?.monitor?.name).toBe(componentName);+ expect(component?.monitor?.description).toBe(componentDescription);+ });++ test("getLight returns the page component name and description", async () => {+ const caller = await createCaller();+ const result = await caller.statusPage.getLight({ slug: publicNameSlug });++ const monitorItem = result?.monitors.find(+ (m) => m.id === publicNameMonitorId,+ );++ expect(monitorItem?.name).toBe(componentName);+ expect(monitorItem?.description).toBe(componentDescription);++ const component = result?.pageComponents.find(+ (c) => c.monitorId === publicNameMonitorId,+ );+ expect(component?.monitor?.name).toBe(componentName);+ expect(component?.monitor?.description).toBe(componentDescription);+ });++ test("falls back to the monitor description when the component has none", async () => {+ const caller = await createCaller();+ const result = await caller.statusPage.get({ slug: publicNameSlug });++ const monitorItem = result?.monitors.find(+ (m) => m.id === noDescriptionMonitorId,+ );+ expect(monitorItem?.description).toBe(fallbackDescription);++ const component = result?.pageComponents.find(+ (c) => c.monitorId === noDescriptionMonitorId,+ );+ expect(component?.monitor?.description).toBe(fallbackDescription);++ const light = await caller.statusPage.getLight({ slug: publicNameSlug });+ const lightItem = light?.monitors.find(+ (m) => m.id === noDescriptionMonitorId,+ );+ expect(lightItem?.description).toBe(fallbackDescription);+ });++ test("keeps a deliberately cleared component description blank", async () => {+ const caller = await createCaller();+ const result = await caller.statusPage.get({ slug: publicNameSlug });++ const monitorItem = result?.monitors.find(+ (m) => m.id === clearedDescriptionMonitorId,+ );+ expect(monitorItem?.description).toBe("");++ const component = result?.pageComponents.find(+ (c) => c.monitorId === clearedDescriptionMonitorId,+ );+ expect(component?.monitor?.description).toBe("");++ const light = await caller.statusPage.getLight({ slug: publicNameSlug });+ const lightItem = light?.monitors.find(+ (m) => m.id === clearedDescriptionMonitorId,+ );+ expect(lightItem?.description).toBe("");+ });++ test("getUptime returns the page component name on the nested monitor", async () => {+ const caller = await createCaller();+ const result = await caller.statusPage.getUptime({+ slug: publicNameSlug,+ pageComponentIds: [String(publicNameComponentId)],+ });++ const component = result?.find(+ (c) => c.pageComponentId === publicNameComponentId,+ );++ expect(component?.name).toBe(componentName);+ expect(component?.monitor?.name).toBe(componentName);+ expect(component?.monitor?.description).toBe(componentDescription);+ });++ test("getMonitor returns the page component name and description", async () => {+ const caller = await createCaller();+ const result = await caller.statusPage.getMonitor({+ slug: publicNameSlug,+ id: publicNameMonitorId,+ });++ expect(result?.name).toBe(componentName);+ expect(result?.description).toBe(componentDescription);+ });+});diff --git a/packages/api/src/router/statusPage.ts b/packages/api/src/router/statusPage.tsindex 74e9963db..1659d28ec 100644--- a/packages/api/src/router/statusPage.ts+++ b/packages/api/src/router/statusPage.ts@@ -497,7 +497,13 @@ export const statusPageRouter = createTRPCRouter({const monitors = monitorComponents.map((c) => ({...c.monitor,- name: c.monitor?.externalName ?? c.monitor?.name ?? "",+ // the page component carries the public-facing name/description;+ // clear externalName so the schema transform keeps the override.+ // description: NULL means never backfilled → fall back to the+ // monitor's own; "" is a deliberately cleared field → stays blank.+ name: c.name,+ description: c.description ?? c.monitor?.description ?? "",+ externalName: null,})).sort((a, b) => {const aComp = monitorComponents.find((m) => m.monitor?.id === a.id);diff --git a/packages/db/src/schema/shared.ts b/packages/db/src/schema/shared.tsindex d6c23baf1..7d7855f95 100644--- a/packages/db/src/schema/shared.ts+++ b/packages/db/src/schema/shared.ts@@ -148,19 +148,30 @@ const trackersSchema = z).prefault([]);-export const selectPageComponentWithMonitorRelation =- selectPageComponentSchema.extend({+export const selectPageComponentWithMonitorRelation = selectPageComponentSchema+ .extend({monitor: selectPublicMonitorBaseSchema.extend({incidents: selectIncidentSchema.array().nullish(),})- .transform((data) => ({- ...data,- name: data.externalName || data.name,- })).nullish(),group: selectPageComponentGroupSchema.nullish(),- });+ })+ // the component owns the public-facing monitor name/description; externalName+ // is cleared so downstream `externalName || name` transforms keep the override.+ // description: NULL means never backfilled → fall back to the monitor's own;+ // "" is a deliberately cleared field (the dashboard stores "") → stays blank.+ .transform(({ monitor, ...component }) => ({+ ...component,+ monitor: monitor+ ? {+ ...monitor,+ name: component.name,+ description: component.description ?? monitor.description,+ externalName: null,+ }+ : monitor,+ }));export type PageComponentWithMonitorRelation = z.infer<typeof selectPageComponentWithMonitorRelation