-
Notifications
You must be signed in to change notification settings - Fork 78
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
Fix gRPC error handling for gateway/filter handler #2669
Conversation
📝 Walkthrough📝 WalkthroughWalkthroughThe changes primarily focus on enhancing error handling and logging within the gRPC server methods of the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🧰 Additional context used🪛 GitHub Check: codecov/patch
🔇 Additional comments (7)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
[CHATOPS:HELP] ChatOps commands.
|
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.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- pkg/gateway/filter/handler/grpc/handler.go (5 hunks)
🔇 Additional comments (4)
pkg/gateway/filter/handler/grpc/handler.go (4)
1537-1543
: Refactor duplicated error handling inSearchByID
The error handling code in lines 1537-1543 duplicates logic found in other methods. Use the proposed helper function
parseErrorAndRecordSpan
to reduce code duplication and enhance maintainability.
2205-2211
: Refactor duplicated error handling inStreamLinearSearchByID
Similar to previous instances, the error handling code in lines 2205-2211 can be refactored using the
parseErrorAndRecordSpan
helper function to adhere to the DRY principle.
3067-3073
: Refactor duplicated error handling inStreamUpsert
The error handling code in lines 3067-3073 is repeated from earlier code segments. Applying the
parseErrorAndRecordSpan
helper function here will improve code consistency and reduce redundancy.
3237-3243
: Refactor duplicated error handling inStreamRemove
Again, the error handling logic in lines 3237-3243 is similar to other methods. Utilize the
parseErrorAndRecordSpan
helper function to maintain consistency and reduce code duplication.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2669 +/- ##
==========================================
+ Coverage 23.94% 24.08% +0.14%
==========================================
Files 539 539
Lines 46937 46638 -299
==========================================
- Hits 11238 11233 -5
+ Misses 34923 34627 -296
- Partials 776 778 +2 ☔ View full report in Codecov by Sentry. |
Deploying vald with Cloudflare Pages
|
Profile Report
|
5a65dc4
to
1daf54b
Compare
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (5)
pkg/gateway/filter/handler/grpc/handler.go (5)
288-296
: LGTM: Consistent error handling implementation.The changes in this segment are consistent with the PR objective and the previous segment. The error handling logic is sound and follows best practices.
Consider extracting this error handling logic into a separate helper function to reduce code duplication across multiple methods. This would improve maintainability and adhere to the DRY principle.
1018-1026
: LGTM: Consistent error handling implementation.The changes in this segment maintain consistency with the PR objective and previous segments. The error handling logic is correctly implemented for the
MultiUpdate
method.Given the extensive repetition of this error handling pattern across multiple operations (search, insert, update) and their variations (stream, multi), it is strongly recommended to refactor this code into a helper function. This refactoring would:
- Significantly reduce code duplication
- Improve maintainability
- Centralize error handling logic
- Make future updates or modifications easier to implement across all methods
Consider creating a function like:
func handleError(err error, span trace.Span, methodName string) *status.Status { st, ok := status.FromError(err) if !ok || st == nil { st = status.New(codes.Internal, "failed to convert "+methodName+" gRPC error response") } if span != nil { span.RecordError(err) span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...) span.SetStatus(trace.StatusError, err.Error()) } return st }This function could then be used across all methods, significantly cleaning up the code.
1271-1279
: LGTM: Consistent error handling implementation.The changes in this segment maintain consistency with the PR objective and previous segments. The error handling logic is correctly implemented for the
MultiUpsert
method.The consistent repetition of this error handling pattern across all major operations (search, insert, update, upsert) and their variations (stream, multi) strongly emphasizes the need for refactoring. Implementing the previously suggested helper function would:
- Eliminate the extensive code duplication observed throughout the file
- Ensure consistent error handling across all methods
- Simplify future maintenance and updates
- Improve code readability
This refactoring should be considered a high priority for improving the overall quality and maintainability of the codebase.
2070-2078
: LGTM: Consistent error handling implementation for stream errors.The changes in this segment maintain consistency with the PR objective and implement proper error handling for the stream in the
StreamLinearSearchByID
method.While this error handling is for the stream itself and slightly different from the previous patterns, it should still be considered in the overall refactoring effort. The helper function suggested earlier could be extended or a separate helper could be created to handle stream-specific errors. This would ensure consistency in error handling across both method-level and stream-level errors throughout the file.
2112-2120
: LGTM: Consistent error handling implementation.The changes in this segment maintain consistency with the PR objective and previous segments. The error handling logic is correctly implemented for the
MultiLinearSearch
method.This final instance of the repeated error handling pattern in the
MultiLinearSearch
method serves as a conclusive evidence for the urgent need of refactoring. To summarize the benefits of implementing the suggested helper function:
- It would eliminate the extensive code duplication observed across all operation types (search, insert, update, upsert) and their variations (stream, multi, linear).
- It would ensure consistent error handling throughout the entire file.
- It would significantly improve code maintainability and readability.
- It would simplify future updates or modifications to the error handling logic.
Implementing this refactoring should be considered a high-priority task to improve the overall quality and efficiency of the codebase.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- pkg/gateway/filter/handler/grpc/handler.go (32 hunks)
🔇 Additional comments (9)
pkg/gateway/filter/handler/grpc/handler.go (9)
239-247
: LGTM: Error handling improvement implemented as per PR objective.The changes in this segment successfully implement the PR objective of replacing
ParseError
withFromError
. The error handling logic is robust, and the span recording is comprehensive, including all necessary error details.
473-481
: LGTM: Consistent error handling implementation.The changes in this segment maintain consistency with the PR objective and previous segments. The error handling logic is correctly implemented.
The previous suggestion for refactoring the error handling logic into a helper function applies here as well. This would significantly reduce code duplication across methods like
MultiSearchObject
,StreamSearchObject
, andMultiLinearSearchObject
.
526-534
: LGTM: Consistent error handling implementation.The changes in this segment maintain consistency with the PR objective and previous segments. The error handling logic is correctly implemented.
The suggestion for refactoring the error handling logic into a helper function remains applicable. This repeated pattern across multiple methods (now including
StreamLinearSearchObject
) strongly indicates that such a refactoring would be beneficial for code maintainability and reducing duplication.
711-719
: LGTM: Consistent error handling implementation.The changes in this segment maintain consistency with the PR objective and previous segments. The error handling logic is correctly implemented for the
StreamInsertObject
method.The repeated occurrence of this error handling pattern across different operation types (search, insert) further emphasizes the need for a helper function. Refactoring would improve code maintainability and reduce duplication across the entire file.
773-781
: LGTM: Consistent error handling implementation.The changes in this segment maintain consistency with the PR objective and previous segments. The error handling logic is correctly implemented for the
MultiInsert
method.The consistent repetition of this error handling pattern across various method types (including
MultiInsert
) strongly reinforces the need for a helper function. Refactoring would significantly improve code maintainability and reduce duplication throughout the file.
957-965
: LGTM: Consistent error handling implementation.The changes in this segment maintain consistency with the PR objective and previous segments. The error handling logic is correctly implemented for the
StreamUpdateObject
method.The recurrence of this error handling pattern in yet another operation type (update) further emphasizes the need for a helper function. Refactoring would significantly improve code maintainability, reduce duplication, and make future updates easier across all operation types in the file.
1210-1218
: LGTM: Consistent error handling implementation.The changes in this segment maintain consistency with the PR objective and previous segments. The error handling logic is correctly implemented for the
StreamUpsertObject
method.The recurrence of this error handling pattern in the upsert operation further reinforces the previous suggestion for refactoring. Implementing the proposed helper function would greatly benefit this method as well, ensuring consistent error handling across all operation types.
1993-2001
: LGTM: Consistent error handling implementation.The changes in this segment maintain consistency with the PR objective and previous segments. The error handling logic is correctly implemented for the
StreamLinearSearch
method.The recurrence of this error handling pattern in the linear search operation further reinforces the urgent need for refactoring, as suggested in previous comments. Implementing the proposed helper function would greatly benefit this method, ensuring consistent and maintainable error handling across all operation types, including linear search.
2048-2056
: LGTM: Consistent error handling implementation.The changes in this segment maintain consistency with the PR objective and previous segments. The error handling logic is correctly implemented for the
StreamLinearSearchByID
method.The presence of this error handling pattern in yet another variation of linear search (StreamLinearSearchByID) further emphasizes the critical need for the refactoring suggested in previous comments. Implementing the proposed helper function would significantly improve code quality, maintainability, and consistency across all search variations and other operations.
1daf54b
to
e84c1bf
Compare
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- pkg/gateway/filter/handler/grpc/handler.go (32 hunks)
🔇 Additional comments (31)
pkg/gateway/filter/handler/grpc/handler.go (31)
288-297
: Refactor suggestionThis error handling block is similar to the one at lines 239-247. Consider using the suggested
handleError
helper function here as well.
473-482
: Refactor suggestionThis error handling block is similar to the ones at lines 239-247 and 288-297. Consider using the suggested
handleError
helper function here as well.
526-535
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
711-720
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
773-782
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
957-966
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
1018-1027
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
1210-1219
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
1271-1280
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
1384-1393
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
1470-1479
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
1562-1571
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
1612-1621
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
1672-1681
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
1730-1739
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
1993-2002
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
2048-2057
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
2070-2079
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
2112-2121
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
2170-2179
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
2360-2369
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
2420-2429
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
2604-2613
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
2658-2667
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
2843-2852
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
2865-2874
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
2908-2917
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
3001-3010
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
3023-3032
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
3065-3074
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
3256-3265
: Refactor suggestionThis error handling block is similar to the previous ones. Consider using the suggested
handleError
helper function here as well.
c9029f6
278f407
to
c9029f6
Compare
Signed-off-by: Kosuke Morimoto <[email protected]>
Signed-off-by: Kosuke Morimoto <[email protected]>
Signed-off-by: Kosuke Morimoto <[email protected]>
c9029f6
to
4bf51e0
Compare
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.
LGTM!
Profile Report
|
* use FromError Signed-off-by: Kosuke Morimoto <[email protected]> * fix Signed-off-by: Kosuke Morimoto <[email protected]> * fix Signed-off-by: Kosuke Morimoto <[email protected]> --------- Signed-off-by: Kosuke Morimoto <[email protected]>
* use FromError * fix * fix --------- Signed-off-by: Kosuke Morimoto <[email protected]> Co-authored-by: Kosuke Morimoto <[email protected]>
Description
use FromError instead of ParseError
Related Issue
Versions
Checklist
Special notes for your reviewer
Summary by CodeRabbit
Bug Fixes
Improvements