-
Notifications
You must be signed in to change notification settings - Fork 2
obs(proxy): classify secondary write failures by reason #585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package proxy | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus/testutil" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestClassifySecondaryWriteError(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| err error | ||
| want string | ||
| }{ | ||
| {"nil error falls back to other", nil, "other"}, | ||
| {"plain write conflict", errors.New("write conflict on key foo"), "write_conflict"}, | ||
| { | ||
| "retry-limit message wins over embedded write-conflict substring", | ||
| errors.New("redis txn retry limit exceeded: write conflict"), | ||
| "retry_limit", | ||
| }, | ||
| {"not leader", errors.New("not leader"), "not_leader"}, | ||
| {"linearizable read not leader", errors.New("linearizable read: not leader"), "not_leader"}, | ||
| {"leader not found (ErrLeaderNotFound message)", errors.New("leader not found"), "not_leader"}, | ||
| {"context deadline exceeded via errors.Is", context.DeadlineExceeded, "deadline_exceeded"}, | ||
| {"wrapped deadline exceeded", fmt.Errorf("dispatch failed: %w", context.DeadlineExceeded), "deadline_exceeded"}, | ||
| {"deadline exceeded substring only", errors.New("rpc: deadline exceeded"), "deadline_exceeded"}, | ||
| {"txn already committed", errors.New("txn already committed"), "txn_already_finalized"}, | ||
| {"txn already aborted", errors.New("txn already aborted"), "txn_already_finalized"}, | ||
| {"txn locked", errors.New("key: foo: txn locked"), "txn_locked"}, | ||
| {"unknown", errors.New("some random failure"), "other"}, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| got := classifySecondaryWriteError(tc.err) | ||
| assert.Equal(t, tc.want, got) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestRecordSecondaryWriteFailureEmitsBothCounters(t *testing.T) { | ||
| metrics := newTestMetrics() | ||
| primary := newMockBackend("primary") | ||
| secondary := newMockBackend("secondary") | ||
| d := NewDualWriter( | ||
| primary, secondary, | ||
| ProxyConfig{Mode: ModeDualWrite, SecondaryTimeout: time.Second}, | ||
| metrics, newTestSentry(), testLogger, | ||
| ) | ||
|
|
||
| err := errors.New("write conflict on !txn|rb|foo") | ||
| d.recordSecondaryWriteFailure("SET", []any{"SET", "k", "v"}, 5*time.Millisecond, 1, false, err) | ||
|
|
||
| assert.InDelta(t, 1, testutil.ToFloat64(metrics.SecondaryWriteErrors), 0.001, | ||
| "unlabelled counter should still tick for dashboard backwards compatibility") | ||
| assert.InDelta(t, 1, testutil.ToFloat64( | ||
| metrics.SecondaryWriteErrorsByReason.WithLabelValues("SET", "write_conflict"), | ||
| ), 0.001, "labelled counter should record the write_conflict reason") | ||
|
|
||
| // Second failure: different reason + command should populate a distinct label pair. | ||
| d.recordSecondaryWriteFailure("EVALSHA", []any{"EVALSHA", "deadbeef"}, time.Millisecond, 3, false, | ||
| errors.New("redis txn retry limit exceeded: write conflict")) | ||
|
|
||
| assert.InDelta(t, 2, testutil.ToFloat64(metrics.SecondaryWriteErrors), 0.001) | ||
| assert.InDelta(t, 1, testutil.ToFloat64( | ||
| metrics.SecondaryWriteErrorsByReason.WithLabelValues("EVALSHA", "retry_limit"), | ||
| ), 0.001) | ||
| assert.InDelta(t, 1, testutil.ToFloat64( | ||
| metrics.SecondaryWriteErrorsByReason.WithLabelValues("SET", "write_conflict"), | ||
| ), 0.001, "previous label pair should be unchanged") | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: bootjp/elastickv
Length of output: 10524
Fix classifier to handle additional error types and prevent misclassification.
The substring matching approach for error classification has gaps:
"leader not found"containsadapter/internal.go:40'sErrLeaderNotFoundmessage, but the classifier checks only for"not leader"(line 513). This causes leadership-related failures to be misclassified as"other"despite being distinct from transient write conflicts.Several transient error types fall to
"other"and won't be visible on dashboards:ErrTxnLocked("txn locked") — common OCC contention signalErrTxnCommitTSRequired,ErrTxnMetaMissing,ErrTxnInvalidMeta,ErrTxnTimestampOverflow— metadata/timestamp issuesThe
nilbranch (line 502–503) is unreachable fromrecordSecondaryWriteFailurebut safe to keep defensively.Consider adding checks for the above error strings or extending the existing
"not leader"check to match"leader not found".🤖 Prompt for AI Agents