Commit 2a3fc24
authored
* feat(#91): metrics gear — source-aware, no-HAProxy mode (phases 0-2)
Lay the foundation for a source-agnostic Metrics gear by introducing
the MetricSource concept end-to-end. The page now declares which
collector produces each number ("HAProxy: Sessions & Requests",
"Host: CPU Load", …) and gracefully degrades on boxes without HAProxy.
Phase 0 — Capability manifest plumbing on the dashboard:
- New per-box CapabilitiesCache (5-min TTL, 3s fetch timeout, negative
caching) in the agent client package; tested with httptest.
- Handler-level BoxCapabilities accessor + cache instance; reconnect
events (server.connected) invalidate so a restarted agent's new probe
table is reflected immediately.
- New GET /api/{boxID}/capabilities endpoint surfaces the cached
manifest to the dashboard's auth-scoped frontend.
- filterGearsByAgentCapabilities (issue #71) refactored onto the cache —
removes one synchronous agent call per Gears-page render.
Phase 1 — Source attribution in the UI:
- Chart card titles carry source-prefix badges (HAProxy / Host) so the
reader can tell which collector produced the metric at a glance.
- KPI cards render a small source-badge in the upper-right corner;
server emits source+source_label on every card.
- "Error Insights" → "HAProxy Error Insights" with explicit copy.
Phase 2 — Graceful no-HAProxy mode:
- /api/{boxID}/metrics/summary checks the haproxy capability and only
emits HAProxy KPI cards when the gear is available; host KPIs (memory,
disk, load 1m) are always emitted from system_metrics_history.
- Frontend hides HAProxy-tagged chart cards and the Error Insights
panel when capabilities lack haproxy; shows an empty-state banner.
- Fail-open everywhere — flaky capabilities don't lock the user out.
CPU%, uptime, and failed-systemd KPIs aren't persisted yet; they'll
follow when the collector starts saving them.
Refs: docs/research/metrics-source-agnostic.md
* feat: add .local.config to .gitignore
* fix(#91): address Copilot review findings on PR #93
- api_capabilities.go: gate /api/{boxID}/capabilities on
ComponentMetrics + PermissionView. The manifest enumerates installed
services on the host, enough for fingerprinting in multi-tenant
deploys — a user without metrics:view shouldn't enumerate the
software inventory. Mirrors APIMetricsSummaryHandler's gate.
- history.templ: no-HAProxy banner now picks copy from the actual
capability entry — not_installed / inaccessible / disabled each get
distinct guidance, and the agent's `reason` is surfaced verbatim.
Previous copy ("Install HAProxy") pointed at the wrong fix when the
binary was present but stats unreachable.
- capabilities_cache.go: cache key is now (boxID, agentURL) so an
operator editing a box's Agent URL gets fresh capabilities on the
next render rather than stale data until the 5-min TTL expires.
Invalidate() drops every entry for the boxID regardless of URL.
- haproxy_config.go: invalidate the capabilities cache on box update
and delete so Agent URL / API key edits take effect immediately.
- api_metrics_insights.go: capability gating uses the sourceHAProxy
constant instead of a duplicate "haproxy" literal — prevents future
drift between KPI source IDs and capability lookups.
New tests:
- TestCapabilitiesCacheDifferentAgentURLBypassesCache — same boxID with
different agent URLs returns each agent's actual verdict, not stale.
- TestCapabilitiesCacheInvalidateDropsAllAgentURLsForBox — Invalidate
drops every entry for a boxID across all URLs it was fetched against.
1 parent 502bd46 commit 2a3fc24
12 files changed
Lines changed: 1040 additions & 52 deletions
File tree
- gearbox
- cmd/server
- internal/framework
- agent
- handler
- templates/pages
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
688 | 688 | | |
689 | 689 | | |
690 | 690 | | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
691 | 696 | | |
692 | 697 | | |
693 | 698 | | |
| |||
| 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 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
0 commit comments