DeepSeek V4 Pro · Balanced

dual-storage-architecture-grafana-codex

Grafana · Go · L · 300–799 lines · 4 files

The normal review, with one generalist agent. Judge: Claude Opus 5.5.

Gold bugs found
6 of 11
Comments published
7
Comments matching a bug
6
Comments not matching
1
Cost of this PR
$0.495

Published comments (7)

mediumbugpkg/apiserver/rest/dualwriter_mode3.go:139

Legacy update uses raw objInfo instead of storage result, diverging writes — The legacy store re-runs objInfo.UpdatedObject against its own possibly stale or absent old object, so the legacy write diverges from unified storage with a different resourceVersion/UID or a create instead of an update. Wrap the storage result with `updateWrapper{upstream: objInfo, updated: res}` so both stores persist the same object.

mediumbugpkg/apiserver/rest/dualwriter_mode3.go:50-57

Async legacy write uses request-scoped context canceled after handler returns — The apiserver cancels the request-scoped ctx as soon as the handler returns, so the goroutine observes `context.Canceled` and the legacy backup is silently dropped. Derive the goroutine context from `context.WithoutCancel(ctx)` so the timeout-only context survives request completion; the same applies in `Delete`, `Update`, and `DeleteCollection`.

mediumbugpkg/apiserver/rest/dualwriter_mode3.go:45

Create error path records legacy duration metric — Recording the storage failure in the legacy histogram pollutes `dual_writer_legacy_duration_seconds` and also uses the wrong `startStorage` timestamp. Use `recordStorageDuration` here, and make the same correction in `Update`.

mediumbugpkg/apiserver/rest/dualwriter_mode3.go:166

DeleteCollection records legacy duration in storage histogram — `startLegacy` belongs to the legacy histogram, so this call miscounts it as a storage operation. Use `recordLegacyDuration` so delete-collection timing lands in `dual_writer_legacy_duration_seconds`.

mediumperformancepkg/apiserver/rest/dualwriter_mode3.go:106

Delete records storage duration metric with object name as kind label — Using `name` as the `kind` label creates an unbounded number of Prometheus series, one per object name. Pass `options.Kind` so metric cardinality stays bounded.

mediumbugpkg/apiserver/rest/dualwriter_mode3.go:100-104

Delete returns early on Storage NotFound and leaves stale legacy copies — Skipping `d.Legacy.Delete` on NotFound leaves stale legacy copies that can resurface if reads fall back to legacy storage. Only short-circuit non-NotFound errors so legacy cleanup still runs when storage reports NotFound.

mediumbugpkg/apiserver/rest/dualwriter_mode3.go:96-97

Delete sets context logger to d.Log instead of log — Passing the bare `d.Log` loses the name/kind/method fields for `klog.FromContext` calls inside `d.Storage.Delete`. Pass the just-built `log` to `klog.NewContext` like every other mode-3 method.

Gold bugs found (6)

mediumThe legacy DeleteCollection goroutine records its duration with recordStorageDuration instead of recordLegacyDuration, misattributing legacy latency and errors to the storage metric.
mediumDelete's success path records the storage metric with the object name in the kind label instead of options.Kind, creating per-object series and inconsistent labels.
mediumOn storage Create/Update failure the duration is recorded with recordLegacyDuration, attributing unified-store errors to the legacy metric.
highMode 3 legacy writes now run in background goroutines derived from the request context, which is cancelled when the request completes, so legacy writes can be cancelled and legacy storage falls out of sync.
highLegacy.Update now receives the original objInfo instead of a wrapper carrying the object stored in unified storage, so legacy recomputes the update and can diverge.
highDualWriterMode3.Delete now returns on any unified-storage error, including NotFound, before deleting from legacy, so objects that exist only in legacy can no longer be deleted.

Gold bugs missed (5)

mediumThe Mode 3 tests never wait for or assert the asynchronous legacy writes, and legacy and storage share one mock, so removing the legacy calls would not fail them.
highIndependent per-request goroutines remove ordering between legacy writes to the same resource, so legacy can end up with an older version or a resurrected object.
mediumMode 3 legacy-storage write errors (create/update/delete/delete-collection) are no longer logged after moving to async goroutines; only a duration metric with an error flag is recorded.
mediumTestMode3_Get and TestMode3_List share one mock.Mock between the legacy and storage mocks with identical method names, so they would still pass if Mode 3 read from LegacyStorage instead of Storage.
mediumThe new Mode 3 playlist integration subtests set DualWriterDesiredModes to Mode3, but SetDualWritingMode defaults a fresh key to Mode1 and only handles Mode1<->Mode2 transitions, so the subtests silently run in Mode1 and Mode3 cannot be enabled through configuration.