Amazon Ergo 1.0 · 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
7 of 11
Comments published
8
Comments matching a bug
7
Comments not matching
1
Cost of this PR
$1.685

Published comments (8)

highbugpkg/apiserver/rest/dualwriter_mode3.go:99-105

Delete now returns on every storage error, including NotFound — Returning immediately from `Delete` strands objects that exist only in legacy storage, so they may reappear when reads switch back. Preserve the `apierrors.IsNotFound` fallthrough to the legacy delete.

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

Mode-3 legacy writes inherit the request context and are canceled on return — The apiserver cancels `ctx` when the handler returns, so fire-and-forget legacy writes can abort early and silently lose the mode-3 backup. Use `context.WithoutCancel(ctx)` before `context.WithTimeoutCause` in all four legacy writes.

highbugpkg/apiserver/rest/dualwriter_mode3.go:134-140

Mode 3 legacy update bypasses the object written by Storage — Passing raw `objInfo` lets `Legacy.Update` re-run `UpdatedObject` against its own old object, so storage-assigned/defaulted fields or create-on-update behavior can diverge and break the backup. Restore `updateWrapper{upstream: objInfo, updated: res}`.

mediumperformancepkg/apiserver/rest/dualwriter_mode3.go:106

Storage duration metric uses object name as kind label — Unbounded Prometheus label cardinality can exhaust metric storage as object names vary, and the reported kind is wrong. Pass `options.Kind` instead of `name` to `recordStorageDuration`.

mediumbugpkg/tests/apis/playlist/playlist_test.go:132-143

Mode-3 dual-write tests actually run in mode 1 — These tests can pass without exercising this PR's mode-3 code because `SetDualWritingMode` only transitions between modes 1 and 2 and returns `Mode1` for a fresh store. Seed the mode-3 transition and assert the active mode in the test helper.

mediumbugpkg/apiserver/rest/dualwriter_mode3.go:166

Legacy DeleteCollection latency recorded via recordStorageDuration in mode 3 — Mode-3 legacy metrics misleadingly attribute backup latency and failures to unified storage, hiding legacy `DeleteCollection` problems. Call `recordLegacyDuration` instead of `recordStorageDuration` in that goroutine.

mediumbugpkg/apiserver/rest/dualwriter_mode3.go:45

Mode 3 Create and Update record storage errors as legacy — Failed unified-storage writes are reported as legacy errors and no storage duration is recorded, hiding storage failures in mode-3 metrics. Replace `recordLegacyDuration(true, ...)` with `recordStorageDuration` in both the `Create` and `Update` error paths.

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

Unbounded legacy-write goroutines can exhaust goroutines and connections — Legacy slowdowns can accumulate goroutines and concurrent database writes for up to 10 seconds, exhausting resources because the old synchronous path no longer applies backpressure. Bound `Create`, `Update`, `Delete`, and `DeleteCollection` with a worker queue or concurrency limit.

Gold bugs found (7)

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.
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.

Gold bugs missed (4)

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.