Add an Active Session History tab to Database Diagnostics
What does this MR do and why?
Uses the endpoints from MR 262489, which is merged.
This is the first screen of the Active Session History (ASH) web UI from work item 608101. It adds an Active session history tab to Admin > Monitoring > Database diagnostics, next to a new Checks tab that holds the existing checks. Admins can look back at what the main database waited on at the time of a slowdown, and which queries caused the load, instead of trying to reproduce it.
- Time range: the last 1, 4, 12 or 24 hours, or a custom start and end date and time. A range can be up to 24 hours long and start up to 30 days ago.
- Wait event types: the share of load and the average and peak active sessions for each wait event type.
- Top queries: the queries that caused the most load across all wait event types.
- States: pg_ash not installed or an unsupported version, sampling off, no samples, and errors with Retry. When admin mode is inactive, the tab says so instead, because Retry cannot help until the admin re-authenticates. The tab has an Experiment badge.
- Docs: a "View active session history" section on the performance monitoring page.
The tab loads when it is opened and whenever the time range changes. It renders only while it is open, so opening Database diagnostics still runs no pg_ash reads, and leaving the tab resets it to the last hour.
Decisions
- Its own tab, not a section at the end of the checks.
- The page is a growing list of checks, and ASH is a different kind of tool: you investigate a time range rather than run a check.
- Tabs keep the existing menu item, docs path and permission. Pajamas tabs show "one content section at a time from a larger set of related content", and the active tab is kept in the URL (
?tab=active-session-history). - A separate Monitoring page is the alternative. It would need a new menu item, route and view.
- Layout. The time range is at the top, and the two tables are tabs, like the admin GitLab Credits dashboard. Boxes are kept to a minimum.
- These tables are tabs inside the page tabs. Pajamas allows nesting tabs two levels deep, but calls it "a last resort". A segmented control above one table is the alternative. UX input welcome.
- No Load button. Opening the tab is now the explicit step, so it loads right away, and a failed load offers Retry. To refresh a preset, reload the page; the tab is kept in the URL.
- Follows existing components. Pajamas tables that stack on narrow screens, and controller JSON with axios, like the other sections. No custom CSS.
- The time range is a
GlCollapsibleListboxin a labelled form group, as on usage quotas and CI/CD analytics. Custom ranges use the date and time picker from the observability pages. - That picker now passes translated From and To labels and names its time inputs, so screen readers announce them. This also applies on the tracing, logs and metrics pages.
- The time range is a
- The page shows the period pg_ash read. The endpoints end a range at the newest summarized minute, and widen ranges under 61 minutes, so the "Time range" line can differ from what was picked.
- Query text shows on one line, with Show full query and a copy button.
- Only short queries also get a tooltip, because a long one covers the table.
- Every query has the button, because the tooltip can't be reached with the keyboard.
GlTruncateTextisn't used, because it raised ResizeObserver errors in this table.
- No feature flag. The tab is admin-only, and there's nothing to show until pg_ash is installed and sampling is turned on. Sampling is off by default.
- Shown to every instance admin, on every offering. pg_ash targets Self-Managed, but nothing stops Dedicated or GitLab.com admins from installing and using it (608101). GitLab.com staging runs it to check stability first (production#23277). Users who aren't instance admins get a 404.
Follow-ups
- A database load chart, with the queries behind each wait event type for any 5 minutes of it (MR 262859, stacked on this one).
- Queries behind a wait event type over a longer window, after GitLab vendors pg_ash 2.0-rc1 or later, which makes that read much faster.
- An Experiment badge and the testing agreement on the Active session history settings (MR 264625).
- Deleting the samples when the sample interval changes, instead of the docs note that earlier numbers change by the same ratio (MR 264876).
References
- Work item: #608101
- Epic: gitlab-org#23091
- Endpoints MR (merged): !262489 (merged)
- Direction for the UI: #608101 (comment 4015339031)
- Earlier proof of concept (closed): !246701 (closed)
Screenshots or screen recordings
Local GDK with a synthetic incident: lock queues, CPU-heavy queries and pg_sleep sessions. For the not-installed, unsupported-version and sampling-off states, the response was changed in the browser.
| Before | After |
|---|---|
![]() |
![]() |
| State | Screenshot |
|---|---|
| Top queries | ![]() |
| Custom time range | ![]() |
| Custom time range over 24 hours | ![]() |
| pg_ash not installed | ![]() |
| Unsupported pg_ash version | ![]() |
| Sampling off | ![]() |
| Narrow screen | ![]() |
How to set up and validate locally
-
Check out this branch.
-
Install pg_ash:
bundle exec rake gitlab:db:pg_ash:install -
Go to Admin > Settings > Metrics and profiling > Active session history, select Turn on session sampling, and select Save changes.
-
Optional. To see query IDs and text, load
pg_stat_statements:- In
gdk psql, runALTER SYSTEM SET shared_preload_libraries = 'pg_stat_statements';. - Run
gdk restart postgresql. - In
gdk psql, runCREATE EXTENSION IF NOT EXISTS pg_stat_statements;.
- In
-
Make the database wait on a lock for two minutes:
- In one
gdk psqlsession, runSELECT pg_advisory_xact_lock(1), pg_sleep(120);. - In two or three other sessions, run
SELECT pg_advisory_xact_lock(1);.
- In one
-
Wait two minutes so the minute rollups catch up.
-
Go to Admin > Monitoring > Database diagnostics. Check that the Checks tab makes no
active_session_historyrequests. -
Select the Active session history tab. It loads the last hour. The lock queue shows as the
Lockwait event type, and the sleeping session asTimeout. -
From the Time range dropdown list, select Custom, and choose a start and end around the lock queue. The tab loads it once both are set.
-
Optional. To see the sampling-off state, turn off Turn on session sampling and open the tab again.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.








