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

Grpc Streaming Metrics #1616

Merged
merged 2 commits into from
Jun 3, 2024
Merged

Grpc Streaming Metrics #1616

merged 2 commits into from
Jun 3, 2024

Conversation

jonfung-dydx
Copy link
Contributor

@jonfung-dydx jonfung-dydx commented Jun 3, 2024

Adds metrics on:

  • rate of stream updates
  • rate of update emissions through subscritions
  • total number of connections

Summary by CodeRabbit

  • New Features

    • Introduced enhanced metrics tracking for gRPC operations, including updates and subscriber counts.
    • Added logging capabilities to the gRPC Streaming Manager for better monitoring and debugging.
  • Refactor

    • Streamlined the process of sending order book updates by introducing a new method to handle stream updates.
  • Improvements

    • Enhanced the Subscribe() method to update metrics, improving visibility into subscription activities.

Copy link
Contributor

coderabbitai bot commented Jun 3, 2024

Walkthrough

The recent changes enhance the gRPC streaming functionality by integrating a logger into the GrpcStreamingManagerImpl struct, improving metrics tracking, and refactoring methods for better organization. These updates ensure more robust logging, detailed metrics, and streamlined code for managing gRPC streams and order book updates.

Changes

File Path Summary
protocol/app/app.go Added logger parameter to getGrpcStreamingManagerFromOptions function.
protocol/lib/metrics/metric_keys.go Added new gRPC-related metrics while maintaining existing ones.
protocol/streaming/grpc/grpc_streaming_manager.go Integrated logger, added EmitMetrics method, refactored methods for better organization and metrics tracking.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant Client
    participant App
    participant GrpcStreamingManager
    participant Logger
    participant Metrics

    Client->>App: Enable gRPC Streaming
    App->>GrpcStreamingManager: Create instance with Logger
    GrpcStreamingManager->>Logger: Initialize Logger
    Client->>GrpcStreamingManager: Subscribe to Stream
    GrpcStreamingManager->>Metrics: Emit Metrics
    Client->>GrpcStreamingManager: Send Orderbook Updates
    GrpcStreamingManager->>GrpcStreamingManager: Call sendStreamUpdate
    GrpcStreamingManager->>Metrics: Track Metrics
    GrpcStreamingManager->>Logger: Log Update
    GrpcStreamingManager->>Client: Send Updates
    GrpcStreamingManager->>Metrics: Emit Metrics
Loading

Poem

In the world of streams and logs,
A rabbit hops through code and fogs.
With metrics bright and logger's light,
It tracks the data, day and night.
Refactored paths, updates so keen,
In gRPC's realm, it's the coding queen.
🐇✨📊


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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
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

Outside diff range and nitpick comments (6)
protocol/streaming/grpc/grpc_streaming_manager.go (1)

[!TIP]
Codebase Verification

The sendStreamUpdate method contains error handling for the Send operation, but there is no detailed error logging to aid in debugging issues related to stream updates.

  • Consider adding more detailed error logging within the sendStreamUpdate method to improve debugging capabilities.
Analysis chain

Line range hint 179-225: The sendStreamUpdate method efficiently handles the distribution of updates to subscribers and correctly increments the GrpcEmitProtocolUpdateCount and GrpcSendResponseToSubscriberCount metrics. However, ensure that error handling is robust, especially in scenarios where Send might fail.

Consider adding more detailed error logging within the sendStreamUpdate method to aid in debugging issues related to stream updates.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify robust error handling in `sendStreamUpdate` method.

# Test: Search for error handling patterns in `sendStreamUpdate`. Expect: Proper error handling and logging.
rg --type go $'sendStreamUpdate' protocol/streaming/grpc/grpc_streaming_manager.go

Length of output: 279



Script:

#!/bin/bash
# Description: Verify robust error handling in `sendStreamUpdate` method.

# Test: Search for error handling patterns in `sendStreamUpdate`. Expect: Proper error handling and logging.
rg --type go 'sendStreamUpdate' -A 20 protocol/streaming/grpc/grpc_streaming_manager.go | rg 'err|log'

Length of output: 102



Script:

#!/bin/bash
# Description: Verify robust error handling in `sendStreamUpdate` method.

# Test: Search for error handling patterns and logging in the entire grpc_streaming_manager.go file.
rg --type go 'sendStreamUpdate' -A 50 protocol/streaming/grpc/grpc_streaming_manager.go | rg 'err|log'

Length of output: 157

protocol/app/app.go (5)

Line range hint 376-376: Undefined function initDatadogProfiler.

Please define the function initDatadogProfiler or ensure it is imported correctly.


Line range hint 378-378: Undefined function GetEncodingConfig.

Please define the function GetEncodingConfig or ensure it is imported correctly.


Line range hint 489-489: Undefined variable maccPerms.

Please define the variable maccPerms or ensure it is imported correctly.


Line range hint 498-498: Undefined method MsgServiceRouter.

Please ensure that the method MsgServiceRouter is defined in the App struct or correctly imported.


Line range hint 506-506: Undefined function BlockedAddresses.

Please define the function BlockedAddresses or ensure it is imported correctly.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e6b6683 and 080edca.

Files selected for processing (3)
  • protocol/app/app.go (1 hunks)
  • protocol/lib/metrics/metric_keys.go (1 hunks)
  • protocol/streaming/grpc/grpc_streaming_manager.go (9 hunks)
Additional context used
golangci-lint
protocol/app/app.go

376-376: undefined: initDatadogProfiler


378-378: undefined: GetEncodingConfig


489-489: undefined: maccPerms


