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

Add option to disable dns resolve #2634

Merged
merged 4 commits into from
Sep 24, 2024
Merged

Conversation

hlts2
Copy link
Contributor

@hlts2 hlts2 commented Sep 19, 2024

Description

When we verified the mirror gateway to connect to multiple locations, we could not connect when dns resolve was enabled. Therefore, I added an interface to disable it.

Related Issue

Versions

  • Vald Version: v1.7.13
  • Go Version: v1.23.1
  • Rust Version: v1.81.0
  • Docker Version: v27.2.1
  • Kubernetes Version: v1.31.0
  • Helm Version: v3.16.0
  • NGT Version: v2.2.4
  • Faiss Version: v1.8.0

Checklist

Special notes for your reviewer

Summary by CodeRabbit

  • New Features

    • Introduced a method to disable DNS resolution for specific addresses, enhancing connection management flexibility.
    • Improved error handling and fallback mechanisms in the gateway service for more reliable gRPC operations.
    • Adjusted connection logic to bypass DNS resolution for certain addresses, potentially improving performance.
    • Added functionality in mock tests to control DNS resolution behavior for more precise testing scenarios.
  • Bug Fixes

    • Enhanced robustness of the gRPC call handling, allowing for alternative connections in case of failures.

Copy link
Contributor

coderabbitai bot commented Sep 19, 2024

Walkthrough

Walkthrough

The changes enhance the gRPC client functionality, particularly regarding DNS address resolution. A new method, SetDisableResolveDNSAddr, is added to the Client interface, enabling clients to disable DNS resolution for specific addresses. The gRPCClient struct is updated with a sync.Map to manage the DNS resolution state. Additionally, the Do method in the gateway struct is improved with enhanced error handling and fallback mechanisms for gRPC calls, while the Connect method in the mirror struct is modified to disable DNS resolution for certain addresses during connection attempts.

Changes

File Path Change Summary
internal/net/grpc/client.go Added SetDisableResolveDNSAddr(addr string, disabled bool) method to Client interface; added disableResolveDNSAddrs sync.Map[string, bool] to gRPCClient struct.
pkg/gateway/mirror/service/gateway.go Enhanced error handling in Do method, implementing a fallback mechanism for gRPC calls with alternative connections.
pkg/gateway/mirror/service/mirror.go Modified Connect method to disable DNS resolution for specific addresses before connecting.
pkg/gateway/mirror/service/mirror_test.go Introduced SetDisableResolveDNSAddrFunc in multiple mock structures for improved test control over DNS resolution behavior.
internal/test/mock/grpc_testify_mock.go Added SetDisableResolveDNSAddr(addr string, distributed bool) method to ClientInternal struct with an empty implementation.

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 202cd08 and cee80ee.

