Skip to content
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

Backport PR #2663 to to release/v1.7 for Fix gRPC error msg handling for lb-gateway handler #2682

Conversation

hlts2
Copy link
Collaborator

@hlts2 hlts2 commented Oct 8, 2024

Description

SSIA

Related Issue

Versions

  • Vald Version: v1.7.13
  • Go Version: v1.23.1
  • Rust Version: v1.81.0
  • Docker Version: v27.3.1
  • Kubernetes Version: v1.31.1
  • Helm Version: v3.16.1
  • NGT Version: v2.2.4
  • Faiss Version: v1.8.0

Checklist

Special notes for your reviewer

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced error handling across key methods: Exists, Insert, Update, and Remove.
    • Improved validation and clarity in error messages for better debugging.
    • Added observability attributes to the aggregationSearch method for improved error tracking.
    • Introduced new helper functions for statistical calculations.
  • Bug Fixes

    • Resolved issues with UUID handling and response parsing to ensure more informative feedback.
  • Refactor

    • Streamlined logic for handling existing records and control flow across multiple methods.
    • Improved tracing capabilities for better monitoring and debugging.

* ♻️ refactor: replace ParseError with FromError

Signed-off-by: vankichi <[email protected]>

* ♻️ fix

Signed-off-by: vankichi <[email protected]>

* ♻️ fix

Signed-off-by: vankichi <[email protected]>

* ♻️ fix

Signed-off-by: vankichi <[email protected]>

---------

Signed-off-by: vankichi <[email protected]>
Co-authored-by: Kosuke Morimoto <[email protected]>
@hlts2 hlts2 requested a review from vankichi October 8, 2024 10:06
Copy link
Contributor

coderabbitai bot commented Oct 8, 2024

📝 Walkthrough

Walkthrough

The pull request introduces significant modifications to the grpc package, specifically enhancing the aggregationSearch method and several others in pkg/gateway/lb/handler/grpc/handler.go. The changes primarily involve the addition of an attrs return value to multiple method signatures, improving error handling and tracing capabilities. The method now returns observability attributes alongside existing return values, allowing for better tracking of execution states and errors. The error handling logic has also been refined to provide more clarity and consistency across various methods.

Changes

File Path Change Summary
pkg/gateway/lb/handler/grpc/aggregation.go Updated aggregationSearch method to include an attrs return value, enhancing error handling and observability attributes collection.
pkg/gateway/lb/handler/grpc/handler.go Multiple methods updated to include attrs return value, refined error handling using status.FromError, improved tracing, and introduced new helper functions.

Possibly related PRs

Suggested labels

priority/low, size/XXXL, area/gateway/lb, actions/e2e-deploy, actions/fossa, actions/e2e-chaos, actions/e2e-profiling, actions/e2e-max-dim, actions/backport/release/v1.7

Suggested reviewers

  • vankichi
  • kmrmt

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@vdaas-ci
Copy link
Collaborator

vdaas-ci commented Oct 8, 2024

[CHATOPS:HELP] ChatOps commands.

  • 🙆‍♀️ /approve - approve
  • 🍱 /format - format codes and add licenses
  • /gen-test - generate test codes
  • 🏷️ /label - add labels
  • 🔚 2️⃣ 🔚 /label actions/e2e-deploy - run E2E deploy & integration test

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4dc9354 and 6c9ab99.

📒 Files selected for processing (2)
  • pkg/gateway/lb/handler/grpc/aggregation.go (8 hunks)
  • pkg/gateway/lb/handler/grpc/handler.go (64 hunks)
🧰 Additional context used
🔇 Additional comments (21)
pkg/gateway/lb/handler/grpc/aggregation.go (8)

34-35: Approved: Importing Observability Packages

The addition of the attribute and trace packages is appropriate for enhancing observability.


266-272: Duplicate Error Handling Logic

Similar to the previous comment, this error handling code is duplicated. Refactoring as suggested earlier will improve maintainability.


287-293: Duplicate Error Handling Logic

This block also contains duplicated error handling code. Consider refactoring to reduce redundancy.


308-316: Duplicate Error Handling Logic

The error handling code here is similar to earlier instances. Refactoring can help reduce code duplication.


332-338: Duplicate Error Handling Logic

This is another instance of duplicated error handling code. Refactoring as suggested will enhance code clarity and maintainability.


Line range hint 345-369: Duplicate Error Handling Logic

The error handling logic in these lines is repetitive. Refactoring to use a helper function can improve maintainability and reduce code duplication.


372-372: Ensure attrs is Appropriately Initialized

In the success path at the end of the function, attrs may be nil. Ensure that downstream code can handle a nil slice without issues.

If necessary, initialize attrs to an empty slice before returning:

