Skip to content

Conversation

@mkysel
Copy link
Collaborator

@mkysel mkysel commented Apr 21, 2025

Add Prometheus metrics collection to MLS validation service client and server gRPC calls to expose method invocation statistics

Implements Prometheus metrics collection for gRPC client operations in two key areas:

  • Adds gRPC interceptors for metrics collection in service.go by integrating grpcprom.ClientMetrics into the MLS validation service client
  • Configures server-side metrics handling in server.go by initializing and registering Prometheus client metrics, then passing them through the NewReplicationServer and startAPIServer functions

📍Where to Start

Start with the NewMlsValidationService function in service.go which shows how the Prometheus metrics interceptors are integrated into the gRPC client connection.


Macroscope summarized 00eb28c.

Summary by CodeRabbit

  • New Features

    • Integrated Prometheus-based monitoring for gRPC client calls, enabling enhanced metrics collection and observability for MLS validation and replication services.
  • Chores

    • Updated internal service initialization to support metrics instrumentation where applicable.

@mkysel mkysel requested a review from a team as a code owner April 21, 2025 19:59
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 21, 2025

Walkthrough

The changes integrate Prometheus-based gRPC client metrics collection into the MLS validation service and related server setup. The constructor for the MLS validation service now accepts a gRPC client metrics parameter, which is used to add monitoring interceptors to gRPC client connections. The server initialization logic creates and registers a new Prometheus gRPC client metrics collector when metrics are enabled, and this collector is passed to the MLS validation service and API server functions. No other logic or control flow is modified.

Changes

File(s) Change Summary
pkg/mlsvalidate/service.go Modified NewMlsValidationService to accept a *grpcprom.ClientMetrics parameter and use it for gRPC interceptors.
pkg/server/server.go Created and registered a Prometheus gRPC client metrics collector; passed it to MLS validation service and API server; updated related function signatures.

Sequence Diagram(s)

sequenceDiagram
    participant Prometheus
    participant Server
    participant MetricsCollector
    participant MLSValidationService
    participant gRPCClient

    Server->>MetricsCollector: Create grpcprom.ClientMetrics
    MetricsCollector->>Prometheus: Register collector (if enabled)
    Server->>MLSValidationService: Initialize with clientMetrics
    MLSValidationService->>gRPCClient: Setup with Prometheus interceptors
    gRPCClient-->>Prometheus: Report client metrics during RPC calls
Loading

Suggested reviewers

  • fbac

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

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 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 8d7da8f and 00eb28c.

📒 Files selected for processing (2)
  • pkg/mlsvalidate/service.go (3 hunks)
  • pkg/server/server.go (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd-cli)
  • GitHub Check: Push Docker Images to GitHub Packages (xmtpd)
  • GitHub Check: Test (Node)
  • GitHub Check: Upgrade Tests
  • GitHub Check: Code Review
🔇 Additional comments (7)
pkg/mlsvalidate/service.go (3)

7-8: Clean import addition for Prometheus gRPC metrics.

Good job adding the Prometheus gRPC metrics provider to enable instrumentation of the MLS validation service.


29-29: Constructor parameter addition looks good.

The addition of the clientMetrics parameter to the constructor follows good practices for dependency injection, allowing the metrics collection to be configured externally.


49-50: Well-integrated Prometheus interceptors.

The implementation correctly adds both unary and streaming interceptors to the gRPC client connection, which will capture metrics for all MLS validation service method calls including GetAssociationState, ValidateKeyPackages, and ValidateGroupMessages.

pkg/server/server.go (4)

18-18: Clean import addition for Prometheus gRPC metrics.

Good job adding the Prometheus gRPC metrics provider to enable instrumentation.


74-76: Good Prometheus client metrics configuration.

The implementation correctly initializes the Prometheus client metrics collector with histogram support, which is essential for tracking latency distributions as required.


82-82: Proper metrics registration.

The client metrics are correctly registered with the Prometheus registry when metrics are enabled.


124-124: Consistent metrics parameter propagation.

The clientMetrics parameter is consistently passed to all relevant components and functions that need it, ensuring uniform instrumentation throughout the codebase.

This implementation addresses the reviewer's question about handling metrics through a Prometheus client interceptor, as it uses the standard gRPC interceptor pattern to instrument all RPC calls automatically.

Also applies to: 154-154, 192-192, 203-203

✨ 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
Copy link
Collaborator Author

mkysel commented Apr 21, 2025

# HELP grpc_client_handling_seconds Histogram of response latency (seconds) of the gRPC until it is finished by the application.
# TYPE grpc_client_handling_seconds histogram
grpc_client_handling_seconds_bucket{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="0.005"} 6
grpc_client_handling_seconds_bucket{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="0.01"} 6
grpc_client_handling_seconds_bucket{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="0.025"} 6
grpc_client_handling_seconds_bucket{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="0.05"} 6
grpc_client_handling_seconds_bucket{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="0.1"} 6
grpc_client_handling_seconds_bucket{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="0.25"} 6
grpc_client_handling_seconds_bucket{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="0.5"} 6
grpc_client_handling_seconds_bucket{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="1"} 6
grpc_client_handling_seconds_bucket{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="2.5"} 6
grpc_client_handling_seconds_bucket{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="5"} 6
grpc_client_handling_seconds_bucket{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="10"} 6
grpc_client_handling_seconds_bucket{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="+Inf"} 6
grpc_client_handling_seconds_sum{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary"} 0.008468042
grpc_client_handling_seconds_count{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary"} 6
grpc_client_handling_seconds_bucket{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="0.005"} 1
grpc_client_handling_seconds_bucket{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="0.01"} 1
grpc_client_handling_seconds_bucket{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="0.025"} 6
grpc_client_handling_seconds_bucket{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="0.05"} 6
grpc_client_handling_seconds_bucket{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="0.1"} 6
grpc_client_handling_seconds_bucket{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="0.25"} 6
grpc_client_handling_seconds_bucket{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="0.5"} 6
grpc_client_handling_seconds_bucket{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="1"} 6
grpc_client_handling_seconds_bucket{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="2.5"} 6
grpc_client_handling_seconds_bucket{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="5"} 6
grpc_client_handling_seconds_bucket{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="10"} 6
grpc_client_handling_seconds_bucket{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary",le="+Inf"} 6
grpc_client_handling_seconds_sum{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary"} 0.10363174900000001
grpc_client_handling_seconds_count{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary"} 6
# HELP grpc_client_msg_received_total Total number of RPC stream messages received by the client.
# TYPE grpc_client_msg_received_total counter
grpc_client_msg_received_total{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary"} 6
grpc_client_msg_received_total{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary"} 6
# HELP grpc_client_msg_sent_total Total number of gRPC stream messages sent by the client.
# TYPE grpc_client_msg_sent_total counter
grpc_client_msg_sent_total{grpc_method="GetAssociationState",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary"} 6
grpc_client_msg_sent_total{grpc_method="ValidateInboxIdKeyPackages",grpc_service="xmtp.mls_validation.v1.ValidationApi",grpc_type="unary"} 6

@mkysel mkysel requested a review from a team as a code owner April 21, 2025 20:02
Copy link
Contributor

@neekolas neekolas left a comment

Choose a reason for hiding this comment

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

I’m a little worried that namespacing this as “mls” instead of something like “validation service” is going to get confusing. We do a lot of things around “mls” and the term might be overloaded.

@mkysel mkysel force-pushed the mkysel/mls-stats branch from f24a6a3 to 00eb28c Compare April 21, 2025 21:21
@mkysel mkysel requested a review from neekolas April 21, 2025 21:23
@mkysel
Copy link
Collaborator Author

mkysel commented Apr 21, 2025

@neekolas I've redone this with just using the vanilla client GRPC interceptor. Its much better this way

Copy link
Contributor

Happy to help. Does look much tidier this way

@mkysel mkysel merged commit 25c7dd3 into main Apr 21, 2025
8 checks passed
@mkysel mkysel deleted the mkysel/mls-stats branch April 21, 2025 21:28
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