A tracingAPI decorator wraps the 17-method libvirt seam and logs one "libvirt call" line per RPC after it returns: method, the identifiers it was given, curated results, duration, and on failure the error with its libvirt code, name and message. At V(2) the same line carries the domain and volume XML, metadata and addresses; upload bodies are never logged. The pool applies it in call() when V(1) is enabled and logs connect, dial-failure and drop events, taking the caller's logger explicitly like every other helper in the package. The integration test installs a testr logger at KVM_TEST_LOG_LEVEL (default 1) so the trace interleaves with t.Log output, which also ends the "log.SetLogger(...) was never called" warning. Docs gained a Logging section and the test env var; the KVM provider execution log records run 4 (guest hang at GRUB) that prompted this. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2.8 KiB
2.8 KiB
Execution: Trace every libvirt call in the KVM provider
Plan: 2026-09-10-0805-kvm-libvirt-tracing.md
- Step 0 — Save plan
- Step 1 —
errors.go: shared error fields - Step 2 —
trace.go: thetracingAPIdecorator - Step 3 —
conn.go: pool logging and wrapping - Step 4 — Call sites
- Step 5 — Integration test output
- Step 6 — Unit tests
- Step 7 — Docs, execution log, CHANGELOG (docs and this log done; CHANGELOG waits for the live run)
Steps 1–6 — Tracer, pool logging, tests, integration wiring
Done as one commit on feat/kvm-provider; the plan's assumption that
this belongs on the KVM branch rather than its own feature branch was
accepted at plan approval.
The code follows the plan closely. Things that came out differently or are worth knowing:
- Logger names join with
/in funcr,.in zap. The trace lines arekvm/libvirtin the unit-test capture and intestroutput, andkvm.libvirtunder the operator's zap logger. The docs use the zap spelling; the unit test asserts the funcr one. First run of the tier test failed on exactly this. - Cancel is not reported as a transport error. The original
calldropped the connection twice on cancellation (once from the abort closure, once from the "not a libvirt error" branch, harmlessly, since drop is idempotent). With a log line on each drop that would have printed bothcontext cancelledandtransport errorfor one event, so the transport branch now skipsctx.Err(). Covered byTestHostPool_call_logsDropReason. ConnectListAllDomainsin the fake includes every defined domain, so the trace test's fixture (one running managed domain plus one stopped domain forDomainCreateto start) lists two; the V(2) assertion checks for thenameskey rather than an exact list.libvirtErrorFieldsalso feedslogAPIError, which therefore gainslibvirtCodeName(e.g.ErrNoDomain) next to the numeric code.- The seam-coverage guard (
reflectcount oflibvirtAPImethods vs the test table) is the only thing standing between a future 18th RPC and a silently untraced call; keep it.
Verification run before committing:
go build ./... && go vet ./... && go vet -tags=integration ./internal/provider/kvm/
go test -short ./...
go test -race -count=1 -cover ./internal/provider/kvm/ # 90.2 %, up from 88.2
go test -tags=integration -count=1 -run TestKVM ./internal/provider/kvm/ # self-skips without env
Worth noting: the live run (make test-integration-kvm against beelink)
had not happened when this was written; it is what Step 7 of the KVM
provider plan is waiting on, and its output is the acceptance test for
this feature. Expected shape is in the plan's Verification section.