Skip to content

Split the connections chart into a gauge and a counter - #417

Open
dpage wants to merge 2 commits into
mainfrom
fix/issue-403-split-connections-chart
Open

Split the connections chart into a gauge and a counter#417
dpage wants to merge 2 commits into
mainfrom
fix/issue-403-split-connections-chart

Conversation

@dpage

@dpage dpage commented Aug 12, 2026

Copy link
Copy Markdown
Member

Summary

PostgresOverviewSection plotted numbackends and sessions as two
series on one shared axis, which mixes two different kinds of
quantity. numbackends is a gauge, bounded by max_connections and
typically in the tens; sessions is a cumulative counter that only
climbs until stats_reset and readily reaches the thousands. The
counter set the scale, the gauge flattened into a line along the
bottom, and the legend invited the reader to compare "40 backends"
with "85,000 sessions" as though both were concurrent.

The section now renders two charts from the same metrics query, so no
extra time-series request is made:

  • Connections (Monitored Database) shows backends together with a
    Max Connections reference series, since a backend count trending
    towards the limit is the signal worth seeing. The reference value
    comes from the latest pg_server_info row through the latest-row
    mode of /api/v1/metrics/query; that probe only stores a row when
    the server configuration changes, so a bucketed query would usually
    come back empty. When the limit is unknown the reference series is
    simply omitted.

  • Sessions Established (Monitored Database) keeps the counter on
    its own axis, with the legend naming it Cumulative Sessions so it
    is not mistaken for a rate.

Both titles state the per-database scope, because the
pg_stat_database probe filters on current_database() and so
undercounts the server total; it also misses walsenders and autovacuum
workers, which still consume connection slots.

The reference line is drawn as a constant series rather than an
ECharts markLine, because Chart does not register the MarkLine
component and deepMerge assigns arrays wholesale, so passing
series through echartsOptions would replace the real data.

Deliberately out of scope

The cleanest long-term treatment of the session counter is a
per-second rate, which would show connection churn directly. That
belongs with #400, which covers raw counters that should be rates
across the dashboard, and is left to it rather than expanded into
this PR. The stacked pg_stat_activity breakdown of active, idle and
idle-in-transaction suggested in #403 is likewise a larger piece of
work needing a new probe series, and is not attempted here. The
change is confined to PostgresOverviewSection.tsx and its tests, so
it does not overlap #404's branch.

Test plan

  • New client/src/components/Dashboard/ServerDashboard/__tests__/PostgresOverviewSection.test.tsx
    with 18 tests covering the split (asserting that no chart carries
    both series), the reference series values, the latest-row query
    parameters, the missing/zero/non-array/failed/aborted max_connections
    paths, the empty and loading panel states, the remaining charts, and
    the KPI tiles.

  • cd client && make coverage: 172 test files, 3506 tests passing.
    PostgresOverviewSection.tsx reports 100% statements, 100% lines,
    100% functions and 97.46% branches, comfortably above the 90% floor.

  • npm run lint is clean for both changed files (0 errors, and the
    40 warnings in the repository are pre-existing and elsewhere), and
    npm run typecheck reports no errors for either file.

  • Visual validation was not possible: neither the dev server nor the
    Vite client was running on the dev host, and they are started
    manually by the developer, so no browser check was made.

  • .claude/react-expert/quality-checklist.md gains a "Dashboard Chart
    Semantics" section recording the gauge-versus-counter rule and the
    markLine caveat.

Closes #403

Summary by CodeRabbit

  • New Features

    • Split the server dashboard’s combined connections chart into separate Connections and Sessions Established charts.
    • Added database-specific chart titles and descriptions for clearer monitoring context.
    • Added a max_connections reference line to connection charts when available.
  • Bug Fixes

    • Improved handling of loading, invalid, failed, and interrupted metric requests.
    • Added clearer placeholders and edge-case handling for dashboard KPIs and cache ratios.
  • Documentation

    • Documented the updated server dashboard chart behavior and metric distinctions.

The server dashboard plotted numbackends and sessions as two series
on one shared axis, which is a category error: numbackends is a gauge
bounded by max_connections and usually sits in the tens, whilst
sessions is a cumulative counter that only climbs until the statistics
are reset and readily reaches the thousands. The counter therefore set
the scale, the gauge collapsed into a flat line along the bottom, and
the legend invited the reader to compare the two as though both were
concurrent figures.

The section now renders two charts from the same metrics query.
Connections shows backends with a max_connections reference series,
which is where the useful signal lives, since a backend count trending
towards the limit means exhaustion risk. Sessions Established keeps
the counter on its own axis, with the legend naming it as cumulative
so nobody mistakes it for a rate. Both titles state that the figures
cover the monitored database, because the pg_stat_database probe
filters on current_database() and so undercounts the server total.

The limit comes from the latest pg_server_info row via the latest-row
mode of the metrics query API; that probe only stores a row when the
server configuration changes, so a bucketed query would usually come
back empty, and the reference series is simply omitted when the limit
is unknown.

Closes #403
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 12 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 90e19226-f478-454b-b8e7-71f9f54a6eb7

📥 Commits

Reviewing files that changed from the base of the PR and between d195322 and 6eceef8.

📒 Files selected for processing (2)
  • client/src/components/Dashboard/ServerDashboard/PostgresOverviewSection.tsx
  • client/src/components/Dashboard/ServerDashboard/__tests__/PostgresOverviewSection.test.tsx

Walkthrough

The PostgreSQL server dashboard now separates backend and cumulative session charts. It retrieves max_connections from the latest pg_server_info row, adds a connection-limit reference series, clarifies database scope, and adds comprehensive tests and changelog documentation.

Changes

PostgreSQL dashboard metrics

Layer / File(s) Summary
Connection limit retrieval
.claude/react-expert/quality-checklist.md, client/src/components/Dashboard/ServerDashboard/PostgresOverviewSection.tsx
The dashboard queries the latest pg_server_info row for max_connections. It accepts positive numeric values, handles errors and aborts, and resets invalid results.
Chart separation and validation
client/src/components/Dashboard/ServerDashboard/PostgresOverviewSection.tsx, client/src/components/Dashboard/ServerDashboard/__tests__/PostgresOverviewSection.test.tsx, docs/changelog.md
The dashboard separates backend and cumulative session datasets. The backend chart includes a Max Connections series when available. Titles, descriptions, tests, and the changelog reflect monitored-database scope and the separate charts.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Dashboard as PostgresOverviewSection
  participant API as API client
  participant Metrics as pg_server_info
  participant Charts as Dashboard charts
  Dashboard->>API: Request latest pg_server_info row
  API->>Metrics: Query max_connections
  Metrics-->>API: Return connection limit
  API-->>Dashboard: Return validated max_connections
  Dashboard->>Charts: Render backend chart with limit and session chart separately
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary change: separating the connections gauge from the cumulative sessions counter.
Linked Issues check ✅ Passed The changes satisfy issue #403 by separating the metrics, adding the max_connections reference line, and labeling the monitored-database scope.
Out of Scope Changes check ✅ Passed The implementation, tests, checklist update, and changelog entry directly support the linked issue and PR objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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/issue-403-split-connections-chart

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

@codacy-production

codacy-production Bot commented Aug 12, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 121 complexity

Metric Results
Complexity 121

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@dpage

dpage commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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: 2

🤖 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
`@client/src/components/Dashboard/ServerDashboard/__tests__/PostgresOverviewSection.test.tsx`:
- Around line 235-290: Update the response-validation tests around renderSection
and seriesNamesFor to use deferred apiGet promises: resolve a valid
max_connections value first, rerender with a new connectionId, then resolve an
invalid or non-array response and await the lookup state transition before
asserting only Backends is present. Replace the unmount-only assertion in the
aborted-request test with this rerender-and-resolution scenario, verifying the
stale valid response cannot add a reference series for the new connection.

In `@client/src/components/Dashboard/ServerDashboard/PostgresOverviewSection.tsx`:
- Around line 91-124: Update useMaxConnections to store the fetched
max-connections value together with the connectionId that produced it, and
return null whenever the stored ID differs from the current connectionId. Ensure
the effect updates both fields only for the active, non-aborted request, then
add a rerender test covering a connection change while the second lookup remains
pending.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9a4e49b5-a633-41cc-9075-98153855f745

📥 Commits

Reviewing files that changed from the base of the PR and between 19c645d and d195322.

📒 Files selected for processing (4)
  • .claude/react-expert/quality-checklist.md
  • client/src/components/Dashboard/ServerDashboard/PostgresOverviewSection.tsx
  • client/src/components/Dashboard/ServerDashboard/__tests__/PostgresOverviewSection.test.tsx
  • docs/changelog.md

Comment thread client/src/components/Dashboard/ServerDashboard/PostgresOverviewSection.tsx Outdated
Address review feedback on the connections chart. The hook kept the
previously fetched limit in state whilst a new lookup was in flight, so
switching connection could briefly draw one server's max_connections
line over another server's backend count. The result now carries the
connection it came from and is discarded when that no longer matches.

The reference-series tests settle deferred lookups by hand rather than
asserting against the initial pre-fetch render, so each case observes a
genuine transition, and the teardown tests assert that the request's
abort signal actually fires on unmount.
@dpage

dpage commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@dpage

dpage commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

Connections Over Time plots a gauge and a cumulative counter on one axis

1 participant