if attrs == nil {
    attrs = []attribute.KeyValue{}
}
return res, attrs, nil

60-60: Verify Callers Handle Updated Function Signature

The aggregationSearch method now returns an additional attrs []attribute.KeyValue. Please ensure that all callers of this method are updated to handle the new return value appropriately.

Run the following script to identify and verify callers of aggregationSearch:

pkg/gateway/lb/handler/grpc/handler.go (13)

42-43: Add necessary imports for tracing functionality

The addition of observability/attribute and observability/trace imports is appropriate for the enhanced tracing and error handling implemented in this PR.


313-320: Correctly propagate attributes from doSearch and set tracing information

The changes in the Search method properly capture attrs returned from doSearch and use them to set span attributes, enhancing tracing and observability.


370-373: ⚠️ Potential issue

Ensure proper handling of status.FromError in SearchByID

Similar to an earlier issue, the boolean return value from status.FromError(err) is ignored. This may lead to a nil pointer dereference if st is nil.

Apply this diff to handle the boolean return value correctly:

-    		st, _ := status.FromError(err)
-    		if span != nil && st != nil && st.Code() != codes.NotFound {
+    		st, ok := status.FromError(err)
+    		if span != nil && ok && st.Code() != codes.NotFound {
    			span.RecordError(err)
    			span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)
    			span.SetStatus(trace.StatusError, err.Error())
    		}

784-788: ⚠️ Potential issue

Handle status.FromError boolean return value in LinearSearchByID

Ensure that the boolean return value from status.FromError(err) is handled to prevent potential nil pointer dereference when accessing st.Code().


1635-1638: ⚠️ Potential issue

Proper error handling in Update method

In the Update method, handle the boolean return value from status.FromError(err) to ensure st is not nil before accessing its methods.


2110-2113: ⚠️ Potential issue

Ensure safe usage of status.FromError in UpdateTimestamp

In the UpdateTimestamp method, handle the boolean return value from status.FromError(err) to avoid nil pointer dereference.


2511-2514: ⚠️ Potential issue

Handle status.FromError return value in Remove method

In the Remove method, correctly handle the boolean return value from status.FromError(err) to prevent accessing a nil st.


3148-3151: ⚠️ Potential issue

Proper handling of status.FromError in GetObject

Ensure that the boolean return value from status.FromError(err) is handled in the GetObject method to avoid potential nil pointer dereference.


3410-3413: ⚠️ Potential issue

Handle status.FromError return value in IndexInfo

In the IndexInfo method, handle the boolean return value from status.FromError(err) to ensure safe error handling.


3541-3544: ⚠️ Potential issue

Ensure correct usage of status.FromError in IndexDetail

Handle the boolean return value from status.FromError(err) in the IndexDetail method to prevent nil pointer dereference.


3707-3710: ⚠️ Potential issue

Avoid nil pointer dereference in GetTimestamp by handling status.FromError return value

In the GetTimestamp method, ensure proper handling of the boolean return value from status.FromError(err).


3874-3877: ⚠️ Potential issue

Handle boolean return value from status.FromError in IndexStatisticsDetail

Properly handle the boolean return value from status.FromError(err) in the IndexStatisticsDetail method to avoid potential nil pointer dereference.


4112-4115: ⚠️ Potential issue

Ensure safe usage of status.FromError in IndexProperty

In the IndexProperty method, handle the boolean return value from status.FromError(err) to prevent accessing a nil st.

pkg/gateway/lb/handler/grpc/aggregation.go Show resolved Hide resolved
pkg/gateway/lb/handler/grpc/handler.go Show resolved Hide resolved
pkg/gateway/lb/handler/grpc/handler.go Show resolved Hide resolved
Copy link

codecov bot commented Oct 8, 2024

Codecov Report

Attention: Patch coverage is 0% with 220 lines in your changes missing coverage. Please review.

Please upload report for BASE (release/v1.7@4dc9354). Learn more about missing BASE report.

Files with missing lines Patch % Lines
pkg/gateway/lb/handler/grpc/handler.go 0.00% 198 Missing ⚠️
pkg/gateway/lb/handler/grpc/aggregation.go 0.00% 22 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##             release/v1.7    #2682   +/-   ##
===============================================
  Coverage                ?   24.09%           
===============================================
  Files                   ?      539           
  Lines                   ?    46983           
  Branches                ?        0           
===============================================
  Hits                    ?    11322           
  Misses                  ?    34892           
  Partials                ?      769           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kpango kpango merged commit 709d00e into release/v1.7 Oct 8, 2024
46 of 48 checks passed
@kpango kpango deleted the backport/release/v1.7/refactor/pkg/fix-handler-gRPC-errro-handling branch October 8, 2024 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants