[1/2] chipingress: expose drop failure classification for partial delivery metrics#2210
[1/2] chipingress: expose drop failure classification for partial delivery metrics#2210pkcll wants to merge 1 commit into
Conversation
📊 API Diff Results
|
59011ac to
d16297c
Compare
✅ API Diff Results -
|
f74f0a3 to
6d7cc16
Compare
6d7cc16 to
5b8513f
Compare
There was a problem hiding this comment.
Pull request overview
Adds shared error classification utilities to pkg/chipingress/batch so downstream components (e.g., beholder in the follow-up PR) can emit consistent partial-delivery / send/queue failure metrics and logs.
Changes:
- Introduces
DropFailureandClassifyDropFailure(err)to map batch send/queue errors into{error_type, error_code, error_reason}. - Adds unit tests covering common gRPC statuses, partial-delivery
PublishError, and local queue conditions. - Exports
ErrMessageBufferFull/ErrClientShutdownsentinels and updatesQueueMessageto return them for reliableerrors.Ismatching.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/chipingress/batch/drop_failure.go | Adds the DropFailure model + ClassifyDropFailure helper used for metric/log dimensions. |
| pkg/chipingress/batch/drop_failure_test.go | Adds coverage for error classification across partial delivery, gRPC, and local queue errors. |
| pkg/chipingress/batch/client.go | Exports sentinel errors and returns them from QueueMessage to enable stable classification. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return DropFailure{ | ||
| ErrorType: ErrorTypeRPCError, | ||
| ErrorCode: codes.Unknown.String(), | ||
| ErrorReason: err.Error(), | ||
| } |
| { | ||
| name: "unknown error", | ||
| err: errors.New("something else"), | ||
| wantType: batch.ErrorTypeRPCError, | ||
| wantCode: codes.Unknown.String(), | ||
| wantReason: "something else", | ||
| }, |
| ErrorType string // partial_delivery | rpc_error | buffer_full | client_error | ||
| ErrorCode string // PUBLISH_ERROR_CODE_* or gRPC code name (DeadlineExceeded, …) | ||
| ErrorReason string // server reason, status message, or client error text | ||
| } |
There was a problem hiding this comment.
It seems that you don't really need a separate type DropFailure here.
In #2266, you can:
- use
sendErr.Error()instead ofdrop.ErrorReason, - use only ErrorCode instead of ErrorType (one can infer one from another)
- In this PR (or you can drop it and update beholder: handle partial-delivery errors via metric and log suppression #2266 directly)have one method generating
ErrorCodewith separate if's based onerrors.AsType.
65f2ba8 to
e8d7286
Compare
| if errors.Is(err, ErrMessageBufferFull) { | ||
| return ErrMessageBufferFull.Error() | ||
| } | ||
| if errors.Is(err, ErrClientShutdown) { | ||
| return ErrClientShutdown.Error() | ||
| } |
| // ErrorCodeFor returns a bounded error code string for a batch send/queue error. | ||
| // The returned code is intended for metric dimensions; callers can infer the | ||
| // error category from the code: | ||
| // - PUBLISH_ERROR_CODE_* -> partial_delivery | ||
| // - "buffer_full" -> buffer_full |
| { | ||
| name: "buffer full", | ||
| err: batch.ErrMessageBufferFull, | ||
| want: batch.ErrMessageBufferFull.Error(), | ||
| }, |
| { | ||
| name: "client shutdown", | ||
| err: batch.ErrClientShutdown, | ||
| want: batch.ErrClientShutdown.Error(), | ||
| }, |
| var ( | ||
| ErrMessageBufferFull = errors.New("message buffer is full") | ||
| ErrClientShutdown = errors.New("client is shutdown") | ||
| ) |
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| t.Parallel() | ||
| assert.Equal(t, tt.want, batch.ErrorCodeFor(tt.err)) | ||
| }) | ||
| } |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (4)
pkg/chipingress/batch/drop_failure.go:40
ErrorCodeForcurrently returns the full sentinel error messages for buffer-full and shutdown ("message buffer is full" / "client is shutdown"), but the function comment describes stable metric codes ("buffer_full" / "client_shutdown"). Returning the human-readable strings couples metric dimensions to error wording and doesn't match the documented values.
if errors.Is(err, ErrMessageBufferFull) {
return ErrMessageBufferFull.Error()
}
if errors.Is(err, ErrClientShutdown) {
return ErrClientShutdown.Error()
pkg/chipingress/batch/drop_failure_test.go:54
- Test expects
ErrorCodeForto return the sentinel error string for buffer-full, but the helper's doc (and intended metric code) is"buffer_full". Align the test expectation with the stable code value.
name: "buffer full",
err: batch.ErrMessageBufferFull,
want: batch.ErrMessageBufferFull.Error(),
},
pkg/chipingress/batch/drop_failure_test.go:59
- Test expects
ErrorCodeForto return the sentinel error string for shutdown, but the helper's doc (and intended metric code) is"client_shutdown". Align the test expectation with the stable code value.
name: "client shutdown",
err: batch.ErrClientShutdown,
want: batch.ErrClientShutdown.Error(),
},
pkg/chipingress/batch/drop_failure.go:53
- PR description mentions adding
batch.ClassifyDropFailureto provide shared metric dimensions (error_type,error_code,error_reason), but this file currently only exposesErrorCodeFor. Consider adding the promised helper so downstream callers (e.g. beholder) can consistently derive all dimensions without re-implementing logic.
return ErrorTypeClientError
}
| func TestErrorCodeFor_nil(t *testing.T) { | ||
| t.Parallel() | ||
| require.Empty(t, batch.ErrorCodeFor(nil)) | ||
| } |
57bb513 to
8cd89c4
Compare
|
Folding this into #2266 — moved drop_failure.go there and simplified ErrorCodeFor to return (errorType, errorCode) directly, so there's no cross-PR dependency to coordinate. |
Part 1 of 2 — adds the chipingress batch client helpers needed for the beholder partial-delivery metric change.
ErrMessageBufferFullandErrClientShutdownsentinels frompkg/chipingress/batch.batch.ClassifyDropFailureto map send/queue errors into shared metric dimensions (error_type,error_code,error_reason).Part 2: #2266
Jira: INFOPLAT-13901