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

Fix gRPC error msg handling for lb-gateway handler #2663

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vankichi
Copy link
Contributor

@vankichi vankichi commented Oct 1, 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

  • New Features

    • Enhanced error handling across key methods: Exists, Search, 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.
  • 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.

Copy link

cloudflare-workers-and-pages bot commented Oct 1, 2024

Deploying vald with  Cloudflare Pages  Cloudflare Pages

Latest commit: 59a39bc
Status: ✅  Deploy successful!
Preview URL: https://a643d56d.vald.pages.dev
Branch Preview URL: https://refactor-pkg-fix-handler-grp.vald.pages.dev

View logs

Copy link
Contributor

coderabbitai bot commented Oct 1, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes involve modifications to the pkg/gateway/lb/handler/grpc/aggregation.go and pkg/gateway/lb/handler/grpc/handler.go files. The aggregationSearch method's signature is updated to include a new return value for observability attributes, necessitating changes in its internal logic for error handling. The handler.go file sees enhancements in error handling and logic across the Exists, Insert, Update, and Remove methods, including improved UUID validation and structured checks for existing records.

Changes

Files Change Summary
pkg/gateway/lb/handler/grpc/aggregation.go - Updated aggregationSearch method to return attrs []attribute.KeyValue alongside existing return values.
- Enhanced error handling logic to populate attrs with observability attributes for various error scenarios.
pkg/gateway/lb/handler/grpc/handler.go - Refined error handling in Exists, Insert, Update, and Remove methods.
- Enhanced UUID validation and error messages in Exists.
- Structured checks for existing UUIDs in Insert.
- Added checks for existing vectors and timestamps in Update.
- Enhanced error handling and context in Remove.
- Updated method signatures for Exists, Insert, Update, and Remove.

Possibly related PRs

  • add check context cancel #2596: This PR enhances error handling related to context cancellation, which is relevant to the changes in the main PR that also involve handling context-related errors in the aggregationSearch method.
  • Bugfix ingress route settings #2636: Although primarily focused on ingress routing, this PR includes modifications to paths that may relate to the methods being called in the aggregationSearch method, particularly if those methods are invoked via gRPC.

Suggested labels

type/bug, priority/medium, size/S, area/internal, actions/e2e-deploy, actions/fossa

Suggested reviewers

  • kpango
  • 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 1, 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

@vankichi vankichi changed the title ♻️ Fix Fix gRPC error msg handling for lb-gateway handler Oct 1, 2024
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d6b6c8c and 3933a21.

📒 Files selected for processing (1)
  • pkg/gateway/lb/handler/grpc/handler.go (1 hunks)

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

codecov bot commented Oct 1, 2024

Codecov Report

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

Project coverage is 24.06%. Comparing base (da0ac80) to head (59a39bc).

Files with missing lines Patch % Lines
pkg/gateway/lb/handler/grpc/handler.go 0.00% 174 Missing ⚠️
pkg/gateway/lb/handler/grpc/aggregation.go 0.00% 22 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2663      +/-   ##
==========================================
+ Coverage   23.99%   24.06%   +0.07%     
==========================================
  Files         539      539              
  Lines       47179    47070     -109     
==========================================
+ Hits        11319    11329      +10     
+ Misses      35090    34972     -118     
+ Partials      770      769       -1     

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

@vankichi vankichi force-pushed the refactor/pkg/fix-handler-gRPC-errro-handling branch from 3933a21 to efbfe88 Compare October 2, 2024 00:59
@vankichi vankichi force-pushed the refactor/pkg/fix-handler-gRPC-errro-handling branch from efbfe88 to 0303819 Compare October 3, 2024 06:36
@vankichi vankichi force-pushed the refactor/pkg/fix-handler-gRPC-errro-handling branch from 0303819 to 59a39bc Compare October 3, 2024 06:37
@github-actions github-actions bot removed the size/S label Oct 3, 2024
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

🧹 Outside diff range and nitpick comments (11)
pkg/gateway/lb/handler/grpc/handler.go (10)

258-270: LGTM! Consider adding unit tests for this section.

The error handling and status code assignment logic in this section are well-implemented. The use of status.FromError is a good practice for handling gRPC errors. However, this newly added code is not covered by tests.

To improve the overall quality and maintainability of the codebase, consider adding unit tests to cover this section of the Exists method, particularly focusing on different error scenarios and status code assignments.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 258-260: pkg/gateway/lb/handler/grpc/handler.go#L258-L260
Added lines #L258 - L260 were not covered by tests


[warning] 262-268: pkg/gateway/lb/handler/grpc/handler.go#L262-L268
Added lines #L262 - L268 were not covered by tests


[warning] 270-270: pkg/gateway/lb/handler/grpc/handler.go#L270
Added line #L270 was not covered by tests


313-313: LGTM! Consider adding unit tests for this section.

The use of doSearch with a function argument is a good practice for code reuse and flexibility. However, this newly added code is not covered by tests.

To ensure the reliability of the Search method, consider adding unit tests that cover this call to doSearch, including various scenarios for the function argument passed to it.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 313-313: pkg/gateway/lb/handler/grpc/handler.go#L313
Added line #L313 was not covered by tests


318-320: LGTM! Consider adding unit tests for error handling.

The error handling and span recording in this section are appropriate for maintaining observability. However, this newly added code is not covered by tests.

To ensure robust error handling, consider adding unit tests that cover these error scenarios in the Search method. This will help verify that span attributes and statuses are correctly set when errors occur.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 318-318: pkg/gateway/lb/handler/grpc/handler.go#L318
Added line #L318 was not covered by tests


[warning] 320-320: pkg/gateway/lb/handler/grpc/handler.go#L320
Added line #L320 was not covered by tests


370-377: LGTM! Consider adding unit tests for fallback mechanism.

The error handling and fallback mechanism to the agent's SearchByID method are well-implemented. The use of status.FromError is consistent with other parts of the code. However, this newly added code is not covered by tests.

To ensure the reliability of the SearchByID method, consider adding unit tests that cover this error handling and fallback mechanism. Specifically, test scenarios where the initial search fails and the fallback to the agent's SearchByID is triggered.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 370-370: pkg/gateway/lb/handler/grpc/handler.go#L370
Added line #L370 was not covered by tests


[warning] 377-377: pkg/gateway/lb/handler/grpc/handler.go#L377
Added line #L377 was not covered by tests


490-493: LGTM! Consider adding unit tests for error handling in StreamSearch.

The error handling and span recording in the StreamSearch method are appropriate for maintaining observability. The use of status.FromError is consistent with other parts of the code. However, this newly added code is not covered by tests.

To ensure robust error handling in the streaming context, consider adding unit tests that cover these error scenarios in the StreamSearch method. This will help verify that span attributes and statuses are correctly set when errors occur during streaming operations.


509-512: LGTM! Consider adding unit tests for final error handling in StreamSearch.

The final error handling and span recording in the StreamSearch method are appropriate for maintaining observability. The use of status.FromError is consistent with other parts of the code. However, this newly added code is not covered by tests.

To ensure comprehensive error handling, consider adding unit tests that cover this final error check in the StreamSearch method. This will help verify that span attributes and statuses are correctly set when errors occur at the end of the streaming operation.


537-540: LGTM! Consider adding unit tests for error handling in StreamSearchByID.

The error handling and span recording in the StreamSearchByID method are appropriate for maintaining observability. The use of status.FromError is consistent with other parts of the code. However, this newly added code is not covered by tests.

To ensure robust error handling in the streaming context, consider adding unit tests that cover these error scenarios in the StreamSearchByID method. This will help verify that span attributes and statuses are correctly set when errors occur during streaming operations.


556-559: LGTM! Consider adding unit tests for final error handling in StreamSearchByID.

The final error handling and span recording in the StreamSearchByID method are appropriate for maintaining observability. The use of status.FromError is consistent with other parts of the code. However, this newly added code is not covered by tests.

To ensure comprehensive error handling, consider adding unit tests that cover this final error check in the StreamSearchByID method. This will help verify that span attributes and statuses are correctly set when errors occur at the end of the streaming operation.


624-628: LGTM! Consider adding unit tests for error handling in MultiSearch.

The error handling and span recording in the MultiSearch method are appropriate for maintaining observability. The use of status.FromError is consistent with other parts of the code. However, this newly added code is not covered by tests.

To ensure robust error handling for multiple search operations, consider adding unit tests that cover these error scenarios in the MultiSearch method. This will help verify that span attributes and statuses are correctly set when errors occur during multiple search operations.


693-697: LGTM! Consider adding unit tests for error handling in MultiSearchByID.

The error handling and span recording in the MultiSearchByID method are appropriate for maintaining observability. The use of status.FromError is consistent with other parts of the code. However, this newly added code is not covered by tests.

To ensure robust error handling for multiple search-by-ID operations, consider adding unit tests that cover these error scenarios in the MultiSearchByID method. This will help verify that span attributes and statuses are correctly set when errors occur during multiple search-by-ID operations.

pkg/gateway/lb/handler/grpc/aggregation.go (1)

34-34: Consider aliasing the imported sync package to avoid confusion

Importing the internal sync package as sync may cause confusion with Go's standard library sync package. To improve code clarity and prevent potential conflicts, consider aliasing the import. For example:

 import (
 	...
-	"github.com/vdaas/vald/internal/sync"
+	internalSync "github.com/vdaas/vald/internal/sync"
 )

This helps differentiate between the standard sync package and the internal one.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between efbfe88 and 59a39bc.

📒 Files selected for processing (2)
  • pkg/gateway/lb/handler/grpc/aggregation.go (8 hunks)
  • pkg/gateway/lb/handler/grpc/handler.go (57 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
pkg/gateway/lb/handler/grpc/aggregation.go

[warning] 60-60: pkg/gateway/lb/handler/grpc/aggregation.go#L60
Added line #L60 was not covered by tests


[warning] 239-239: pkg/gateway/lb/handler/grpc/aggregation.go#L239
Added line #L239 was not covered by tests


[warning] 242-242: pkg/gateway/lb/handler/grpc/aggregation.go#L242
Added line #L242 was not covered by tests


[warning] 245-245: pkg/gateway/lb/handler/grpc/aggregation.go#L245
Added line #L245 was not covered by tests


[warning] 266-266: pkg/gateway/lb/handler/grpc/aggregation.go#L266
Added line #L266 was not covered by tests


[warning] 269-269: pkg/gateway/lb/handler/grpc/aggregation.go#L269
Added line #L269 was not covered by tests


[warning] 272-272: pkg/gateway/lb/handler/grpc/aggregation.go#L272
Added line #L272 was not covered by tests


[warning] 287-287: pkg/gateway/lb/handler/grpc/aggregation.go#L287
Added line #L287 was not covered by tests


[warning] 290-290: pkg/gateway/lb/handler/grpc/aggregation.go#L290
Added line #L290 was not covered by tests


[warning] 293-293: pkg/gateway/lb/handler/grpc/aggregation.go#L293
Added line #L293 was not covered by tests


[warning] 308-308: pkg/gateway/lb/handler/grpc/aggregation.go#L308
Added line #L308 was not covered by tests


[warning] 311-311: pkg/gateway/lb/handler/grpc/aggregation.go#L311
Added line #L311 was not covered by tests


[warning] 316-316: pkg/gateway/lb/handler/grpc/aggregation.go#L316
Added line #L316 was not covered by tests


[warning] 332-332: pkg/gateway/lb/handler/grpc/aggregation.go#L332
Added line #L332 was not covered by tests


[warning] 335-335: pkg/gateway/lb/handler/grpc/aggregation.go#L335
Added line #L335 was not covered by tests


[warning] 338-338: pkg/gateway/lb/handler/grpc/aggregation.go#L338
Added line #L338 was not covered by tests


[warning] 345-345: pkg/gateway/lb/handler/grpc/aggregation.go#L345
Added line #L345 was not covered by tests


[warning] 348-348: pkg/gateway/lb/handler/grpc/aggregation.go#L348
Added line #L348 was not covered by tests


[warning] 363-363: pkg/gateway/lb/handler/grpc/aggregation.go#L363
Added line #L363 was not covered by tests


[warning] 366-366: pkg/gateway/lb/handler/grpc/aggregation.go#L366
Added line #L366 was not covered by tests


[warning] 369-369: pkg/gateway/lb/handler/grpc/aggregation.go#L369
Added line #L369 was not covered by tests


[warning] 372-372: pkg/gateway/lb/handler/grpc/aggregation.go#L372
Added line #L372 was not covered by tests

pkg/gateway/lb/handler/grpc/handler.go

[warning] 258-260: pkg/gateway/lb/handler/grpc/handler.go#L258-L260
Added lines #L258 - L260 were not covered by tests


[warning] 262-268: pkg/gateway/lb/handler/grpc/handler.go#L262-L268
Added lines #L262 - L268 were not covered by tests


[warning] 270-270: pkg/gateway/lb/handler/grpc/handler.go#L270
Added line #L270 was not covered by tests


[warning] 313-313: pkg/gateway/lb/handler/grpc/handler.go#L313
Added line #L313 was not covered by tests


[warning] 318-318: pkg/gateway/lb/handler/grpc/handler.go#L318
Added line #L318 was not covered by tests


[warning] 320-320: pkg/gateway/lb/handler/grpc/handler.go#L320
Added line #L320 was not covered by tests


[warning] 370-370: pkg/gateway/lb/handler/grpc/handler.go#L370
Added line #L370 was not covered by tests


[warning] 377-377: pkg/gateway/lb/handler/grpc/handler.go#L377
Added line #L377 was not covered by tests

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

github-actions bot commented Oct 3, 2024

@vdaas-ci
Copy link
Collaborator

vdaas-ci commented Oct 3, 2024

Profile Report

typevald-agent-ngtvald-lb-gatewayvald-discoverervald-manager-index
cpu
heap
other images

@vankichi vankichi marked this pull request as ready for review October 3, 2024 07:34
@vankichi vankichi requested review from a team and kmrmt and removed request for a team October 3, 2024 07:34
@vankichi vankichi requested review from datelier, a team, kpango and hlts2 and removed request for kmrmt, datelier and a team October 3, 2024 07:34
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.

3 participants