Skip to content

Open-source status page, incident response and uptime monitoring

chore: stpg improvements (#1387)

Maximilian Kaske7fbfedaea96d
diff --git a/apps/dashboard/src/app/metadata.ts b/apps/dashboard/src/app/metadata.ts
index fd9971e17..922876cf6 100644
--- a/apps/dashboard/src/app/metadata.ts
+++ b/apps/dashboard/src/app/metadata.ts
@@ -1,10 +1,10 @@
import type { Metadata } from "next";
-export const TITLE = "OpenStatus";
+export const TITLE = "openstatus";
export const DESCRIPTION =
- "OpenStatus is an open-source platform to monitor your services and keep your users informed.";
+ "Open-source platform to monitor your services and keep your users informed.";
-const OG_TITLE = "OpenStatus";
+const OG_TITLE = "openstatus";
const OG_DESCRIPTION = "Monitor your services and keep your users informed.";
const FOOTER = "app.openstatus.dev";
const IMAGE = "assets/og/dashboard-v2.png";
diff --git a/apps/status-page/src/app/global-error.tsx b/apps/status-page/src/app/global-error.tsx
index f9babe1cf..6acd44847 100644
--- a/apps/status-page/src/app/global-error.tsx
+++ b/apps/status-page/src/app/global-error.tsx
@@ -1,13 +1,16 @@
"use client";
+import { Link } from "@/components/common/link";
+import { Button } from "@/components/ui/button";
import * as Sentry from "@sentry/nextjs";
-import NextError from "next/error";
import { useEffect } from "react";
export default function GlobalError({
error,
+ reset,
}: {
error: Error & { digest?: string };
+ reset: () => void;
}) {
useEffect(() => {
Sentry.captureException(error);
@@ -16,9 +19,38 @@ export default function GlobalError({
return (
<html lang="en">
<body>
- {/* This is the default Next.js error component but it doesn't allow omitting the statusCode property yet. */}
- {/* biome-ignore lint/suspicious/noExplicitAny: <explanation> */}
- <NextError statusCode={undefined as any} />
+ <main className="flex min-h-screen w-full flex-col space-y-6 bg-background p-4 md:p-8">
+ <div className="flex flex-1 flex-col items-center justify-center gap-8">
+ <div className="mx-auto max-w-xl border bg-card text-center">
+ <div className="flex flex-col gap-4 p-6 sm:p-12">
+ <div className="flex flex-col gap-1">
+ <h2 className="font-cal text-2xl text-foreground">
+ Application Error
+ </h2>
+ <p className="text-muted-foreground text-sm sm:text-base">
+ An unexpected error occurred. This has been reported and
+ we&apos;re working on it.{" "}
+ <Link href="mailto:[email protected]">Contact us</Link> if
+ it persists.
+ </p>
+ </div>
+ <div className="flex flex-col items-center justify-center gap-4 sm:flex-row">
+ <Button
+ variant="outline"
+ size="lg"
+ onClick={reset}
+ className="cursor-pointer"
+ >
+ Try Again
+ </Button>
+ <Button size="lg" asChild>
+ <Link href="/">Go Home</Link>
+ </Button>
+ </div>
+ </div>
+ </div>
+ </div>
+ </main>
</body>
</html>
);
diff --git a/apps/status-page/src/app/metadata.ts b/apps/status-page/src/app/metadata.ts
index d133ade2b..37663c9b7 100644
--- a/apps/status-page/src/app/metadata.ts
+++ b/apps/status-page/src/app/metadata.ts
@@ -1,13 +1,14 @@
import type { Metadata } from "next";
-export const TITLE = "OpenStatus";
+export const TITLE = "openstatus";
export const DESCRIPTION =
- "OpenStatus is an open-source platform to monitor your services and keep your users informed.";
+ "Use community themes for your status page or contribute your own.";
-const OG_TITLE = "OpenStatus";
-const OG_DESCRIPTION = "Monitor your services and keep your users informed.";
-const FOOTER = "app.openstatus.dev";
-const IMAGE = "assets/og/dashboard-v2.png";
+const OG_TITLE = "Theme Store";
+const OG_DESCRIPTION =
+ "Use community themes for your status page or contribute your own.";
+const FOOTER = "themes.openstatus.dev";
+const IMAGE = "assets/og/status-page.png";
export const defaultMetadata: Metadata = {
title: {
diff --git a/apps/status-page/src/app/not-found.tsx b/apps/status-page/src/app/not-found.tsx
index 86b5aacd9..267c6f981 100644
--- a/apps/status-page/src/app/not-found.tsx
+++ b/apps/status-page/src/app/not-found.tsx
@@ -9,11 +9,11 @@ export default function NotFound() {
const router = useRouter();
return (
- <main className="flex min-h-screen w-full flex-col space-y-6 p-4 md:p-8 bg-background">
+ <main className="flex min-h-screen w-full flex-col space-y-6 bg-background p-4 md:p-8">
<div className="flex flex-1 flex-col items-center justify-center gap-8">
- <div className="mx-auto max-w-xl text-center border bg-card">
+ <div className="mx-auto max-w-xl border bg-card text-center">
<div className="flex flex-col gap-4 p-6 sm:p-12">
- <div className="flex flex-col gap-2">
+ <div className="flex flex-col gap-1">
<p className="font-mono text-foreground">404 Page not found</p>
<h2 className="font-cal text-2xl text-foreground">
Oops, something went wrong.
@@ -26,7 +26,7 @@ export default function NotFound() {
<Button
variant="outline"
size="lg"
- onClick={() => void router.back()}
+ onClick={router.back}
className="cursor-pointer"
>
Go Back
diff --git a/apps/status-page/src/components/status-page/floating-button.tsx b/apps/status-page/src/components/status-page/floating-button.tsx
index 74486e9ac..b2f9f51e0 100644
--- a/apps/status-page/src/components/status-page/floating-button.tsx
+++ b/apps/status-page/src/components/status-page/floating-button.tsx
@@ -149,10 +149,6 @@ export function StatusPageProvider({
);
}
-const DISPLAY_FLOATING_BUTTON =
- process.env.NODE_ENV === "development" ||
- process.env.NEXT_PUBLIC_ENABLE_FLOATING_BUTTON === "true";
-
export function FloatingButton({ className }: { className?: string }) {
const {
cardType,
@@ -166,8 +162,26 @@ export function FloatingButton({ className }: { className?: string }) {
radius,
setRadius,
} = useStatusPage();
+ const [display, setDisplay] = useState(false);
+
+ useEffect(() => {
+ const enabled =
+ sessionStorage.getItem("status-page-configuration") === "true";
+ const host = window.location.host;
+ if (
+ (host.includes("localhost") ||
+ host.includes("stpg.dev") ||
+ host.includes("openstatus.dev") ||
+ host.includes("vercel.app")) &&
+ enabled
+ ) {
+ setDisplay(true);
+ } else if (process.env.NODE_ENV === "development") {
+ setDisplay(true);
+ }
+ }, []);
- if (!DISPLAY_FLOATING_BUTTON) return null;
+ if (!display) return null;
return (
<div className={cn("fixed right-4 bottom-4 z-50", className)}>
diff --git a/apps/status-page/src/components/status-page/floating-theme.tsx b/apps/status-page/src/components/status-page/floating-theme.tsx
index 91bc6e5c2..c41b749b8 100644
--- a/apps/status-page/src/components/status-page/floating-theme.tsx
+++ b/apps/status-page/src/components/status-page/floating-theme.tsx
@@ -36,6 +36,7 @@ export function FloatingTheme({ className }: { className?: string }) {
if (
(host.includes("localhost") ||
host.includes("stpg.dev") ||
+ host.includes("openstatus.dev") ||
host.includes("vercel.app")) &&
enabled
) {
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 b10d2e790..d4deb4146 100644
--- a/apps/status-page/src/components/status-page/status-events.tsx
+++ b/apps/status-page/src/components/status-page/status-events.tsx
@@ -103,30 +103,42 @@ export function StatusEventTimelineReport({
}[];
withDot?: boolean;
}) {
- const startedAt = new Date(updates[0].date);
- const endedAt = new Date(updates[updates.length - 1].date);
- const duration = formatDistanceStrict(startedAt, endedAt);
return (
<div className={cn("text-muted-foreground text-sm", className)} {...props}>
- {/* TODO: make sure they are sorted by date */}
+ {/* NOTE: make sure they are sorted by date */}
{updates
.sort((a, b) => b.date.getTime() - a.date.getTime())
- .map((update, index) => (
- <StatusEventTimelineReportUpdate
- key={index}
- report={update}
- duration={
- index === 0 &&
- update.status === "resolved" &&
- duration !== "0 seconds"
- ? duration
- : undefined
+ .map((update, index) => {
+ const updateDate = new Date(update.date);
+ let durationText: string | undefined;
+
+ if (index === 0) {
+ const startedAt = new Date(updates[updates.length - 1].date);
+ const duration = formatDistanceStrict(startedAt, updateDate);
+
+ if (duration !== "0 seconds" && update.status === "resolved") {
+ durationText = `(in ${duration})`;
}
- withSeparator={index !== updates.length - 1}
- withDot={withDot}
- isLast={index === updates.length - 1}
- />
- ))}
+ } else {
+ const lastUpdateDate = new Date(updates[index - 1].date);
+ const timeFromLast = formatDistanceStrict(
+ updateDate,
+ lastUpdateDate,
+ );
+ durationText = `(${timeFromLast} earlier)`;
+ }
+
+ return (
+ <StatusEventTimelineReportUpdate
+ key={index}
+ report={update}
+ duration={durationText}
+ withSeparator={index !== updates.length - 1}
+ withDot={withDot}
+ isLast={index === updates.length - 1}
+ />
+ );
+ })}
</div>
);
}
@@ -151,7 +163,7 @@ function StatusEventTimelineReportUpdate({
return (
<div data-variant={report.status} className="group">
<div className="flex flex-row items-center justify-between gap-2">
- <div className="flex flex-row gap-2">
+ <div className="flex flex-row gap-4">
{withDot ? (
<div className="flex flex-col">
<div className="flex h-5 flex-col items-center justify-center">
@@ -164,14 +176,14 @@ function StatusEventTimelineReportUpdate({
<StatusEventTimelineTitle>
<span>{status[report.status]}</span>{" "}
{/* underline decoration-dashed underline-offset-2 decoration-muted-foreground/30 */}
- <span className="font-mono text-muted-foreground/70 text-xs">
+ <span className="font-mono text-muted-foreground text-xs">
<TimestampHoverCard date={new Date(report.date)} asChild>
<span>{formatDateTime(report.date)}</span>
</TimestampHoverCard>
</span>{" "}
{duration ? (
<span className="font-mono text-muted-foreground/70 text-xs">
- (in {duration})
+ {duration}
</span>
) : null}
</StatusEventTimelineTitle>
@@ -204,7 +216,7 @@ export function StatusEventTimelineMaintenance({
return (
<div data-variant="maintenance" className="group">
<div className="flex flex-row items-center justify-between gap-2">
- <div className="flex flex-row gap-2">
+ <div className="flex flex-row gap-4">
{withDot ? (
<div className="flex flex-col">
<div className="flex h-5 flex-col items-center justify-center">
@@ -216,7 +228,7 @@ export function StatusEventTimelineMaintenance({
<div>
<StatusEventTimelineTitle>
<span>Maintenance</span>{" "}
- <span className="font-mono text-muted-foreground/70 text-xs">
+ <span className="font-mono text-muted-foreground text-xs">
<TimestampHoverCard date={maintenance.from} asChild>
<span>{from}</span>
</TimestampHoverCard>
@@ -264,7 +276,7 @@ export function StatusEventTimelineMessage({
}: React.ComponentProps<"div">) {
return (
<div
- className={cn("font-mono text-muted-foreground text-sm", className)}
+ className={cn("py-1.5 font-mono text-foreground/90 text-sm", className)}
{...props}
>
{children}
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 7feb92f51..f25018708 100644
--- a/apps/status-page/src/components/status-page/status-tracker.tsx
+++ b/apps/status-page/src/components/status-page/status-tracker.tsx
@@ -303,7 +303,7 @@ export function StatusTracker({ data }: { data: UptimeData }) {
const content = (
<StatusTrackerEvent
- key={event.id}
+ key={`${event.id}-${event.type}`}
status={eventStatus}
name={event.name}
from={event.from}
diff --git a/apps/web/public/assets/og/status-page.png b/apps/web/public/assets/og/status-page.png
new file mode 100644
index 000000000..048993f13
Binary files /dev/null and b/apps/web/public/assets/og/status-page.png differ
diff --git a/packages/api/src/router/statusPage.utils.ts b/packages/api/src/router/statusPage.utils.ts
index f541bed3d..a04de2ca9 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,
+ name: incident.title || "Downtime",
from: incident.createdAt,
to: incident.resolvedAt,
type: "incident",
@@ -213,6 +213,10 @@ const STATUS_PRIORITY = {
empty: -1,
} as const;
+// Constants for time calculations
+const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;
+const MILLISECONDS_PER_MINUTE = 1000 * 60;
+
// Helper to get highest priority status from data
function getHighestPriorityStatus(
item: StatusData,
@@ -298,8 +302,8 @@ function getTotalEventsDurationMs(events: Event[], date: Date): number {
return acc + Math.max(0, duration);
}, 0);
- // Cap at 24 hours (86400000 milliseconds) per day
- return Math.min(total, 24 * 60 * 60 * 1000);
+ // Cap at 24 hours per day
+ return Math.min(total, MILLISECONDS_PER_DAY);
}
export function setDataByType({
@@ -313,6 +317,194 @@ export function setDataByType({
cardType: "requests" | "duration" | "dominant" | "manual";
barType: "absolute" | "dominant" | "manual";
}): UptimeData[] {
+ // Helper functions moved inside to share inputs and avoid parameter passing
+ function createEventSegments(
+ incidents: Event[],
+ reports: Event[],
+ maintenances: Event[],
+ date: Date,
+ ): Array<{ status: "info" | "degraded" | "error"; count: number }> {
+ const eventTypes = [
+ { status: "info" as const, events: maintenances },
+ { status: "degraded" as const, events: reports },
+ { status: "error" as const, events: incidents },
+ ];
+
+ return eventTypes
+ .filter(({ events }) => events.length > 0)
+ .map(({ status, events }) => ({
+ status,
+ count: getTotalEventsDurationMs(events, date),
+ }));
+ }
+
+ function createErrorOnlyBarData(
+ errorSegmentCount: number,
+ ): UptimeData["bar"] {
+ return [
+ {
+ status: "success" as const,
+ height:
+ ((MILLISECONDS_PER_DAY - errorSegmentCount) / MILLISECONDS_PER_DAY) *
+ 100,
+ },
+ {
+ status: "error" as const,
+ height: (errorSegmentCount / MILLISECONDS_PER_DAY) * 100,
+ },
+ ];
+ }
+
+ function createProportionalBarData(
+ segments: Array<{ status: "info" | "degraded" | "error"; count: number }>,
+ ): UptimeData["bar"] {
+ const totalDuration = segments.reduce(
+ (sum, segment) => sum + segment.count,
+ 0,
+ );
+
+ return segments.map((segment) => ({
+ status: segment.status,
+ height: (segment.count / totalDuration) * 100,
+ }));
+ }
+
+ function createStatusSegments(
+ dayData: StatusData,
+ ): Array<{ status: "success" | "degraded" | "error"; count: number }> {
+ return [
+ { status: "success" as const, count: dayData.ok },
+ { status: "degraded" as const, count: dayData.degraded },
+ { status: "error" as const, count: dayData.error },
+ ];
+ }
+
+ function segmentsToBarData(
+ segments: Array<{
+ status: "success" | "degraded" | "error";
+ count: number;
+ }>,
+ total: number,
+ ): UptimeData["bar"] {
+ return segments
+ .filter((segment) => segment.count > 0)
+ .map((segment) => ({
+ status: segment.status,
+ height: (segment.count / total) * 100,
+ }));
+ }
+
+ function createEmptyBarData(): UptimeData["bar"] {
+ return [
+ {
+ status: "empty",
+ height: 100,
+ },
+ ];
+ }
+
+ function createEmptyCardData(
+ eventStatus?: "error" | "degraded" | "info" | "success" | "empty",
+ ): UptimeData["card"] {
+ return [{ status: eventStatus ?? "empty", value: "" }];
+ }
+
+ function createRequestEntries(dayData: StatusData): Array<{
+ status: "success" | "degraded" | "error" | "info";
+ count: number;
+ }> {
+ return [
+ { status: "success" as const, count: dayData.ok },
+ { status: "degraded" as const, count: dayData.degraded },
+ { status: "error" as const, count: dayData.error },
+ { status: "info" as const, count: 0 },
+ ];
+ }
+
+ function createDurationEntries(dayData: StatusData): Array<{
+ status: "success" | "degraded" | "error" | "info";
+ count: number;
+ }> {
+ return [
+ { status: "error" as const, count: dayData.error },
+ { status: "degraded" as const, count: dayData.degraded },
+ { status: "success" as const, count: dayData.ok },
+ { status: "info" as const, count: 0 },
+ ];
+ }
+
+ function entriesToRequestCardData(
+ entries: Array<{
+ status: "success" | "degraded" | "error" | "info";
+ count: number;
+ }>,
+ ): UptimeData["card"] {
+ return entries
+ .filter((entry) => entry.count > 0)
+ .map((entry) => ({
+ status: entry.status,
+ value: `${formatNumber(entry.count)} reqs`,
+ }));
+ }
+
+ // Helper to calculate duration in minutes for a specific event type
+ function calculateEventDurationMinutes(events: Event[], date: Date): number {
+ const totalDuration = getTotalEventsDurationMs(events, date);
+ return Math.round(totalDuration / MILLISECONDS_PER_MINUTE);
+ }
+
+ // Helper to calculate total minutes in a day (handles today vs past days)
+ function getTotalMinutesInDay(date: Date): number {
+ const now = new Date();
+ const startOfDay = new Date(date);
+ startOfDay.setUTCHours(0, 0, 0, 0);
+
+ if (isToday(date)) {
+ const minutesElapsed = Math.floor(
+ (now.getTime() - startOfDay.getTime()) / MILLISECONDS_PER_MINUTE,
+ );
+ return minutesElapsed;
+ }
+ return 24 * 60;
+ }
+
+ // Helper to create duration card data for a specific status
+ function createDurationCardEntry(
+ status: "error" | "degraded" | "info" | "success",
+ events: Event[],
+ date: Date,
+ durationMap: Map<string, number>,
+ ): {
+ status: "error" | "degraded" | "info" | "success";
+ value: string;
+ } | null {
+ if (status === "success") {
+ // Calculate success duration as remaining time
+ let totalEventMinutes = 0;
+ // biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
+ durationMap.forEach((minutes) => (totalEventMinutes += minutes));
+
+ const totalMinutesInDay = getTotalMinutesInDay(date);
+ const successMinutes = Math.max(totalMinutesInDay - totalEventMinutes, 0);
+
+ if (successMinutes === 0) return null;
+ return {
+ status,
+ value: formatDuration(successMinutes),
+ };
+ }
+
+ // For error, degraded, info - calculate from events
+ const minutes = calculateEventDurationMinutes(events, date);
+ durationMap.set(status, minutes);
+
+ if (minutes === 0) return null;
+ return {
+ status,
+ value: formatDuration(minutes),
+ };
+ }
+
return data.map((dayData) => {
const date = new Date(dayData.day);
@@ -346,35 +538,31 @@ export function setDataByType({
switch (barType) {
case "absolute":
if (eventStatus) {
- // If there's an event override, show single status
- barData = [
- {
- status: eventStatus,
- height: 100,
- },
- ];
+ // Create segments based on event durations for the day
+ const eventSegments = createEventSegments(
+ incidents,
+ reports,
+ maintenances,
+ date,
+ );
+
+ // Special case: if only errors exist, show uptime vs downtime
+ if (
+ eventSegments.length === 1 &&
+ eventSegments[0].status === "error"
+ ) {
+ barData = createErrorOnlyBarData(eventSegments[0].count);
+ } else {
+ // Multiple segments: show proportional distribution
+ barData = createProportionalBarData(eventSegments);
+ }
} else if (total === 0) {
- // Empty day
- barData = [
- {
- status: "empty",
- height: 100,
- },
- ];
+ // Empty day - no data available
+ barData = createEmptyBarData();
} else {
- // Multiple segments for absolute view
- const segments = [
- { status: "success" as const, count: dayData.ok },
- { status: "degraded" as const, count: dayData.degraded },
- { status: "error" as const, count: dayData.error },
- ]
- .filter((segment) => segment.count > 0)
- .map((segment) => ({
- status: segment.status,
- height: (segment.count / total) * 100,
- }));
-
- barData = segments;
+ // Multiple segments for absolute view - show proportional distribution of status data
+ const statusSegments = createStatusSegments(dayData);
+ barData = segmentsToBarData(statusSegments, total);
}
break;
case "dominant":
@@ -416,104 +604,37 @@ export function setDataByType({
switch (cardType) {
case "requests":
if (total === 0) {
- cardData = [{ status: eventStatus ?? "empty", value: "" }];
+ cardData = createEmptyCardData(eventStatus);
} else {
- const entries = [
- { status: "success" as const, count: dayData.ok },
- { status: "degraded" as const, count: dayData.degraded },
- { status: "error" as const, count: dayData.error },
- { status: "info" as const, count: 0 },
- ];
-
- cardData = entries
- .filter((entry) => entry.count > 0)
- .map((entry) => ({
- status: entry.status,
- value: `${formatNumber(entry.count)} reqs`,
- }));
+ const requestEntries = createRequestEntries(dayData);
+ cardData = entriesToRequestCardData(requestEntries);
}
break;
case "duration":
if (total === 0) {
- cardData = [{ status: eventStatus ?? "empty", value: "" }];
+ cardData = createEmptyCardData(eventStatus);
} else {
- const entries = [
- { status: "error" as const, count: dayData.error },
- { status: "degraded" as const, count: dayData.degraded },
- { status: "success" as const, count: dayData.ok },
- { status: "info" as const, count: 0 },
- ];
-
- const map = new Map<
- "error" | "degraded" | "success" | "info",
- number
- >();
+ const entries = createDurationEntries(dayData);
+ const durationMap = new Map<string, number>();
cardData = entries
.map((entry) => {
- if (entry.status === "error") {
- const totalDuration = getTotalEventsDurationMs(incidents, date);
- const minutes = Math.round(totalDuration / (1000 * 60));
- map.set("error", minutes);
- if (minutes === 0) return null;
- return {
- status: entry.status,
- value: formatDuration(minutes),
- };
- }
-
- if (entry.status === "degraded") {
- const totalDuration = getTotalEventsDurationMs(reports, date);
- const minutes = Math.round(totalDuration / (1000 * 60));
- map.set("degraded", minutes);
- if (minutes === 0) return null;
- return {
- status: entry.status,
- value: formatDuration(minutes),
- };
- }
-
- if (entry.status === "info") {
- const totalDuration = getTotalEventsDurationMs(
- maintenances,
- date,
- );
- const minutes = Math.round(totalDuration / (1000 * 60));
- map.set("info", minutes);
- if (minutes === 0) return null;
- return {
- status: entry.status,
- value: formatDuration(minutes),
- };
- }
-
- if (entry.status === "success") {
- let total = 0;
- // biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
- map.forEach((d) => (total += d));
-
- const now = new Date();
- const startOfDay = new Date(date);
- startOfDay.setUTCHours(0, 0, 0, 0);
-
- let totalMinutesInDay: number;
- if (isToday(date)) {
- const minutesElapsed = Math.floor(
- (now.getTime() - startOfDay.getTime()) / (1000 * 60),
- );
- totalMinutesInDay = minutesElapsed;
- } else {
- totalMinutesInDay = 24 * 60;
- }
-
- const minutes = Math.max(totalMinutesInDay - total, 0);
- if (minutes === 0) return null;
- return {
- status: entry.status,
- value: formatDuration(minutes),
- };
- }
+ // Map each entry status to its corresponding events
+ const eventMap = {
+ error: incidents,
+ degraded: reports,
+ info: maintenances,
+ success: [], // Success is calculated differently
+ };
+
+ const events = eventMap[entry.status as keyof typeof eventMap];
+ return createDurationCardEntry(
+ entry.status,
+ events,
+ date,
+ durationMap,
+ );
})
.filter((item): item is NonNullable<typeof item> => item !== null);
}
@@ -544,27 +665,21 @@ export function setDataByType({
default:
// Default to requests behavior
if (total === 0) {
- cardData = [{ status: eventStatus ?? "empty", value: "" }];
+ cardData = createEmptyCardData(eventStatus);
} else {
- const entries = [
- { status: "error" as const, count: dayData.error },
- { status: "degraded" as const, count: dayData.degraded },
- { status: "success" as const, count: dayData.ok },
- ];
-
- cardData = entries
- .filter((entry) => entry.count > 0)
- .map((entry) => ({
- status: entry.status,
- value: `${formatNumber(entry.count)} reqs`,
- }));
+ const defaultEntries = createRequestEntries(dayData);
+ cardData = entriesToRequestCardData(defaultEntries);
}
break;
}
return {
day: dayData.day,
- events: [...reports, ...maintenances],
+ events: [
+ ...reports,
+ ...maintenances,
+ ...(barType === "absolute" ? incidents : []),
+ ],
bar: barData,
card: cardData,
};
@@ -589,7 +704,7 @@ export function getUptime({
return acc + ((item.to || new Date()).getTime() - item.from.getTime());
}, 0);
- const total = data.length * 24 * 60 * 60 * 1000;
+ const total = data.length * MILLISECONDS_PER_DAY;
return `${Math.round(((total - duration) / total) * 10000) / 100}%`;
}