498-498: app.MsgServiceRouter undefined (type *App has no field or method MsgServiceRouter)


506-506: undefined: BlockedAddresses


598-598: app.MsgServiceRouter undefined (type *App has no field or method MsgServiceRouter)


643-643: app.MsgServiceRouter undefined (type *App has no field or method MsgServiceRouter)


765-765: app.Logger undefined (type *App has no field or method Logger)


1356-1356: app.GRPCQueryRouter undefined (type *App has no field or method GRPCQueryRouter)


1362-1362: app.GRPCQueryRouter undefined (type *App has no field or method GRPCQueryRouter)


1365-1365: app.MountKVStores undefined (type *App has no field or method MountKVStores)


1366-1366: app.MountTransientStores undefined (type *App has no field or method MountTransientStores)


1367-1367: app.MountMemoryStores undefined (type *App has no field or method MountMemoryStores)


1370-1370: app.SetInitChainer undefined (type *App has no field or method SetInitChainer)


1372-1372: app.SetMempool undefined (type *App has no field or method SetMempool)


1373-1373: app.SetPreBlocker undefined (type *App has no field or method SetPreBlocker)


1374-1374: app.SetBeginBlocker undefined (type *App has no field or method SetBeginBlocker)


1375-1375: app.SetEndBlocker undefined (type *App has no field or method SetEndBlocker)


1376-1376: app.SetPrecommiter undefined (type *App has no field or method SetPrecommiter)


1377-1377: app.SetPrepareCheckStater undefined (type *App has no field or method SetPrepareCheckStater)


1381-1381: app.SetPrepareProposal undefined (type *App has no field or method SetPrepareProposal)


1382-1382: app.SetProcessProposal undefined (type *App has no field or method SetProcessProposal)


1392-1392: app.AddRunTxRecoveryHandler undefined (type *App has no field or method AddRunTxRecoveryHandler)


1395-1395: app.setupUpgradeHandlers undefined (type *App has no field or method setupUpgradeHandlers)


1396-1396: app.setupUpgradeStoreLoaders undefined (type *App has no field or method setupUpgradeStoreLoaders)


1403-1403: app.LoadLatestVersion undefined (type *App has no field or method LoadLatestVersion)


1411-1411: app.Logger undefined (type *App has no field or method Logger)


1430-1430: app.Logger undefined (type *App has no field or method Logger)


1564-1564: app.SetExtendVoteHandler undefined (type *App has no field or method SetExtendVoteHandler)


1565-1565: app.SetVerifyVoteExtensionHandler undefined (type *App has no field or method SetVerifyVoteExtensionHandler)


1573-1573: app.ChainID undefined (type *App has no field or method ChainID)


1650-1650: app.scheduleForkUpgrade undefined (type *App has no field or method scheduleForkUpgrade)


1694-1694: undefined: GenesisState


1716-1716: app.LoadVersion undefined (type *App has no field or method LoadVersion)


1796-1796: app.Query undefined (type *App has no field or method Query)


1802-1802: app.GRPCQueryRouter undefined (type *App has no field or method GRPCQueryRouter)


1812-1812: undefined: NewAnteHandler


1813-1813: undefined: HandlerOptions


1838-1838: app.SetAnteHandler undefined (type *App has no field or method SetAnteHandler, but does have setAnteHandler)

Additional comments not posted (6)
protocol/lib/metrics/metric_keys.go (1)

71-73: The new metric keys for gRPC operations are well-defined and follow the established naming conventions.

protocol/streaming/grpc/grpc_streaming_manager.go (5)

Line range hint 23-46: The addition of a logger field in GrpcStreamingManagerImpl and its initialization in NewGrpcStreamingManager enhances debugging capabilities and is a good use of dependency injection for better testability.


55-60: The EmitMetrics method correctly updates the GrpcStreamSubscriberCount metric based on the number of active subscriptions. This is a crucial metric for monitoring the usage of gRPC streams.


86-86: Calling EmitMetrics at the end of the Subscribe method ensures that metrics are updated immediately after a new subscription is added, which is good for real-time monitoring.


133-137: Refactoring the update sending logic into sendStreamUpdate in SendOrderbookUpdates method improves modularity and reusability of the code.


172-177: Using sendStreamUpdate in SendOrderbookFillUpdates ensures consistency in how updates are sent across different types of data, which is beneficial for maintaining a uniform interface for update dispatch.

@@ -1931,7 +1931,7 @@ func getGrpcStreamingManagerFromOptions(
) (manager streamingtypes.GrpcStreamingManager) {
if appFlags.GrpcStreamingEnabled {
logger.Info("GRPC streaming is enabled")
return streaming.NewGrpcStreamingManager()
return streaming.NewGrpcStreamingManager(logger)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper initialization of GrpcStreamingManager with logger.

- return streaming.NewGrpcStreamingManager(logger)
+ return streaming.NewGrpcStreamingManager(logger, someOtherNecessaryParams)

Committable suggestion was skipped due low confidence.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 080edca and 1b395f0.

Files selected for processing (1)
  • protocol/streaming/grpc/grpc_streaming_manager.go (9 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/streaming/grpc/grpc_streaming_manager.go

@jonfung-dydx jonfung-dydx requested a review from jayy04 June 3, 2024 14:58
@jonfung-dydx jonfung-dydx merged commit 230c44e into main Jun 3, 2024
18 checks passed
@jonfung-dydx jonfung-dydx deleted the jonfung/grpcStreamMetrics branch June 3, 2024 16:15
jonfung-dydx added a commit that referenced this pull request Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants