perf(stats): draw the Statistics charts from the page's own metrics scan - #275
Merged
Merged
Conversation
The page read idx_query_logs_ts_metrics for its breakdowns, then the browser fetched the timeline (the same index again) and the heatmap (idx_query_logs_timestamp). stats_scan_since now reads the metrics index once and also returns per-quarter-hour counts on UTC boundaries, which the page embeds and app.js folds into the viewer's calendar. The fold is exact because every UTC offset in use is a whole number of quarter hours. On a 370k-row database, a whole-table visit drops from 13 298 to 9 758 page misses. The API's timeline and heatmap endpoints are unchanged; a new e2e spec checks the browser folds against them across ranges and offsets. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #275 +/- ##
==========================================
+ Coverage 91.18% 91.26% +0.07%
==========================================
Files 31 31
Lines 11224 11329 +105
==========================================
+ Hits 10235 10339 +104
- Misses 989 990 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A visit to the Statistics page scanned
idx_query_logs_ts_metricstwice andidx_query_logs_timestamponce. The server scanned the metrics index for the breakdowns. After the page loaded, the browser fetched the timeline, which scanned the same index again, and the heatmap, which scanned the timestamp index.Database::stats_scan_sincereads the metrics index once, starting at the earlier of the range window and the 30-day heatmap window. It returns the window readings plus aQuarterSeries: query counts per UTC quarter hour, with a separate boundary for each window.<stats-page data-series data-bucket-secs>.app.js(timelineFromQuarters/heatmapFromQuarters) folds it into the viewer's calendar, so the page no longer requests its charts. The fold is exact because every UTC offset in use is a whole number of quarter hours.response_msapproaches one group per row, which would mean a temp b-tree as large as the window./api/stats/v2/timelineand/api/stats/v2/heatmapare unchanged for API callers.Page misses
stats_page_miss_benchagainst a copy of a real 370k-row database (7-day data, default retention):Before this change, a visit cost breakdowns + top_domains + top_clients + db_health + timeline + heatmap = 13 298 pages. It now costs 9 758 (−27%). 90d reads the same as 30d because both cover the whole table. 7d goes from 12 430 to 9 300.
Tests
stats_db_test: the scan returns the same window readings aswindow_metrics_since. Folding its series reproducestimeline_multi_sinceandhourly_heatmap_sincefor eight offsets, including +5:30, +5:45 and −9:30, across all three bucket widths. Each window keeps its own boundary to the millisecond.stats_page_miss_test: the page's scan costs no more than the window readings alone, and less than half of the three statements it replaces.admin_api_test: the rendered page carries the series and the bucket width.stats_charts.rs: runs the JavaScript folds in a real browser and compares them against the API for every range and all eight offsets.The UI looks the same, so screenshots were not regenerated.
🤖 Generated with Claude Code