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 validation service address #293

Merged
merged 4 commits into from
Nov 26, 2024
Merged

Fix validation service address #293

merged 4 commits into from
Nov 26, 2024

Conversation

richardhuaaa
Copy link
Contributor

@richardhuaaa richardhuaaa commented Nov 26, 2024

GRPC uses a different target format

Summary by CodeRabbit

  • New Features

    • Enhanced logging capabilities for the MLS Validation Service during initialization.
    • Improved secure connection handling to the gRPC service.
  • Bug Fixes

    • Updated gRPC address format to ensure proper interaction with the service.
  • Chores

    • Streamlined import statements in the utilities package.
    • Updated environment variable to specify HTTP protocol for gRPC address.

@richardhuaaa richardhuaaa requested a review from a team as a code owner November 26, 2024 19:55
Copy link

coderabbitai bot commented Nov 26, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces modifications to the NewMlsValidationService function in pkg/mlsvalidate/service.go, adding logging capabilities and enhancing error handling for gRPC connections. The NewReplicationServer function in pkg/server/server.go is updated to accommodate the new logging parameter. Additionally, the GrpcAddress in the config.MlsValidationOptions structure is updated for clarity in pkg/server/server_test.go, while minor import adjustments are made in pkg/utils/grpc.go. Overall, the changes improve initialization and error reporting for the MLS validation service.

Changes

File Change Summary
pkg/mlsvalidate/service.go Updated NewMlsValidationService to include log *zap.Logger, improved error handling, and logging.
pkg/server/server.go Modified NewReplicationServer to pass log parameter to MlsValidationService.
pkg/server/server_test.go Changed GrpcAddress from "localhost:60051" to "http://localhost:60051" in NewTestServer.
pkg/utils/grpc.go Added net/url import, removed duplicate import, and adjusted HttpAddressToGrpcTarget for URL parsing.
dev/local.env Updated XMTPD_MLS_VALIDATION_GRPC_ADDRESS from "localhost:60051" to "http://localhost:60051".

Possibly related PRs

  • Only listen on localhost for unit tests #261: The changes in this PR involve updating the NewReplicationServer function to include a logging parameter, which is directly related to the logging enhancements made in the main PR's NewMlsValidationService function.
  • Add some logs #292: This PR enhances logging functionality in the ReplicationServer, which aligns with the logging improvements introduced in the main PR's modifications to the NewMlsValidationService function.

Suggested reviewers

  • mkysel

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.

Copy link

@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)
pkg/mlsvalidate/service.go (1)

30-30: Maintain consistency in error message capitalization

Error messages should follow consistent capitalization. Consider this change:

-		return nil, fmt.Errorf("Failed to convert HTTP address to gRPC target: %v", err)
+		return nil, fmt.Errorf("failed to convert HTTP address to gRPC target: %v", err)
-		return nil, fmt.Errorf("Failed to get credentials: %v", err)
+		return nil, fmt.Errorf("failed to get credentials: %v", err)

Also applies to: 35-35

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f05ea4c and d1163b2.

📒 Files selected for processing (4)
  • pkg/mlsvalidate/service.go (2 hunks)
  • pkg/server/server.go (1 hunks)
  • pkg/server/server_test.go (2 hunks)
  • pkg/utils/grpc.go (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • pkg/server/server_test.go
  • pkg/utils/grpc.go
🔇 Additional comments (5)
pkg/server/server.go (2)

99-102: LGTM! Verify indexer integration with the validation service.

The addition of logging to the MLS validation service initialization looks good. The error handling is properly implemented, and the service is correctly integrated with the indexer when enabled.

Let's verify the integration points:

✅ Verification successful

Integration with validation service is properly implemented

The validation service is correctly integrated throughout the codebase:

  • Properly initialized in the server with logging and configuration
  • Correctly passed to the indexer's StartIndexer function
  • Used in the IdentityUpdateStorer for validating association states
  • Well-tested with proper mocking in test files
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the validation service integration with indexer
# and configuration structure

# Check validation service usage in indexer
ast-grep --pattern 'StartIndexer($_) {
  $$$
  validationService
  $$$
}'

# Verify MlsValidation options structure
ast-grep --pattern 'type MlsValidationOptions struct {
  $$$
}'

Length of output: 387


Script:

#!/bin/bash
# Let's check how validationService is used in the server implementation
rg "validationService" -A 3 -B 3

