Skip to content

refactor: unify overall status handling across components and improve… - #753

Merged
rajnandan1 merged 1 commit into
mainfrom
fix/717
Jun 12, 2026
Merged

refactor: unify overall status handling across components and improve…#753
rajnandan1 merged 1 commit into
mainfrom
fix/717

Conversation

@rajnandan1

@rajnandan1 rajnandan1 commented Jun 12, 2026

Copy link
Copy Markdown
Owner

… documentation, fixes #717

Summary by CodeRabbit

  • Bug Fixes

    • Fixed inconsistent status aggregation across UI components to follow a consistent "worst-wins" ordering (DOWN > DEGRADED > MAINTENANCE > UP), preventing maintenance from masking active outages.
  • Documentation

    • Clarified overall status priority ordering and the site-wide all-monitors badge behavior in the sharing monitors guide.

Copilot AI review requested due to automatic review settings June 12, 2026 06:53
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR implements consistent "problem-first" status ordering across all components. It introduces a CollapseStatusCounts helper that enforces DOWN > DEGRADED > MAINTENANCE > UP ordering, refactors controller and client code to use it, removes the now-unused getMonitoringDataAll method stack-wide, and updates documentation to clarify site-wide badge semantics.

Changes

Consistent Status Ordering

Layer / File(s) Summary
Canonical status ordering definition
CONTEXT.md, docs/adr/0007-problem-first-overall-status.md
Glossary entries define Overall Status (worst-state collapse rule) and All-Monitors Badge (_ token, site-wide scope). ADR 0007 documents the problem-first ordering (DOWN > DEGRADED > MAINTENANCE > UP), records Issue #717 inconsistencies, and clarifies that the site-wide badge is intentionally not page-scoped.
Status collapse helper and export
src/lib/clientTools.ts
New CollapseStatusCounts helper applies canonical status ordering by counting occurrences and returning the worst state. Import of GC constants added alongside export of the helper function.
Client summary and color functions refactor
src/lib/clientTools.ts
GetStatusSummary and GetStatusColor refactored to use CollapseStatusCounts via switch statements, removing prior inline percent-based and maintenance-first branching logic.
Controller integration and filter standardization
src/lib/server/controllers/monitorsController.ts
GetLatestStatusActiveAll refactored to count status occurrences and return collapsed result via CollapseStatusCounts. Monitor queries across badge generation paths standardized to use GC.ACTIVE/GC.NO constants instead of string literals, with consistent active/not-hidden filtering applied.
Removal of getMonitoringDataAll across stack
src/lib/server/controllers/monitorsController.ts, src/lib/server/db/dbimpl.ts, src/lib/server/db/repositories/monitoring.ts
Exported GetMonitoringDataAll function removed from controller. DbImpl class binding for getMonitoringDataAll removed. Repository method getMonitoringDataAll removed, completing deprecation of multi-tag monitoring data queries.
User-facing documentation updates
src/routes/(docs)/docs/content/v4/sharing.md
New "All-monitors badge" subsection explains _ badge endpoint patterns and site-wide (non-page-scoped) semantics. "Overall status priority" subsection defines collapse ordering and clarifies maintenance behavior and NO_DATA conditions.

🎯 3 (Moderate) | ⏱️ ~25 minutes

