Skip to content

Conversation

@mkysel
Copy link
Collaborator

@mkysel mkysel commented Apr 22, 2025

Add Prometheus metrics to Payer gRPC client operations and consolidate MLS validation service initialization

  • Adds Prometheus metrics instrumentation to the Payer gRPC client operations in clientManager.go and service.go
  • Consolidates MLS validation service initialization logic in server.go to trigger when either Indexer or Replication is enabled
  • Adds nil validation check for validationService parameter in NewReplicationApiService function in service.go
  • Moves golang.org/x/crypto from indirect to direct dependency in go.mod

📍Where to Start

Start with the NewClientManager function in clientManager.go which introduces the new Prometheus metrics functionality for gRPC client operations.


Macroscope summarized f65ddf7.

Summary by CodeRabbit

  • New Features

    • Integrated Prometheus-based client-side metrics collection for gRPC client connections in the payer API, enabling enhanced monitoring and observability.
  • Bug Fixes

    • Improved validation by preventing the creation of a replication API service without a valid validation service.
  • Chores

    • Updated dependencies and internal service initialization to ensure consistent metrics integration and validation handling across the application.

@mkysel mkysel requested a review from a team as a code owner April 22, 2025 17:30
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 22, 2025

Walkthrough

This set of changes introduces Prometheus client-side metrics collection to the gRPC client connections managed by the ClientManager in the payer API. It does so by extending constructors and internal logic to accept and propagate a *grpcprom.ClientMetrics instance, ensuring metrics interceptors are attached to gRPC connections. The payer API service constructor is updated to accept this new parameter, and all relevant instantiations in tests and server setup are adjusted accordingly. Additionally, a stricter nil check is added to the replication API service constructor, and the initialization logic for validationService in the server is refined to occur under broader conditions.

Changes

File(s) Change Summary
go.mod Moved golang.org/x/crypto from indirect to direct dependency.
pkg/api/message/service.go Added a nil check for validationService in NewReplicationApiService.
pkg/api/payer/clientManager.go Added clientMetrics field to ClientManager, updated constructor to accept it, and integrated Prometheus metrics interceptors into gRPC client connections.
pkg/api/payer/clientManager_test.go Updated tests to pass a Prometheus client metrics instance to NewClientManager.
pkg/api/payer/publish_test.go, pkg/testutils/api/api.go Updated test helpers to provide an additional (nil) argument to NewPayerApiService.
pkg/api/payer/service.go Updated NewPayerApiService to accept an optional clientMetrics parameter, defaulting to a new instance if nil, and passed it to ClientManager.
pkg/server/server.go Changed validationService initialization to occur if Indexer or Replication options are enabled, removed lazy initialization, and passed clientMetrics to NewPayerApiService.

Sequence Diagram(s)

sequenceDiagram
    participant Server
    participant PayerApiService
    participant ClientManager
    participant PrometheusMetrics

    Server->>PayerApiService: NewPayerApiService(..., clientMetrics)
    PayerApiService->>ClientManager: NewClientManager(..., clientMetrics)
    ClientManager->>PrometheusMetrics: Use Unary/Stream Interceptors
    ClientManager->>gRPC: BuildClient(with Prometheus interceptors)
Loading
sequenceDiagram
    participant Server
    participant ValidationService
    participant ReplicationApiService

    Server->>ValidationService: Initialize if Indexer or Replication enabled
    Server->>ReplicationApiService: NewReplicationApiService(validationService)
    ReplicationApiService->>ValidationService: Nil check (error if nil)
Loading

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a657935 and f65ddf7.

📒 Files selected for processing (8)
  • go.mod (1 hunks)
  • pkg/api/message/service.go (2 hunks)
  • pkg/api/payer/clientManager.go (3 hunks)
  • pkg/api/payer/clientManager_test.go (2 hunks)
  • pkg/api/payer/publish_test.go (1 hunks)
  • pkg/api/payer/service.go (2 hunks)
  • pkg/server/server.go (4 hunks)
  • pkg/testutils/api/api.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
pkg/api/payer/service.go (2)
pkg/api/payer/nodeCursorTracker.go (2)
  • MetadataApiClientConstructor (15-17)
  • DefaultMetadataApiClientConstructor (18-20)
pkg/api/payer/clientManager.go (1)
  • NewClientManager (29-40)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Code Review
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd-cli)
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd)
  • GitHub Check: Upgrade Tests
  • GitHub Check: Test (Node)
🔇 Additional comments (17)
go.mod (1)

23-23: Dependency moved to direct requirements.

The golang.org/x/crypto package was moved from indirect to direct dependencies, indicating it's now explicitly imported and used in the codebase.

pkg/api/message/service.go (1)

64-66: Good addition of nil validation check.

Adding this explicit check prevents potential nil pointer dereferences later when methods are called on the validation service (e.g., in validateKeyPackage). This defensive programming practice improves code robustness and error clarity.

pkg/testutils/api/api.go (1)

158-158: Updated constructor call for client metrics support.

Added nil as the last parameter to match the updated signature of NewPayerApiService, which now accepts a client metrics parameter.

pkg/api/payer/publish_test.go (1)

88-88: Updated constructor call for client metrics parameter.

Added nil parameter to match the updated signature of NewPayerApiService, consistent with the PR objectives to add Prometheus client metrics support.

pkg/api/payer/clientManager_test.go (2)

9-10: New import for Prometheus metrics added correctly.

The import for the Prometheus client metrics package is properly added to support the extended constructor parameters.


41-41: Test updated correctly to use Prometheus metrics.

The NewClientManager constructor call is properly updated to include the new prometheus.NewClientMetrics() parameter, ensuring the test works with the new metrics functionality.

pkg/server/server.go (3)

119-129: Good improvement to validationService initialization logic.

The condition for initializing validationService has been expanded to trigger when either Indexer or Replication is enabled, which is a logical enhancement. The service is now correctly passed the clientMetrics parameter to support Prometheus metrics collection.


131-141: Indexer initialization properly isolated.

The Indexer-specific initialization is now correctly isolated to only run when the Indexer option is enabled, which is cleaner than the previous implementation.


273-273: Prometheus metrics properly integrated with PayerApiService.

The clientMetrics parameter is now correctly passed to the payer service constructor, enabling metrics collection for the payer API's gRPC client connections.

pkg/api/payer/clientManager.go (4)

6-7: Prometheus client metrics import correctly added.

Import statement for the Prometheus client metrics package is properly added to support the metrics integration.


26-26: ClientManager struct enhanced with metrics support.

The ClientManager struct is correctly extended with a clientMetrics field to store the Prometheus metrics instance.


29-39: Constructor updated to support metrics collection.

The NewClientManager constructor is properly updated to accept and store a Prometheus clientMetrics parameter, enabling metrics collection for all client connections managed by this instance.


76-79: gRPC interceptors correctly added for metrics collection.

The client connection builder now correctly includes unary and stream interceptors for Prometheus metrics collection, which will provide valuable insights into client-side gRPC performance and behavior.

pkg/api/payer/service.go (4)

8-9: Prometheus import correctly added to service.

The import for the Prometheus client metrics package is properly added to support metrics integration at the service level.


50-51: Service constructor updated to support metrics.

The NewPayerApiService constructor is correctly extended to accept a clientMetrics parameter, enabling metrics collection for the payer API service.


52-55: Appropriate fallback for metrics parameter.

The null check and default initialization for clientMetrics ensures that the service will always have metrics capabilities, even when the parameter is not explicitly provided. This is good defensive programming.


57-57: Metrics properly propagated to ClientManager.

The clientMetrics parameter is correctly passed to the ClientManager constructor, ensuring metrics collection for all client connections created by the service.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for this 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.

@mkysel mkysel changed the title More Payer metrics and only one MLS service constructor Add Prometheus metrics to Payer gRPC client operations and consolidate MLS validation service initialization Apr 22, 2025
@mkysel mkysel enabled auto-merge (squash) April 22, 2025 17:40
@mkysel mkysel merged commit 6022791 into main Apr 22, 2025
8 checks passed
@mkysel mkysel deleted the mkysel/more-metrics branch April 22, 2025 19:13
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