Commit e09943a
feat(agent): Resources field on ProbeResult + access-log log_sources (#135)
* feat(agent): Resources field on ProbeResult + access-log log_sources (#112)
The dashboard's capability-driven UI has been inferring resource lists
(log sources, services, metric sources) from gear-availability flags.
That works for binary "is this gear present?" decisions but breaks
down for "what concrete sources does this gear expose?" — the Logs
page's hardcoded [haproxy, system] fallback was the worst offender.
Phase 2 of issue #112 introduces a structured Resources field the
agent populates per-gear, the dashboard consumes by name.
Agent changes:
- ProbeResult gains `Resources map[string]any`, serialized as the
`resources` JSON object on CapabilityEntry. Omitted when empty so
older dashboards see the unchanged wire shape.
- New gear.ProbeAvailableWithResources(reason, capabilities, resources)
constructor for gears that want to publish typed resource lists;
gears that don't need this keep using ProbeAvailable.
- access-log gear now publishes `log_sources` — a slice of
{name, display_name, path} for every readable web-server access
log it discovers (haproxy / nginx / apache / caddy). The flat
`<src>_log` keys in Capabilities stay for backward compat with
pre-Phase-2 dashboards.
Tests:
- TestProbePopulatesLogSourcesResource on the access-log gear asserts
the structured shape, name → display_name mapping, and absence of
entries for non-readable paths.
- TestCapabilitiesEndpointSurfacesResources on the manager asserts
Resources round-trips through the JSON envelope at
/api/v1/system/capabilities — decoded via map[string]any so we
catch any field-name regression on the wire.
Dashboard-side consumer lands in a follow-up PR (sibling to this one).
Phase 2 of #112.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(agent): address Copilot review on Phase 2 Resources (#112)
Four review findings, all addressed:
1. Probe was mutating g.paths despite the ProbeableGear contract
that Probe must be side-effect-free. Refactor: extract
pathsFromDeps as a shared deps→map helper, add
resolveLogPathWith(src, overrides) so Probe operates on a local
override map. Initialize is now the single place g.paths gets
written.
2. Resources was always populated with a "log_sources" key even when
no readable log files were found, so the JSON envelope's
`omitempty` tag never fired and the wire format gained a
permanent (empty-slice) field. Only attach Resources when
log_sources actually has entries.
3. Manager.ProbeResults returned a shallow copy — callers could
mutate nested Capabilities/Resources maps and race against
manager state under load. Added cloneProbeResult that
duplicates Capabilities as a fresh map and JSON-round-trips
Resources (so nested slices and sub-maps come back as fresh
allocations). JSON round-trip is the same cost the capabilities
endpoint encoder pays anyway, and falls back to a shallow
Resources copy if marshaling fails.
4. Test comment claimed "decode through json.RawMessage" but the
test actually decoded straight into map[string]any. Switch the
test to a two-stage decode: first peel the outer envelope into
json.RawMessage per gear (catches field-name regressions in the
wire format), then decode the resources object into a typed
shape and assert on payload contents. Avoids Go's `any`
decoding quirks in the wire-format guard.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 79d3a3e commit e09943a
5 files changed
Lines changed: 323 additions & 26 deletions
File tree
- gearbox-agent/internal
- framework/gear
- gears/accesslog
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
| 249 | + | |
| 250 | + | |
250 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
251 | 273 | | |
252 | 274 | | |
253 | 275 | | |
| |||
261 | 283 | | |
262 | 284 | | |
263 | 285 | | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
264 | 300 | | |
265 | 301 | | |
266 | 302 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
151 | 159 | | |
152 | 160 | | |
153 | 161 | | |
154 | 162 | | |
155 | 163 | | |
156 | | - | |
| 164 | + | |
157 | 165 | | |
158 | 166 | | |
159 | 167 | | |
160 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
161 | 225 | | |
162 | 226 | | |
163 | 227 | | |
| |||
508 | 572 | | |
509 | 573 | | |
510 | 574 | | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
511 | 583 | | |
512 | 584 | | |
513 | 585 | | |
| |||
Lines changed: 85 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
297 | 297 | | |
298 | 298 | | |
299 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
300 | 385 | | |
301 | 386 | | |
302 | 387 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
142 | 155 | | |
143 | 156 | | |
144 | 157 | | |
145 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
146 | 174 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 175 | + | |
153 | 176 | | |
154 | 177 | | |
| 178 | + | |
155 | 179 | | |
156 | | - | |
157 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
158 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
159 | 199 | | |
160 | 200 | | |
161 | 201 | | |
162 | 202 | | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
173 | 209 | | |
174 | 210 | | |
175 | 211 | | |
176 | 212 | | |
177 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
178 | 225 | | |
179 | 226 | | |
180 | 227 | | |
| |||
285 | 332 | | |
286 | 333 | | |
287 | 334 | | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
292 | 340 | | |
293 | | - | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
294 | 356 | | |
295 | 357 | | |
296 | 358 | | |
| |||
0 commit comments