A rabbit hops through status streams,
Now worst wins cleanly—no maintenance dreams,
From constants to counts, the logic flows bright,
Bad news rings loudly, maintenance stays right,
One collapse rule makes everything light. 🐰✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning PR claims to fix issue #722 (manual maintenance completion UI), but changes only address overall status unification and documentation; no manual completion functionality is implemented. Either implement the manual completion feature for issue #722 or remove the reference to that issue from the PR objectives.
Title check ❓ Inconclusive Title is truncated and vague, using ellipsis instead of completing the main change description, making it unclear without viewing the full PR. Complete the title with the full change description (e.g., 'refactor: unify overall status handling and document priority rules') to clearly convey the primary change.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Out of Scope Changes check ✅ Passed All changes consistently focus on unifying status handling logic, refactoring related code paths, and updating documentation to reflect the new status priority rules.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/717

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a long-standing masking bug (issue #722) where a single monitor under maintenance caused the page banner to show "Under Maintenance" even while another monitor was actively DOWN or DEGRADED. It also patched the all-monitors _ badge, which previously had no MAINTENANCE branch at all, causing a fleet entirely under maintenance to fall through to "No Status Available". The fix extracts a single canonical CollapseStatusCounts function (DOWN > DEGRADED > MAINTENANCE > UP) and wires it consistently into both the frontend banner and the server-side badge endpoint.

  • clientTools.ts: new CollapseStatusCounts helper exported and consumed by GetStatusSummary and GetStatusColor, eliminating their independent (and divergent) collapse logic.
  • monitorsController.ts: GetLatestStatusActiveAll rewired to use CollapseStatusCounts; adds proper MAINTENANCE counting that was absent from the old loop; also replaces bare string literals \"ACTIVE\"/\"NO\" with GC.ACTIVE/GC.NO throughout badge lookups.
  • monitoring.ts / dbimpl.ts: removes getMonitoringDataAll, a SQL-level collapse query that omitted MAINTENANCE and is now superseded by the application-level canonical function.

Confidence Score: 4/5

The core bug fix is correct and the canonical collapse function is well-reasoned; the only thing worth verifying before merge is the new active/non-hidden filter on single-monitor uptime/latency badges.

The refactoring is clean and the canonical collapse function correctly fixes both the banner-masking bug and the missing MAINTENANCE branch in the badge loop. The one concern introduced by the PR is the undocumented change in single-monitor uptime/latency badge behaviour for hidden or inactive monitors — callers that relied on those badges returning historical data will now get an error SVG without any migration path.

src/lib/server/controllers/monitorsController.ts — specifically the single-monitor uptime/latency badge path around line 641 where the new active/non-hidden filter was added.

Important Files Changed

Filename Overview
src/lib/clientTools.ts Introduces CollapseStatusCounts (canonical worst-wins collapse), refactors GetStatusSummary and GetStatusColor to delegate to it, and exports the helper for server-side reuse.
src/lib/server/controllers/monitorsController.ts Rewrites GetLatestStatusActiveAll to use count-based accumulation and CollapseStatusCounts; adds MAINTENANCE support that was previously absent. Silently changes single-monitor uptime/latency badge to filter by ACTIVE+non-hidden where it previously had no such filter.
src/lib/server/db/repositories/monitoring.ts Removes getMonitoringDataAll (the SQL-level status-collapse query that lacked a MAINTENANCE branch and is superseded by the new application-level CollapseStatusCounts).
src/lib/server/db/dbimpl.ts Removes the getMonitoringDataAll binding to match the repository removal; no other changes.
docs/adr/0007-problem-first-overall-status.md New ADR documenting the problem-first overall-status ordering and the rationale for rejecting alternatives; well-written and accurate.
CONTEXT.md Adds canonical definitions for Overall Status and All-Monitors Badge consistent with the ADR and implementation.
src/routes/(docs)/docs/content/v4/sharing.md Documents the _ token, all-monitors badge scope, and the DOWN > DEGRADED > MAINTENANCE > UP ordering in user-facing docs.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Monitor statuses collected\n(ACTIVE, non-hidden)"] --> B["Accumulate counts\ncountOfUp / Down / Degraded / Maintenance"]
    B --> C{"CollapseStatusCounts\n(canonical collapse)"}
    C -->|"countOfDown > 0"| D["DOWN"]
    C -->|"countOfDegraded > 0"| E["DEGRADED"]
    C -->|"countOfMaintenance > 0"| F["MAINTENANCE"]
    C -->|"countOfUp > 0 (only)"| G["UP"]
    C -->|"total == 0"| H["NO_DATA"]
    D --> I["GetStatusSummary\n≥75% → MAJOR_OUTAGE\nelse → PARTIAL_OUTAGE"]
    E --> J["GetStatusSummary\n≥75% → DEGRADED_PERFORMANCE\nelse → PARTIAL_DEGRADED"]
    F --> K["GetStatusSummary\nUNDER_MAINTENANCE"]
    G --> L["GetStatusSummary\nALL_OPERATIONAL"]
    H --> M["GetStatusSummary\nNO_DATA"]
    subgraph "Page Banner (clientTools.ts)"
        I
        J
        K
        L
        M
    end
    subgraph "_ Badge (monitorsController.ts)"
        C2["CollapseStatusCounts\n(same function)"] --> D2["status string\nreturned directly"]
    end
Loading

Reviews (1): Last reviewed commit: "refactor: unify overall status handling ..." | Re-trigger Greptile

Comment on lines 641 to 644
} else {
// Single monitor badge
const monitors = await GetMonitorsParsed({ tag });
const monitors = await GetMonitorsParsed({ tag, status: GC.ACTIVE, is_hidden: GC.NO });
if (monitors.length === 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Silent behavior change for hidden/inactive single-monitor uptime/latency badges

The single-monitor uptime/latency branch previously queried with only { tag } and returned data for any monitor regardless of status or hidden flag. Adding status: GC.ACTIVE, is_hidden: GC.NO means a badge URL for a hidden or inactive monitor (e.g. an internal service or a temporarily paused check) now returns ErrorSvg instead of historical uptime data. Status badges already behaved this way, so this is arguably a consistency improvement — but it is an undocumented breaking change for anyone who has embedded uptime or latency badges for non-ACTIVE or hidden monitors.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR standardizes how “Overall Status” is derived when collapsing multiple monitor statuses into a single display status (banner and _ all-monitors badge), and updates documentation/ADR to describe the intended worst-wins ordering.

Changes:

  • Added a shared CollapseStatusCounts helper and updated page-status summary/color to use problem-first ordering (DOWN > DEGRADED > MAINTENANCE > UP).
  • Updated server-side all-monitors status aggregation (GetLatestStatusActiveAll) to include MAINTENANCE and to use the same canonical collapse logic.
  • Expanded docs (Sharing page, ADR, glossary/context) and removed the unused getMonitoringDataAll repository method and bindings.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/routes/(docs)/docs/content/v4/sharing.md Documents _ all-monitors badge behavior and overall-status priority.
src/lib/server/db/repositories/monitoring.ts Removes getMonitoringDataAll implementation.
src/lib/server/db/dbimpl.ts Removes getMonitoringDataAll binding/exposure from the DB façade.
src/lib/server/controllers/monitorsController.ts Uses canonical status-collapsing for all-monitors status and tightens badge monitor filtering via constants.
src/lib/clientTools.ts Introduces CollapseStatusCounts and reworks summary/color to use the canonical ordering.
docs/adr/0007-problem-first-overall-status.md Adds ADR documenting problem-first overall-status semantics.
CONTEXT.md Adds/clarifies glossary entries for “Overall Status” and _ all-monitors badge.

@@ -0,0 +1,7 @@
# Overall Status is problem-first: DOWN > DEGRADED > MAINTENANCE > UP

Everywhere a set of monitor statuses collapses into one display status — the page banner (`GetStatusSummary`/`GetStatusColor` in `src/lib/clientTools.ts`), the per-day bar summaries, and the all-monitors `_` badge and dot badge (`GetLatestStatusActiveAll` in `src/lib/server/controllers/monitorsController.ts`) — the same worst-wins ordering applies: DOWN > DEGRADED > MAINTENANCE > UP, with NO_DATA only when no monitor has any data at all.

Everywhere a set of monitor statuses collapses into one display status — the page banner (`GetStatusSummary`/`GetStatusColor` in `src/lib/clientTools.ts`), the per-day bar summaries, and the all-monitors `_` badge and dot badge (`GetLatestStatusActiveAll` in `src/lib/server/controllers/monitorsController.ts`) — the same worst-wins ordering applies: DOWN > DEGRADED > MAINTENANCE > UP, with NO_DATA only when no monitor has any data at all.

Issue #717 exposed that the codebase had three independent answers to "what does maintenance mean when aggregating". The frontend banner checked maintenance first, so one monitor in a planned window reported "Under Maintenance" even while another monitor was hard DOWN — a real outage masked by planned work. The badge loop had no MAINTENANCE branch at all, so maintenance samples were silently skipped (DEGRADED+UP+MAINTENANCE → "Degraded", disagreeing with the banner) and a fleet entirely under maintenance fell through to "No Status Available". Group Monitor scoring counts maintenance as UP. With the same monitors, the page and the badge told different stories, which breaks any automation treating either as the source of truth.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/clientTools.ts`:
- Around line 323-329: Add table-driven unit tests for CollapseStatusCounts to
lock the precedence contract encoded in that function: create a test suite that
imports CollapseStatusCounts, StatusCounts and GC and asserts expected
StatusType for cases including (1) countOfDown>0 and countOfMaintenance>0 =>
GC.DOWN, (2) countOfDegraded>0 and countOfMaintenance>0 => GC.DEGRADED, (3) only
countOfMaintenance>0 => GC.MAINTENANCE, plus baseline cases like all zeros =>
GC.NO_DATA and only up => GC.UP; structure tests as small table rows mapping
input StatusCounts to expected GC value to ensure future changes preserve this
precedence.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f59580ae-a70e-4395-9338-5c481682b7d9

📥 Commits

Reviewing files that changed from the base of the PR and between 1ac0f22 and 4ed40a0.

📒 Files selected for processing (7)
  • CONTEXT.md
  • docs/adr/0007-problem-first-overall-status.md
  • src/lib/clientTools.ts
  • src/lib/server/controllers/monitorsController.ts
  • src/lib/server/db/dbimpl.ts
  • src/lib/server/db/repositories/monitoring.ts
  • src/routes/(docs)/docs/content/v4/sharing.md
💤 Files with no reviewable changes (2)
  • src/lib/server/db/dbimpl.ts
  • src/lib/server/db/repositories/monitoring.ts

Comment thread src/lib/clientTools.ts
Comment on lines +323 to +329
function CollapseStatusCounts(counts: StatusCounts): StatusType {
const total = counts.countOfUp + counts.countOfDown + counts.countOfDegraded + counts.countOfMaintenance;
if (total === 0) return GC.NO_DATA;
if (counts.countOfDown > 0) return GC.DOWN;
if (counts.countOfDegraded > 0) return GC.DEGRADED;
if (counts.countOfMaintenance > 0) return GC.MAINTENANCE;
return GC.UP;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Lock the new precedence contract in tests.

This helper now defines the canonical rule for both the local banner/color helpers and the server-side overall-status path, so a few table-driven cases would pay off here: DOWN + MAINTENANCE => DOWN, DEGRADED + MAINTENANCE => DEGRADED, and MAINTENANCE only => MAINTENANCE.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/clientTools.ts` around lines 323 - 329, Add table-driven unit tests
for CollapseStatusCounts to lock the precedence contract encoded in that
function: create a test suite that imports CollapseStatusCounts, StatusCounts
and GC and asserts expected StatusType for cases including (1) countOfDown>0 and
countOfMaintenance>0 => GC.DOWN, (2) countOfDegraded>0 and countOfMaintenance>0
=> GC.DEGRADED, (3) only countOfMaintenance>0 => GC.MAINTENANCE, plus baseline
cases like all zeros => GC.NO_DATA and only up => GC.UP; structure tests as
small table rows mapping input StatusCounts to expected GC value to ensure
future changes preserve this precedence.

@rajnandan1
rajnandan1 merged commit c301aaa into main Jun 12, 2026
2 checks passed
@rajnandan1
rajnandan1 deleted the fix/717 branch June 12, 2026 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Page status display differs between frontend UI and badge API

2 participants