Skip to content

Open-source status page, incident response and uptime monitoring

fix: more stpg stuff (#1400)

Maximilian Kaske237481ec0cdf
diff --git a/apps/status-page/src/app/(status-page)/[domain]/(public)/events/(list)/page.tsx b/apps/status-page/src/app/(status-page)/[domain]/(public)/events/(list)/page.tsx
index e3b815756..2c76023a9 100644
--- a/apps/status-page/src/app/(status-page)/[domain]/(public)/events/(list)/page.tsx
+++ b/apps/status-page/src/app/(status-page)/[domain]/(public)/events/(list)/page.tsx
@@ -15,13 +15,13 @@ import {
StatusEventTimelineMaintenance,
StatusEventTimelineReport,
StatusEventTitle,
+ StatusEventTitleCheck,
} from "@/components/status-page/status-events";
import { Badge } from "@/components/ui/badge";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { formatDate } from "@/lib/formatter";
import { useTRPC } from "@/lib/trpc/client";
import { useQuery } from "@tanstack/react-query";
-import { Check } from "lucide-react";
import Link from "next/link";
import { useParams } from "next/navigation";
@@ -71,13 +71,7 @@ export default function Page() {
<StatusEventContent>
<StatusEventTitle className="inline-flex gap-1">
{report.title}
- {isReportResolvedOnly ? (
- <div className="mt-1 ml-1.5">
- <div className="rounded-full border border-success/20 bg-success/10 p-0.5 text-success">
- <Check className="size-3 shrink-0" />
- </div>
- </div>
- ) : null}
+ {isReportResolvedOnly ? <StatusEventTitleCheck /> : null}
</StatusEventTitle>
{report.monitorsToStatusReports.length > 0 ? (
<StatusEventAffected className="flex flex-wrap gap-1">
diff --git a/apps/status-page/src/app/(status-page)/[domain]/(public)/events/(view)/report/[id]/page.tsx b/apps/status-page/src/app/(status-page)/[domain]/(public)/events/(view)/report/[id]/page.tsx
index d6acef6b7..58b3cf7ee 100644
--- a/apps/status-page/src/app/(status-page)/[domain]/(public)/events/(view)/report/[id]/page.tsx
+++ b/apps/status-page/src/app/(status-page)/[domain]/(public)/events/(view)/report/[id]/page.tsx
@@ -11,6 +11,7 @@ import {
StatusEventContent,
StatusEventTimelineReport,
StatusEventTitle,
+ StatusEventTitleCheck,
} from "@/components/status-page/status-events";
import { Badge } from "@/components/ui/badge";
import { useTRPC } from "@/lib/trpc/client";
@@ -26,7 +27,13 @@ export default function ReportPage() {
if (!report) return null;
- const startedAt = report.statusReportUpdates[0].date;
+ const firstUpdate = report.statusReportUpdates[0];
+ const lastUpdate =
+ report.statusReportUpdates[report.statusReportUpdates.length - 1];
+
+ // HACKY: LEGACY: only resolved via report and not via report update
+ const isReportResolvedOnly =
+ report.status === "resolved" && lastUpdate.status !== "resolved";
return (
<div className="flex flex-col gap-4">
@@ -37,11 +44,14 @@ export default function ReportPage() {
<StatusEvent>
<StatusEventAside>
<span className="font-medium text-foreground/80">
- {formatDate(startedAt, { month: "short" })}
+ {formatDate(firstUpdate.date, { month: "short" })}
</span>
</StatusEventAside>
<StatusEventContent hoverable={false}>
- <StatusEventTitle>{report.title}</StatusEventTitle>
+ <StatusEventTitle className="inline-flex gap-1">
+ {report.title}
+ {isReportResolvedOnly ? <StatusEventTitleCheck /> : null}
+ </StatusEventTitle>
{report.monitorsToStatusReports.length > 0 ? (
<StatusEventAffected className="flex flex-wrap gap-1">
{report.monitorsToStatusReports.map((affected) => (
diff --git a/apps/status-page/src/app/(status-page)/[domain]/(public)/page.tsx b/apps/status-page/src/app/(status-page)/[domain]/(public)/page.tsx
index af9dc0b98..badd89f6e 100644
--- a/apps/status-page/src/app/(status-page)/[domain]/(public)/page.tsx
+++ b/apps/status-page/src/app/(status-page)/[domain]/(public)/page.tsx
@@ -129,29 +129,33 @@ export default function Page() {
<StatusBanner status={page.status} />
)}
{/* NOTE: check what gap feels right */}
- <StatusContent className="gap-5">
- {page.monitors.map((monitor) => {
- const { data, uptime } =
- uptimeData?.find((m) => m.id === monitor.id) ?? {};
- return (
- <StatusMonitor
- key={monitor.id}
- status={monitor.status}
- data={data}
- monitor={monitor}
- uptime={uptime}
- showUptime={showUptime}
- isLoading={isLoading}
- />
- );
- })}
- </StatusContent>
+ {page.monitors.length > 0 ? (
+ <StatusContent className="gap-5">
+ {page.monitors.map((monitor) => {
+ const { data, uptime } =
+ uptimeData?.find((m) => m.id === monitor.id) ?? {};
+ return (
+ <StatusMonitor
+ key={monitor.id}
+ status={monitor.status}
+ data={data}
+ monitor={monitor}
+ uptime={uptime}
+ showUptime={showUptime}
+ isLoading={isLoading}
+ />
+ );
+ })}
+ </StatusContent>
+ ) : null}
<Separator />
<StatusContent>
<StatusFeed
statusReports={page.statusReports
.filter((report) =>
- page.lastEvents.some((event) => event.id === report.id),
+ page.lastEvents.some(
+ (event) => event.id === report.id && event.type === "report",
+ ),
)
.map((report) => ({
...report,
@@ -162,7 +166,10 @@ export default function Page() {
}))}
maintenances={page.maintenances
.filter((maintenance) =>
- page.lastEvents.some((event) => event.id === maintenance.id),
+ page.lastEvents.some(
+ (event) =>
+ event.id === maintenance.id && event.type === "maintenance",
+ ),
)
.map((maintenance) => ({
...maintenance,
diff --git a/apps/status-page/src/components/status-page/status-blank.tsx b/apps/status-page/src/components/status-page/status-blank.tsx
index 833d9a70e..e1c780bee 100644
--- a/apps/status-page/src/components/status-page/status-blank.tsx
+++ b/apps/status-page/src/components/status-page/status-blank.tsx
@@ -1,4 +1,6 @@
+import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
+import Link from "next/link";
export function StatusBlankContainer({
children,
@@ -8,7 +10,7 @@ export function StatusBlankContainer({
return (
<div
className={cn(
- "flex flex-col items-center justify-center gap-2 rounded-lg border bg-muted/30 px-3 py-2 text-center sm:px-8 sm:py-6",
+ "flex flex-col items-center justify-center gap-2.5 rounded-lg border bg-muted/30 px-3 py-2 text-center sm:px-8 sm:py-6",
className,
)}
{...props}
@@ -45,13 +47,32 @@ export function StatusBlankDescription({
);
}
+export function StatusBlankLink({
+ children,
+ className,
+ href,
+ ...props
+}: React.ComponentProps<typeof Button> & { href: string }) {
+ return (
+ <Button
+ variant="outline"
+ size="sm"
+ className={cn("text-foreground", className)}
+ asChild
+ {...props}
+ >
+ <Link href={href}>{children}</Link>
+ </Button>
+ );
+}
+
export function StatusBlankContent({
children,
className,
...props
}: React.ComponentProps<"div">) {
return (
- <div className={cn("", className)} {...props}>
+ <div className={cn("space-y-1", className)} {...props}>
{children}
</div>
);
diff --git a/apps/status-page/src/components/status-page/status-events.tsx b/apps/status-page/src/components/status-page/status-events.tsx
index cd98be361..7d776a2f6 100644
--- a/apps/status-page/src/components/status-page/status-events.tsx
+++ b/apps/status-page/src/components/status-page/status-events.tsx
@@ -1,9 +1,16 @@
import { ProcessMessage } from "@/components/content/process-message";
import { TimestampHoverCard } from "@/components/content/timestamp-hover-card";
import { Separator } from "@/components/ui/separator";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger,
+} from "@/components/ui/tooltip";
import { formatDateRange, formatDateTime } from "@/lib/formatter";
import { cn } from "@/lib/utils";
import { formatDistanceStrict } from "date-fns";
+import { Check } from "lucide-react";
import { status } from "./messages";
export function StatusEvent({
@@ -54,6 +61,29 @@ export function StatusEventTitle({
);
}
+export function StatusEventTitleCheck({
+ className,
+ children,
+ ...props
+}: React.ComponentProps<"div">) {
+ return (
+ <div className={cn("mt-1 ml-1.5", className)} {...props}>
+ <TooltipProvider>
+ <Tooltip>
+ <TooltipTrigger>
+ <div className="rounded-full border border-success/20 bg-success/10 p-0.5 text-success">
+ <Check className="size-3 shrink-0" />
+ </div>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>Report resolved</p>
+ </TooltipContent>
+ </Tooltip>
+ </TooltipProvider>
+ </div>
+ );
+}
+
// TODO: affected monitors
export function StatusEventAffected({
className,
@@ -186,7 +216,11 @@ function StatusEventTimelineReportUpdate({
) : null}
</StatusEventTimelineTitle>
<StatusEventTimelineMessage>
- <ProcessMessage value={report.message} />
+ {report.message.trim() === "" ? (
+ <span className="text-muted-foreground/70">-</span>
+ ) : (
+ <ProcessMessage value={report.message} />
+ )}
</StatusEventTimelineMessage>
</div>
</div>
@@ -242,7 +276,11 @@ export function StatusEventTimelineMaintenance({
) : null}
</StatusEventTimelineTitle>
<StatusEventTimelineMessage>
- <ProcessMessage value={maintenance.message} />
+ {maintenance.message.trim() === "" ? (
+ <span className="text-muted-foreground/70">-</span>
+ ) : (
+ <ProcessMessage value={maintenance.message} />
+ )}
</StatusEventTimelineMessage>
</div>
</div>
diff --git a/apps/status-page/src/components/status-page/status-feed.tsx b/apps/status-page/src/components/status-page/status-feed.tsx
index c59463c35..ec8ddf83b 100644
--- a/apps/status-page/src/components/status-page/status-feed.tsx
+++ b/apps/status-page/src/components/status-page/status-feed.tsx
@@ -9,6 +9,7 @@ import {
StatusBlankContainer,
StatusBlankContent,
StatusBlankDescription,
+ StatusBlankLink,
StatusBlankReport,
StatusBlankTitle,
} from "./status-blank";
@@ -92,6 +93,9 @@ export function StatusFeed({
<StatusBlankDescription>
There have been no reports within the last 7 days.
</StatusBlankDescription>
+ <StatusBlankLink href={`${prefix ? `/${prefix}` : ""}/events`}>
+ View all reports
+ </StatusBlankLink>
</StatusBlankContent>
</StatusBlankContainer>
);
@@ -186,6 +190,12 @@ export function StatusFeed({
}
return null;
})}
+ <StatusBlankLink
+ className="mx-auto"
+ href={`${prefix ? `/${prefix}` : ""}/events`}
+ >
+ View all events
+ </StatusBlankLink>
</div>
);
}
diff --git a/apps/status-page/src/components/status-page/status-tracker.tsx b/apps/status-page/src/components/status-page/status-tracker.tsx
index f25018708..837f65b74 100644
--- a/apps/status-page/src/components/status-page/status-tracker.tsx
+++ b/apps/status-page/src/components/status-page/status-tracker.tsx
@@ -401,7 +401,7 @@ function StatusTrackerEvent({
status: "success" | "degraded" | "error" | "info" | "empty";
}) {
if (!from) return null;
- const duration = to ? formatDistanceStrict(from, to) : "ongoing";
+
return (
<div className="group relative text-sm">
{/* NOTE: this is to make the text truncate based on the with of the sibling element */}
@@ -421,9 +421,23 @@ function StatusTrackerEvent({
<div className="mt-1 text-muted-foreground text-xs">
{formatDateRange(from, to ?? undefined)}{" "}
<span className="ml-1.5 font-mono text-muted-foreground/70">
- {duration === "0 seconds" ? null : duration}
+ {formatDuration({ from, to, name, status })}
</span>
</div>
</div>
);
}
+
+const formatDuration = ({
+ from,
+ to,
+ name,
+}: React.ComponentProps<typeof StatusTrackerEvent>) => {
+ if (!from) return null;
+ if (!to) return "ongoing";
+ const duration = formatDistanceStrict(from, to);
+ const isMultipleIncidents = name.includes("Downtime (");
+ if (isMultipleIncidents) return `across ${duration}`;
+ if (duration === "0 seconds") return null;
+ return duration;
+};
diff --git a/packages/api/src/router/statusPage.ts b/packages/api/src/router/statusPage.ts
index 934438ede..c623d928c 100644
--- a/packages/api/src/router/statusPage.ts
+++ b/packages/api/src/router/statusPage.ts
@@ -125,6 +125,7 @@ export const statusPageRouter = createTRPCRouter({
.filter((e) => {
if (e.type === "incident") return false;
if (!e.from || e.from.getTime() >= threshold) return true;
+ if (e.type === "report" && e.status !== "success") return true;
return false;
})
.sort((a, b) => a.from.getTime() - b.from.getTime());
diff --git a/packages/api/src/router/statusPage.utils.ts b/packages/api/src/router/statusPage.utils.ts
index 8a481b7d0..fd0e8f3b7 100644
--- a/packages/api/src/router/statusPage.utils.ts
+++ b/packages/api/src/router/statusPage.utils.ts
@@ -134,7 +134,7 @@ export function getEvents({
if (!incident.createdAt || incident.createdAt < pastThreshod) return;
events.push({
id: incident.id,
- name: incident.title || "Downtime",
+ name: "Downtime",
from: incident.createdAt,
to: incident.resolvedAt,
type: "incident",
@@ -703,12 +703,33 @@ export function setDataByType({
break;
}
+ // Bundle incidents that occur on the same day if there are more than 4
+ const bundledIncidents =
+ incidents.length > 4
+ ? [
+ {
+ id: -1, // Use -1 to indicate bundled incidents
+ name: `Downtime (${incidents.length} incidents)`,
+ from: new Date(
+ Math.min(...incidents.map((i) => i.from.getTime())),
+ ),
+ to: new Date(
+ Math.max(
+ ...incidents.map((i) => (i.to || new Date()).getTime()),
+ ),
+ ),
+ type: "incident" as const,
+ status: "error" as const,
+ },
+ ]
+ : incidents;
+
return {
day: dayData.day,
events: [
...reports,
...maintenances,
- ...(barType === "absolute" ? incidents : []),
+ ...(barType === "absolute" ? bundledIncidents : []),
],
bar: barData,
card: cardData,