Skip to content

Open-source status page, incident response and uptime monitoring

feat: 30 days lookback (#1104)

Maximilian Kaskea95f63a6d04c
diff --git a/apps/web/src/app/status-page/[domain]/page.tsx b/apps/web/src/app/status-page/[domain]/page.tsx
index eb8cdadac..0051c09f5 100644
--- a/apps/web/src/app/status-page/[domain]/page.tsx
+++ b/apps/web/src/app/status-page/[domain]/page.tsx
@@ -9,6 +9,13 @@ import { StatusCheck } from "@/components/status-page/status-check";
import { api } from "@/trpc/server";
import { Separator } from "@openstatus/ui";
+/**
+ * Right now, we do not allow workspaces to have a custom lookback period.
+ * If we decide to allow this in the future, we should move this to the database.
+ */
+const WORKSPACES =
+ process.env.WORKSPACES_LOOKBACK_30?.split(",").map(Number) || [];
+
type Props = {
params: { domain: string };
searchParams: { [key: string]: string | string[] | undefined };
@@ -49,6 +56,7 @@ export default async function Page({ params }: Props) {
incidents={page.incidents}
maintenances={page.maintenances}
showMonitorValues={!!page.showMonitorValues}
+ totalDays={WORKSPACES.includes(page.workspaceId) ? 30 : 45}
/>
) : (
<EmptyState
diff --git a/apps/web/src/components/status-page/monitor-list.tsx b/apps/web/src/components/status-page/monitor-list.tsx
index 2a4224db6..f290c133b 100644
--- a/apps/web/src/components/status-page/monitor-list.tsx
+++ b/apps/web/src/components/status-page/monitor-list.tsx
@@ -15,12 +15,14 @@ export const MonitorList = ({
incidents,
maintenances,
showMonitorValues,
+ totalDays,
}: {
monitors: PublicMonitor[];
statusReports: z.infer<typeof selectPublicStatusReportSchemaWithRelation>[];
incidents: Incident[];
maintenances: Maintenance[];
showMonitorValues?: boolean;
+ totalDays?: number;
}) => {
return (
<div className="grid gap-4">
@@ -44,6 +46,7 @@ export const MonitorList = ({
incidents={monitorIncidents}
maintenances={monitorMaintenances}
showValues={showMonitorValues}
+ totalDays={totalDays}
/>
);
})}
diff --git a/apps/web/src/components/status-page/monitor.tsx b/apps/web/src/components/status-page/monitor.tsx
index 77c41f5c8..d55c63bf2 100644
--- a/apps/web/src/components/status-page/monitor.tsx
+++ b/apps/web/src/components/status-page/monitor.tsx
@@ -16,18 +16,21 @@ export const Monitor = async ({
incidents,
maintenances,
showValues,
+ totalDays,
}: {
monitor: PublicMonitor;
statusReports: z.infer<typeof selectPublicStatusReportSchemaWithRelation>[];
incidents: Incident[];
maintenances: Maintenance[];
showValues?: boolean;
+ totalDays?: number;
}) => {
const res = await prepareStatusByPeriod(
"45d",
monitor.jobType as "http" | "tcp",
).getData({
monitorId: String(monitor.id),
+ days: totalDays,
});
// TODO: we could handle the `statusReports` here instead of passing it down to the tracker
diff --git a/packages/db/src/schema/shared.ts b/packages/db/src/schema/shared.ts
index 5cb511402..67b17df58 100644
--- a/packages/db/src/schema/shared.ts
+++ b/packages/db/src/schema/shared.ts
@@ -73,7 +73,7 @@ export const selectPublicPageSchemaWithRelation = selectPageSchema
.transform((val) => val ?? "free"),
})
.omit({
- workspaceId: true,
+ // workspaceId: true,
id: true,
});
diff --git a/packages/tinybird/pipes/endpoint__http_status_45d.pipe b/packages/tinybird/pipes/endpoint__http_status_45d.pipe
index 2ceece2aa..e77cab7ea 100644
--- a/packages/tinybird/pipes/endpoint__http_status_45d.pipe
+++ b/packages/tinybird/pipes/endpoint__http_status_45d.pipe
@@ -18,5 +18,6 @@ SQL >
TO toStartOfDay(
date_sub(DAY, 45, now())
) STEP INTERVAL -1 DAY
+ LIMIT {{ Int16(days, 45) }}
diff --git a/packages/tinybird/pipes/endpoint__tcp_status_45d.pipe b/packages/tinybird/pipes/endpoint__tcp_status_45d.pipe
index 63d8707f7..c0e3081d7 100644
--- a/packages/tinybird/pipes/endpoint__tcp_status_45d.pipe
+++ b/packages/tinybird/pipes/endpoint__tcp_status_45d.pipe
@@ -18,5 +18,6 @@ SQL >
TO toStartOfDay(
date_sub(DAY, 45, now())
) STEP INTERVAL -1 DAY
+ LIMIT {{ Int16(days, 45) }}
diff --git a/packages/tinybird/src/client.ts b/packages/tinybird/src/client.ts
index 24add3d98..0a5ff55e4 100644
--- a/packages/tinybird/src/client.ts
+++ b/packages/tinybird/src/client.ts
@@ -304,6 +304,7 @@ export class OSTinybird {
pipe: "endpoint__http_status_45d__v0",
parameters: z.object({
monitorId: z.string(),
+ days: z.number().int().max(45).optional(),
}),
data: z.object({
day: z.string().transform((val) => {
@@ -644,6 +645,7 @@ export class OSTinybird {
pipe: "endpoint__tcp_status_45d__v0",
parameters: z.object({
monitorId: z.string(),
+ days: z.number().int().max(45).optional(),
}),
data: z.object({
day: z.string().transform((val) => {