Skip to content

Open-source status page, incident response and uptime monitoring

fix: proportional reports maintenances incidents (#2220)

Maximilian Kaske8964cc366357
diff --git a/packages/api/src/router/statusPage.utils.test.ts b/packages/api/src/router/statusPage.utils.test.ts
index 5ca7a3420..8105774fb 100644
--- a/packages/api/src/router/statusPage.utils.test.ts
+++ b/packages/api/src/router/statusPage.utils.test.ts
@@ -155,6 +155,65 @@ describe("setDataByType", () => {
expect(statuses).toContain("info");
});
+ it("should keep downtime proportional to the day when maintenance is present", () => {
+ const data = [createStatusData(0, 100, 0, 0)];
+ const events = [
+ createMaintenance(1, 0, 2), // 2h maintenance
+ createIncident(2, 0, 1), // 1h downtime
+ ];
+
+ const result = setDataByType({
+ events,
+ data,
+ cardType: "requests",
+ barType: "absolute",
+ });
+
+ const bar = result[0].bar;
+ const errorHeight = bar.find((b) => b.status === "error")?.height ?? 0;
+ const infoHeight = bar.find((b) => b.status === "info")?.height ?? 0;
+
+ // 1h downtime is at most 1/24 of the day (~4.17%), never the old ~33%
+ expect(errorHeight).toBeGreaterThan(0);
+ expect(errorHeight).toBeLessThan(5);
+ expect(errorHeight).toBeLessThan(infoHeight);
+ // maintenance fills the remaining space, no green uptime
+ expect(bar.some((b) => b.status === "success")).toBe(false);
+ expect(errorHeight + infoHeight).toBeCloseTo(100, 5);
+ });
+
+ it("should fill the whole day for a maintenance-only day", () => {
+ const data = [createStatusData(0, 100, 0, 0)];
+ const events = [createMaintenance(1, 0, 2)];
+
+ const result = setDataByType({
+ events,
+ data,
+ cardType: "requests",
+ barType: "absolute",
+ });
+
+ expect(result[0].bar).toHaveLength(1);
+ expect(result[0].bar[0].status).toBe("info");
+ expect(result[0].bar[0].height).toBe(100);
+ });
+
+ it("should fill the whole day for a report-only day", () => {
+ const data = [createStatusData(0, 100, 0, 0)];
+ const events = [createReport(1, 0, 2)];
+
+ const result = setDataByType({
+ events,
+ data,
+ cardType: "requests",
+ barType: "absolute",
+ });
+
+ expect(result[0].bar).toHaveLength(1);
+ expect(result[0].bar[0].status).toBe("degraded");
+ expect(result[0].bar[0].height).toBe(100);
+ });
+
it("should show empty bar when no data available", () => {
const data = [createStatusData(0, 0, 0, 0)];
const events: Event[] = [];
diff --git a/packages/api/src/router/statusPage.utils.ts b/packages/api/src/router/statusPage.utils.ts
index d8d36cec4..7d613688a 100644
--- a/packages/api/src/router/statusPage.utils.ts
+++ b/packages/api/src/router/statusPage.utils.ts
@@ -484,16 +484,36 @@ export function setDataByType({
function createProportionalBarData(
segments: Array<{ status: "info" | "degraded" | "error"; count: number }>,
): UptimeData["bar"] {
- const totalDuration = segments.reduce(
+ // Downtime keeps its true proportion of the day; maintenance/reports are
+ // highlight events that fill the remaining space (no uptime shown).
+ const errorMs = segments
+ .filter((segment) => segment.status === "error")
+ .reduce((sum, segment) => sum + segment.count, 0);
+ const errorHeight =
+ (Math.min(errorMs, MILLISECONDS_PER_DAY) / MILLISECONDS_PER_DAY) * 100;
+ const remainingHeight = Math.max(0, 100 - errorHeight);
+
+ const highlightSegments = segments.filter(
+ (segment) => segment.status !== "error",
+ );
+ const highlightTotal = highlightSegments.reduce(
(sum, segment) => sum + segment.count,
0,
);
- return segments.map((segment) => ({
- status: segment.status,
- // NOTE: if totalDuration is 0 (single event without duration), we want to show 100% for the segment
- height: totalDuration > 0 ? (segment.count / totalDuration) * 100 : 100,
- }));
+ return segments.map((segment) => {
+ if (segment.status === "error") {
+ return { status: segment.status, height: errorHeight };
+ }
+ // instant highlight events (no duration) split the remaining space evenly
+ return {
+ status: segment.status,
+ height:
+ highlightTotal > 0
+ ? (segment.count / highlightTotal) * remainingHeight
+ : remainingHeight / highlightSegments.length,
+ };
+ });
}
function createStatusSegments(