Skip to content

Open-source status page, incident response and uptime monitoring

fix: dates inbetween (#254)

Maximilian Kaske0a208e9de5f8
diff --git a/apps/web/src/app/status-page/[domain]/layout.tsx b/apps/web/src/app/status-page/[domain]/layout.tsx
index d7eef968b..e7480ed14 100644
--- a/apps/web/src/app/status-page/[domain]/layout.tsx
+++ b/apps/web/src/app/status-page/[domain]/layout.tsx
@@ -6,7 +6,10 @@ export default function StatusPageLayout({
return (
<div className="flex min-h-screen w-full flex-col space-y-6 p-4 md:p-8">
<main className="flex flex-1 flex-col items-center justify-center gap-8">
- <div className="mx-auto w-full max-w-xl text-center">{children}</div>
+ <div className="mx-auto w-full max-w-xl text-center">
+ {children}
+ <IssueBanner />
+ </div>
</main>
<footer className="z-10">
<p className="text-muted-foreground text-center text-sm">
@@ -24,3 +27,14 @@ export default function StatusPageLayout({
</div>
);
}
+
+function IssueBanner() {
+ return (
+ <p className="text-muted-foreground mt-3 text-center text-xs backdrop-blur-[2px]">
+ <span className="inline-flex items-center">
+ OpenStatus faced issues between 24.08. and 27.08., preventing data
+ collection.
+ </span>
+ </p>
+ );
+}
diff --git a/apps/web/src/components/tracker.tsx b/apps/web/src/components/tracker.tsx
index 37b5a9c8e..f501e8d0a 100644
--- a/apps/web/src/components/tracker.tsx
+++ b/apps/web/src/components/tracker.tsx
@@ -37,6 +37,9 @@ const tracker = cva("h-10 rounded-full flex-1", {
},
});
+// We had issues during those dates!
+const blacklistedDates = [1692921600000, 1693008000000];
+
interface TrackerProps {
data: Monitor[];
url: string;
@@ -59,6 +62,10 @@ export function Tracker({
const slicedData = data.slice(0, maxSize).reverse();
const placeholderData: null[] = Array(maxSize).fill(null);
+ const filledData =
+ // playground includes not only aggregated data, but data by ping (so every 10m)
+ context === "play" ? slicedData : fillMissingDates(slicedData);
+
const reducedData = slicedData.reduce(
(prev, curr) => {
prev.ok += curr.ok;
@@ -95,7 +102,7 @@ export function Tracker({
// TODO: use `Bar` component and `HoverCard` with empty state
return <div key={i} className={tracker({ variant: "empty" })} />;
})}
- {slicedData.map((props) => {
+ {filledData.map((props) => {
return (
<Bar key={props.cronTimestamp} context={context} {...props} />
);
@@ -210,8 +217,55 @@ const Bar = ({
// FIXME this is a temporary solution
const getStatus = (
ratio: number,
-): { label: string; variant: "up" | "degraded" | "down" } => {
+): { label: string; variant: "up" | "degraded" | "down" | "empty" } => {
+ if (isNaN(ratio)) return { label: "Missing", variant: "empty" };
if (ratio >= 0.98) return { label: "Operational", variant: "up" };
if (ratio >= 0.5) return { label: "Degraded", variant: "degraded" };
return { label: "Downtime", variant: "down" };
};
+
+// TODO: is there a way to do it with `date-fns`?
+// Function to fill missing dates in the data array
+function fillMissingDates(data: Monitor[]) {
+ const startDate = new Date(data[0].cronTimestamp);
+ const endDate = new Date(data[data.length - 1].cronTimestamp);
+ const dateSequence = generateDateSequence(startDate, endDate);
+
+ const filledData: Monitor[] = [];
+ let dataIndex = 0;
+
+ for (const currentDate of dateSequence) {
+ const currentTimestamp = currentDate.getTime();
+ if (
+ dataIndex < data.length &&
+ data[dataIndex].cronTimestamp === currentTimestamp &&
+ // can be removed once not needed!
+ !blacklistedDates.includes(currentTimestamp)
+ ) {
+ filledData.push(data[dataIndex]);
+ dataIndex++;
+ } else {
+ filledData.push({
+ count: 0,
+ ok: 0,
+ avgLatency: 0,
+ cronTimestamp: currentTimestamp,
+ });
+ }
+ }
+
+ return filledData;
+}
+
+// Function to generate a sequence of dates between two dates
+function generateDateSequence(startDate: Date, endDate: Date) {
+ const dateSequence = [];
+ const currentDate = new Date(startDate);
+
+ while (currentDate <= endDate) {
+ dateSequence.push(new Date(currentDate));
+ currentDate.setDate(currentDate.getDate() + 1);
+ }
+
+ return dateSequence;
+}