Files selected for processing (2)
  • internal/test/mock/grpc_testify_mock.go (1 hunks)
  • pkg/gateway/mirror/service/gateway.go (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • pkg/gateway/mirror/service/gateway.go
Additional comments not posted (1)
internal/test/mock/grpc_testify_mock.go (1)

217-217: LGTM!

The addition of the SetDisableResolveDNSAddr method to the ClientInternal mock struct is appropriate. The empty implementation is suitable for a mock, as it allows the struct to satisfy the interface without providing any actual behavior.


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

[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: 0

Outside diff range and nitpick comments (1)
internal/net/grpc/client.go (1)

951-955: Implementation looks good!

The SetDisableResolveDNSAddr function allows for dynamically disabling DNS resolution for specific addresses, which is necessary when connecting to multiple locations. The comments provide good context on the rationale behind this implementation.

A few additional suggestions:

  • Consider adding unit tests to verify the behavior of this function.
  • Consider documenting this function in the Client interface definition for better visibility.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bcebbdc and 41f84ae.

Files ignored due to path filters (2)
  • apis/grpc/v1/payload/payload.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • apis/grpc/v1/rpc/errdetails/error_details.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
Files selected for processing (3)
  • internal/net/grpc/client.go (3 hunks)
  • pkg/gateway/mirror/service/gateway.go (2 hunks)
  • pkg/gateway/mirror/service/mirror.go (1 hunks)
Additional comments not posted (3)
pkg/gateway/mirror/service/gateway.go (1)

147-161: LGTM!

The changes to the Do method enhance its error handling capabilities and introduce a robust fallback mechanism. Key improvements include:

  • Checking for an empty target and returning an appropriate error.
  • Creating a new fctx variable to store the forwarded context.
  • Implementing a fallback mechanism using a round-robin approach to attempt the gRPC call with other available connections when an error occurs.
  • Handling the case where the connection's target matches the original target by returning a specific error.
  • Attempting to call the provided function f with the new connection's target as a fallback.

These enhancements allow the method to better manage connection issues, improve the reliability of service calls, and increase the likelihood of successful gRPC operations.

pkg/gateway/mirror/service/mirror.go (1)

322-322: LGTM!

The change to disable DNS resolution for the target address before attempting to connect aligns with the PR objective and could potentially improve connection reliability in certain scenarios.

Please verify that disabling DNS resolution does not introduce any unintended side effects or break existing functionality. Consider running tests or performing manual verification to ensure the change behaves as expected.

Verification successful

LGTM! The change appears to be safe, but careful testing and monitoring are advised.

The implementation to disable DNS resolution for specific addresses in the Connect method is localized and doesn't seem to affect the global DNS behavior of the system. However, given the extensive use of DNS throughout the project, it's crucial to ensure this change doesn't introduce any unintended side effects.

  • Thoroughly test the mirror service functionality, especially in scenarios where DNS resolution is disabled for certain addresses.
  • Monitor the performance and behavior of the mirror service in production after deploying this change.
  • Consider implementing logging or metrics to track when and how often DNS resolution is disabled, which could help in future optimizations.

Please proceed with caution and keep an eye on the system's behavior after deployment.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if disabling DNS resolution has any impact on existing functionality.

# Test: Search for potential side effects or issues related to disabling DNS resolution.
rg --type go -i 'dns|resolve' -A 5

Length of output: 191007

internal/net/grpc/client.go (1)

986-992: Changes look good!

The modifications to the Connect function align with the purpose of the SetDisableResolveDNSAddr function. The added check on the disableResolveDNSAddrs map allows for dynamically disabling DNS resolution for specific addresses. The logic is correct and does not introduce any issues.

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 19, 2024
Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 13.63636% with 19 lines in your changes missing coverage. Please review.

Project coverage is 24.35%. Comparing base (e67dfa1) to head (cee80ee).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
pkg/gateway/mirror/service/gateway.go 0.00% 11 Missing ⚠️
internal/net/grpc/client.go 0.00% 7 Missing ⚠️
internal/test/mock/grpc_testify_mock.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2634      +/-   ##
==========================================
+ Coverage   24.23%   24.35%   +0.11%     
==========================================
  Files         534      536       +2     
  Lines       46261    46459     +198     
==========================================
+ Hits        11213    11315     +102     
- Misses      34296    34375      +79     
- Partials      752      769      +17     

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

Copy link
Contributor

Copy link

cloudflare-workers-and-pages bot commented Sep 19, 2024

Deploying vald with  Cloudflare Pages  Cloudflare Pages

Latest commit: cee80ee
Status: ✅  Deploy successful!
Preview URL: https://c573c062.vald.pages.dev
Branch Preview URL: https://fix-mirror-add-disable-resol.vald.pages.dev

View logs

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 19, 2024
@hlts2 hlts2 mentioned this pull request Sep 20, 2024
2 tasks
@hlts2 hlts2 requested review from a team and datelier and removed request for kmrmt, vankichi, datelier and a team September 20, 2024 07:33
Copy link
Collaborator

@kpango kpango left a comment

Choose a reason for hiding this comment

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

LGTM

@kpango kpango merged commit 10cfd82 into main Sep 24, 2024
180 of 182 checks passed
@kpango kpango deleted the fix/mirror/add-disable-resolve-dns branch September 24, 2024 05:42
vdaas-ci pushed a commit that referenced this pull request Sep 24, 2024
* fix: add option to disable dns resolve

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

* fix: add mock function

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

* fix: unimplemented error

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

* fix: change ForwardedContext method to private

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

---------

Signed-off-by: hlts2 <[email protected]>
hlts2 added a commit that referenced this pull request Sep 24, 2024
* fix: add option to disable dns resolve



* fix: add mock function



* fix: unimplemented error



* fix: change ForwardedContext method to private



---------

Signed-off-by: hlts2 <[email protected]>
Co-authored-by: Hiroto Funakoshi <[email protected]>
@kpango kpango mentioned this pull request Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment