Commit 669318f
authored
refactor: rename Metrics gear URL /history → /metrics + themed 404 (#97)
* refactor: rename Metrics gear URL /history → /metrics; clarify the term
The Metrics gear was historically called "history" because the page
shows time-series data. That name leaked into the URL (/history), the
API endpoints (/api/{boxID}/history/*), the templ file
(history.templ), the handler functions (HistoryPage,
APIStatsHistoryHandler, …), and assorted comments / docs / README
entries. With nginx / Apache / Caddy / Traefik detection now landing
(issue #95) and "metric source" / "primary source" terminology in the
new code, the dual naming has become genuinely confusing.
This commit renames the metrics-gear identity end-to-end:
- Page route: /history → /metrics (plugin.go SidebarItem.Path,
base.templ path-prefix match + sidebar links, gears-page.js).
- API routes:
/api/{boxID}/history/stats → /api/{boxID}/metrics/stats
/api/{boxID}/history/metrics → /api/{boxID}/metrics/system
/api/{boxID}/history/backend/{name} → /api/{boxID}/metrics/backend/{name}
(Last one coexists with /metrics/backend/{name}/details — the
time-series endpoint vs the drill-down details endpoint added in #87.)
- Handler functions:
HistoryPage → MetricsPage
APIStatsHistoryHandler → APIMetricsStatsHandler
APIBackendHistoryHandler → APIMetricsBackendHandler
APISystemMetricsHistoryHandler → APIMetricsSystemHandler
- File: pages/history.templ → pages/metrics.templ
(templ component History() → Metrics())
- JS callers: history.templ + details.templ + chart_partials.templ
(8 fetch() URLs updated).
- Docs: metrics gear README routes table + architecture diagram +
development snippet; cmd/server/main.go route-group comment;
pages.go migration-history comment; permissions.go field comment;
docs/gears.md gear list.
Intentionally **kept** as legitimate "history" concepts (per design
discussion):
- DB tables stats_history, system_metrics_history, backend_history —
the rows ARE historical records. Renaming requires a migration with
no user-visible benefit; the names accurately describe what they
contain. The DB query methods that read them (GetStatsHistory,
GetBackendHistory, GetSystemMetricsHistory) keep their names for
the same reason.
- Snapshot interval / retention config: HistoryIntervalSeconds,
store_history, history_retention_days — these control how the
historical record is kept. Same reasoning.
- Local `history` variable names inside the renamed handler functions
— they reflect what the DB methods return.
- OS-update apt/zypper/dnf/pacman history — distinct concept.
/api/v1/system/updates/history on the agent, /os-updates/history on
the dashboard, parseAptHistoryLog, /var/log/apt/history.log, etc.
All untouched.
- HAProxy config change history — distinct concept.
/{boxID}/haproxy/config/history,
templates/pages/haproxy_config/change_history.templ, etc. Untouched.
Agent module: no changes. The agent's "history" references are all
OS-update package-manager history (apt/zypper/dnf/pacman/apk/yum),
which is the legitimate concept.
Tests + build green on both modules.
* feat: themed static 404 page for unmatched routes
Wires chi's NotFound to a self-contained handler so a typo'd URL (or a
bookmark to the now-renamed /history) lands on a small Gearbox-themed
page instead of the browser's default 404. Particularly relevant after
the /history → /metrics rename in this PR — anyone with a bookmark to
the old URL will hit this.
Security posture: the handler is deliberately static end-to-end.
- No templ rendering, no auth middleware, no DB / agent lookups.
- HTML is a Go const so there's no filesystem or template lookup at
request time.
- Inline CSS only (no <link> tags) so the response works even if the
static-asset bundle didn't load.
- No request data echoed into the response (test enforces this) —
guards against the page becoming a reflection vector.
- `Cache-Control: no-store` so a 404 doesn't outlive a deploy that
later adds the missing route.
Tests:
- TestNotFoundHandlerStatusAndBody: 404 status, HTML body, Cache-
Control, expected copy.
- TestNotFoundHandlerDoesNotEchoRequestData: URL/header/cookie probes
don't appear in the response body — handler is fully static.
- TestNotFoundHandlerStableAcrossMethods: GET/POST/PUT/DELETE/PATCH
all return the same 404 page.
Visual: matches the dashboard's blue accent (#2563eb), uses system
fonts (no external font loading), `prefers-color-scheme`-aware so it
renders in dark mode without JS.
* docs: fix grammar in metrics README (Copilot review nit)1 parent 5819f15 commit 669318f
15 files changed
Lines changed: 275 additions & 70 deletions
File tree
- docs
- gearbox
- cmd/server
- internal
- framework
- handler
- models
- templates
- layouts
- pages
- gears/metrics
- static/js/gears
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
| 141 | + | |
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
452 | 452 | | |
453 | 453 | | |
454 | 454 | | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
455 | 461 | | |
456 | 462 | | |
457 | 463 | | |
| |||
627 | 633 | | |
628 | 634 | | |
629 | 635 | | |
630 | | - | |
| 636 | + | |
631 | 637 | | |
632 | 638 | | |
633 | 639 | | |
| |||
676 | 682 | | |
677 | 683 | | |
678 | 684 | | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | | - | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
683 | 692 | | |
684 | 693 | | |
685 | 694 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
106 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
107 | 111 | | |
108 | 112 | | |
109 | 113 | | |
| |||
142 | 146 | | |
143 | 147 | | |
144 | 148 | | |
145 | | - | |
146 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
147 | 155 | | |
148 | 156 | | |
149 | 157 | | |
| |||
191 | 199 | | |
192 | 200 | | |
193 | 201 | | |
194 | | - | |
195 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
196 | 206 | | |
197 | 207 | | |
198 | 208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
338 | | - | |
| 338 | + | |
339 | 339 | | |
340 | 340 | | |
341 | 341 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
2175 | 2175 | | |
2176 | 2176 | | |
2177 | 2177 | | |
2178 | | - | |
| 2178 | + | |
2179 | 2179 | | |
2180 | 2180 | | |
2181 | 2181 | | |
| |||
2287 | 2287 | | |
2288 | 2288 | | |
2289 | 2289 | | |
2290 | | - | |
| 2290 | + | |
2291 | 2291 | | |
2292 | 2292 | | |
2293 | 2293 | | |
| |||
2332 | 2332 | | |
2333 | 2333 | | |
2334 | 2334 | | |
2335 | | - | |
| 2335 | + | |
2336 | 2336 | | |
2337 | 2337 | | |
2338 | 2338 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
714 | 714 | | |
715 | 715 | | |
716 | 716 | | |
717 | | - | |
| 717 | + | |
718 | 718 | | |
719 | 719 | | |
720 | 720 | | |
| |||
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
| 7 | + | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
843 | 843 | | |
844 | 844 | | |
845 | 845 | | |
846 | | - | |
847 | | - | |
| 846 | + | |
| 847 | + | |
848 | 848 | | |
849 | 849 | | |
850 | | - | |
851 | | - | |
| 850 | + | |
| 851 | + | |
852 | 852 | | |
853 | 853 | | |
854 | 854 | | |
| |||
0 commit comments