# Also check for any indexer-related code that might use the validation service
ast-grep --pattern 'func ($_) StartIndexer($_) {
  $$$
}'

Length of output: 5280


99-99: Verify GRPC address format in configuration.

Since this PR addresses GRPC target format changes, ensure that options.MlsValidation contains the correctly formatted GRPC address.

Let's check the configuration handling:

✅ Verification successful

Let me gather more information about the address conversion utility that's being used.


Let me check the complete implementation of the address conversion utility and its tests.


GRPC address format is properly handled

The implementation in pkg/utils/grpc.go correctly handles GRPC address conversion by:

  • Parsing URLs with both HTTP and HTTPS schemes
  • Properly extracting hostname and port information
  • Setting TLS flag based on the scheme
  • Handling empty schemes and ports appropriately
  • Returning well-formatted GRPC target addresses

The configuration is properly utilized in pkg/mlsvalidate/service.go where it:

  1. Converts the HTTP address to GRPC target
  2. Sets up appropriate credentials based on TLS
  3. Logs the connection details for monitoring
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the GRPC address format handling

# Check for GRPC address format handling
rg -A 3 "MlsValidation.*Address|GrpcAddress" 

# Look for any address conversion utilities
ast-grep --pattern 'func $_($_, address string) string {
  $$$
}'

Length of output: 1272


Script:

#!/bin/bash
# Check the implementation of HttpAddressToGrpcTarget
rg -A 10 "HttpAddressToGrpcTarget" 

# Look for any related tests
rg -A 5 "TestHttpAddressToGrpcTarget"

Length of output: 1874


Script:

#!/bin/bash
# Get the complete implementation of HttpAddressToGrpcTarget
ast-grep --pattern 'func HttpAddressToGrpcTarget(httpAddress string) (string, bool, error) {
  $$$
}'

# Look for tests in a different way
rg -l "HttpAddressToGrpcTarget.*test"

Length of output: 1046

pkg/mlsvalidate/service.go (3)

14-15: LGTM: Import additions are appropriate

The new imports for utils and zap logger are necessary for the enhanced functionality.


24-41: LGTM: Improved GRPC connection handling with proper security

The changes correctly implement:

  • GRPC target format conversion
  • Proper TLS credential handling
  • Comprehensive error handling
  • Informative logging

28-31: Verify GRPC address format compatibility

Let's ensure the new GRPC target format is compatible with all existing configurations.

✅ Verification successful

Let me gather more information about the GRPC address format conversion utility.


Let me check the implementation details and test coverage of the GRPC address conversion utility.


GRPC address format is well-defined and safely implemented

The implementation of HttpAddressToGrpcTarget follows standard URL parsing and GRPC target format specifications. The function:

  • Handles both HTTP and HTTPS schemes
  • Properly manages empty schemes defaulting to non-TLS
  • Correctly extracts hostname and port information
  • Is used consistently across the codebase (mlsvalidate and registry services)
  • Has clear error handling for invalid URLs and unknown schemes

The only test configuration found uses a valid format (http://localhost:60051), which is compatible with the implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for GRPC address configurations and usage
echo "Searching for GRPC address configurations..."
rg -A 2 "GrpcAddress" 

echo "Searching for NewMlsValidationService usage..."
ast-grep --pattern 'NewMlsValidationService($$$)'

Length of output: 1240


Script:

#!/bin/bash
# Search for HttpAddressToGrpcTarget implementation and usage
echo "Searching for HttpAddressToGrpcTarget implementation..."
ast-grep --pattern 'HttpAddressToGrpcTarget($$$)'

echo "Searching for related test cases..."
rg -A 5 "HttpAddressToGrpcTarget"

Length of output: 1421


Script:

#!/bin/bash
# Search for the complete implementation and tests
echo "Searching for complete implementation in utils/grpc.go..."
cat pkg/utils/grpc.go

echo "Searching for related test files..."
fd "grpc_test.go" --exec cat {}

Length of output: 1567

@mkysel
Copy link
Collaborator

mkysel commented Nov 26, 2024

do we need to fix the dev scripts too? local.env and possibly others?

@richardhuaaa richardhuaaa enabled auto-merge (squash) November 26, 2024 20:54
@richardhuaaa richardhuaaa merged commit 5fcc382 into main Nov 26, 2024
7 of 8 checks passed
@richardhuaaa richardhuaaa deleted the rich/fix-address branch November 26, 2024 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants