Kimi K3.1 Pro · Balanced
dual-storage-architecture-grafana-codex
Grafana · Go · L · 300–799 lines · 4 files
The normal review, with one generalist agent. Judge: Claude Haiku 5.5.
- Gold bugs found
- 7 of 9
- Comments published
- 9
- Comments matching a bug
- 7
- Comments not matching
- 2
- Cost of this PR
- $1.108
Published comments (9)
Mode3 dual-write tests silently exercise Mode1 instead — `InstallAPIs` resolves this desired value through `SetDualWritingMode`, which defaults a fresh key to Mode1 and only implements Mode1/Mode2 transitions, so these new cases silently exercise Mode1 and Mode3 cannot be enabled through this configuration. Add the Mode3 transition and assert the selected mode.
Async legacy writes inherit canceled request contexts — The timeout inherits the incoming HTTP request context, which is canceled when the handler returns, so the asynchronous legacy call can start with an already-canceled context and skip the safety write; delete, update, and delete-collection repeat this pattern. Build the timeout from `context.WithoutCancel(ctx)` so request values remain but request cancellation does not propagate.
Async legacy writes can reorder creates and updates, leaving stale state — Independent legacy goroutines allow sequential API operations to execute out of order, so an older update can finish after a newer one or an update can run before its create, leaving legacy stale or missing after all writes finish. Serialize legacy operations per object/key while keeping the unified write synchronous.
Legacy update recomputes the object instead of using the storage result — Passing the original `objInfo` makes legacy updaters such as playlist's call `UpdatedObject` a second time against legacy state instead of persisting the object produced by unified storage, allowing non-idempotent transforms and server-populated fields to diverge. Capture a deep copy of `res` and pass it through `updateWrapper` as the previous implementation did.
Unbounded legacy-write goroutines accumulate when the backend is slow — Every successful write creates an untracked goroutine with no concurrency bound, so a slow legacy backend lets completed requests accumulate goroutines and backend operations without applying backpressure. Replace per-request goroutines in all four write paths with a bounded worker queue.
Delete metrics use object names as kind labels, causing unbounded cardinality — Passing `name` as the `kind` label creates a persistent Prometheus histogram series per deleted object, causing unbounded cardinality and memory growth while preventing per-kind aggregation. Pass `options.Kind` instead.
Legacy delete-collection duration is misattributed to unified storage — Call `recordLegacyDuration` here.
Returning on every unified-storage error skips the legacy delete when unified storage returns… — This leaves stale legacy data that can reappear after a rollback; preserve the `NotFound` exception by scheduling `d.Legacy.Delete` and returning the original not-found error, while failing fast only for other errors.
Unified create failures are recorded in the legacy histogram — Call `recordStorageDuration` here. **Also found in:** - `pkg/apiserver/rest/dualwriter_mode3.go:129-129`