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 add channel buffer per subscription and metrics #1687

Merged
merged 8 commits into from
Jun 12, 2024

Conversation

jonfung-dydx
Copy link
Contributor

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

Adds a channel buffer per subscription so that the full node won't stall on laggy connections.

Also adds fine-grained metrics.

Screenshot 2024-06-12 at 3 32 15 PM

Summary by CodeRabbit

  • New Features

    • Added new branch pattern triggers for workflows to include jonfung/**.
  • Updates

    • Renamed gRPC metrics and added new metrics for better monitoring.
    • Enhanced gRPC streaming manager to handle updates through channels with improved buffering and error handling.
  • Refactor

    • Renamed GrpcStreamingMaxBufferSize to GrpcStreamingMaxBatchSize and introduced GrpcStreamingMaxChannelBufferSize in configuration and validation.
  • Tests

    • Updated test cases to reflect new flag names and values.

@jonfung-dydx jonfung-dydx requested a review from jayy04 June 12, 2024 19:32
Copy link
Contributor

coderabbitai bot commented Jun 12, 2024

Walkthrough

The recent changes encompass updates to workflow triggers, metrics, and gRPC streaming management. Workflow files now include triggers for branches matching jonfung/**. Metrics in metric_keys.go have been revised, including renaming and adding new metrics. The gRPC streaming manager has been enhanced with new fields and constants to improve subscription handling. Additionally, the Flags struct and associated functions have been updated to reflect new buffer size parameters, ensuring more robust and configurable streaming management.

Changes

File Path Change Summary
.github/workflows/protocol-build-and-push-snapshot.yml, .github/workflows/protocol-build-and-push.yml Added new trigger for branches matching jonfung/**
protocol/lib/metrics/metric_keys.go Updated gRPC metrics: replaced GrpcEmitProtocolUpdateCount with GrpcAddUpdateToBufferCount, added GrpcAddToSubscriptionChannelCount, and introduced GrpcSubscriptionChannelLength
protocol/streaming/grpc/grpc_streaming_manager.go Added MAX_BUFF_LEN constant, subscriptionId and updatesChannel fields to OrderbookSubscription, and updated subscription handling logic
protocol/app/app.go Changed parameter in getGrpcStreamingManagerFromOptions to GrpcStreamingMaxChannelBufferSize from GrpcStreamingMaxBufferSize
protocol/app/flags/flags.go Renamed GrpcStreamingMaxBufferSize to GrpcStreamingMaxBatchSize, added GrpcStreamingMaxChannelBufferSize, and updated related functions and validations
protocol/app/flags/flags_test.go Adjusted tests for renamed and new flags: GrpcStreamingMaxBatchSize and GrpcStreamingMaxChannelBufferSize

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Workflow
    participant Metrics
    participant gRPC Manager

    Client->>Workflow: Push to jonfung/*
    Workflow-->>Client: Trigger build and push

    Client->>gRPC Manager: Subscribe to updates
    gRPC Manager->>Metrics: Increment GrpcAddToSubscriptionChannelCount
    gRPC Manager->>gRPC Manager: Buffer updates in updatesChannel

    Metrics->>gRPC Manager: Track GrpcSubscriptionChannelLength
    gRPC Manager->>Client: Send buffered updates
Loading

Poem

In the land of code and streams,
New triggers dance on branches' dreams,
Metrics shift, they count anew,
Buffers grow, for updates true.
Flags wave high, with values bright,
Streaming flows, both day and night.
Celebrate, the rabbit's cheer,
For changes bring the future near! 🐇✨


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.

@@ -6,6 +6,8 @@ on: # yamllint disable-line rule:truthy
- main
- 'release/protocol/v[0-9]+.[0-9]+.x' # e.g. release/protocol/v0.1.x
- 'release/protocol/v[0-9]+.x' # e.g. release/protocol/v1.x
- 'jonfung/**' # e.g. jonfung/hi
Copy link
Contributor

Choose a reason for hiding this comment

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

remove later

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2446abf and ef874ab.

Files selected for processing (4)
  • .github/workflows/protocol-build-and-push-snapshot.yml (1 hunks)
  • .github/workflows/protocol-build-and-push.yml (1 hunks)
  • protocol/lib/metrics/metric_keys.go (1 hunks)
  • protocol/streaming/grpc/grpc_streaming_manager.go (11 hunks)
Additional comments not posted (7)
protocol/lib/metrics/metric_keys.go (3)

72-72: The new metric GrpcAddUpdateToBufferCount is well-named and follows the existing naming conventions. Good job on maintaining consistency.


73-73: The metric GrpcAddToSubscriptionChannelCount is appropriately named and aligns with the module's naming standards.


78-78: The metric GrpcSubscriptionChannelLength is a useful addition for monitoring the length of the subscription channel. This should help in identifying bottlenecks or potential overflow issues.

.github/workflows/protocol-build-and-push.yml (1)

9-9: Adding the branch pattern jonfung/** expands the conditions under which the workflow is triggered. Ensure that this is intended and that it won't lead to unintended builds or resource wastage.

Verification successful

The search for the branch pattern jonfung/** did not yield any relevant results in the workflow files or elsewhere in the repository, except for a comment in a test file. This suggests that the pattern is not used elsewhere and is likely intended to be isolated to the specified workflow file.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of the new branch pattern in other workflow files.

# Test: Search for the branch pattern usage. Expect: Consistent usage across workflow files.
rg --type yaml $'jonfung/**'

Length of output: 29



Script:

#!/bin/bash
# Description: Verify the usage of the new branch pattern in all files.

# Test: Search for the branch pattern usage across all files. Expect: Consistent usage or isolated to the specified workflow file.
rg 'jonfung/**'

Length of output: 133

.github/workflows/protocol-build-and-push-snapshot.yml (1)

9-10: The addition of the jonfung/** branch pattern here mirrors the change in the other workflow file. This consistency is good, but as previously mentioned, ensure it's intended to avoid unnecessary builds.

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

Line range hint 47-59: The addition of subscriptionId and updatesChannel to OrderbookSubscription is crucial for managing individual subscriptions effectively. Ensure proper synchronization mechanisms are in place to handle concurrent access to these channels.


168-177: The error handling for failed message sends is robust, logging the error and removing the subscription. This should help maintain the stability of the streaming service under failure conditions.

@@ -17,6 +17,11 @@ import (

var _ types.GrpcStreamingManager = (*GrpcStreamingManagerImpl)(nil)

const (
// TODO CHANGE THIS CONFIGURABLE
MAX_BUFF_LEN = 1000
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The search results indicate that MAX_BUFF_LEN is currently hard-coded and there is a TODO comment suggesting that it should be made configurable. However, there is no existing configuration or documentation justifying the value of 1000.

  • protocol/streaming/grpc/grpc_streaming_manager.go: const (
    • // TODO CHANGE THIS CONFIGURABLE
    • MAX_BUFF_LEN = 1000

This confirms that the value is not yet configurable and lacks justification.

Analysis chain

Setting MAX_BUFF_LEN to 1000 is a significant change. Ensure this value is configurable or justified by load testing, as hard-coded limits can lead to scalability issues.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify if `MAX_BUFF_LEN` is configurable or justified.

# Test: Search for configuration options related to `MAX_BUFF_LEN`. Expect: Configurable options or documentation justifying the value.
rg --type go $'MAX_BUFF_LEN'

Length of output: 217



Script:

#!/bin/bash
# Description: Verify if `MAX_BUFF_LEN` is configurable or justified.

# Test 1: Search for configuration files or environment variables related to `MAX_BUFF_LEN`.
rg 'MAX_BUFF_LEN' --type toml --type yaml --type json
rg 'MAX_BUFF_LEN' --type sh

# Test 2: Search for comments or documentation justifying the value of `MAX_BUFF_LEN`.
rg 'MAX_BUFF_LEN' --type go --context 5

Length of output: 1808

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/app/app.go (6)

Line range hint 381-381: The function initDatadogProfiler is undefined. Ensure that it is implemented or imported correctly.


Line range hint 383-383: The function GetEncodingConfig is undefined. Ensure that it is implemented or imported correctly.


Line range hint 498-498: The variable maccPerms is undefined. Ensure that it is declared or imported correctly.


Line range hint 507-507: The method MsgServiceRouter is undefined for the type *App. Ensure that it is declared correctly in the App struct.

Also applies to: 607-607, 652-652


Line range hint 515-515: The function BlockedAddresses is undefined. Ensure that it is implemented or imported correctly.


Line range hint 774-774: The method Logger or GRPCQueryRouter is undefined for the type *App. Ensure that these methods are declared correctly in the App struct.

Also applies to: 1379-1379, 1385-1385

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ef874ab and 2516ca1.

Files selected for processing (4)
  • protocol/app/app.go (1 hunks)
  • protocol/app/flags/flags.go (7 hunks)
  • protocol/app/flags/flags_test.go (5 hunks)
  • protocol/streaming/grpc/grpc_streaming_manager.go (10 hunks)
Files skipped from review as they are similar to previous changes (1)
  • protocol/streaming/grpc/grpc_streaming_manager.go
Additional context used
golangci-lint
protocol/app/app.go

381-381: undefined: initDatadogProfiler (typecheck)


383-383: undefined: GetEncodingConfig (typecheck)


498-498: undefined: maccPerms (typecheck)


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


515-515: undefined: BlockedAddresses (typecheck)


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


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


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


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


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

Additional comments not posted (9)
protocol/app/flags/flags.go (6)

24-27: The addition of new flags for gRPC streaming configuration is clear and well-structured.


44-47: The new constants for gRPC streaming flags are consistent with existing naming conventions.


60-63: The default values for the new gRPC streaming flags are appropriately set.


105-112: The new flags are correctly added to the command with clear descriptions and default values.


133-141: The validation logic for the new gRPC streaming flags is robust, ensuring that all values are positive.


219-227: The logic to retrieve and cast the new gRPC streaming flag values from options is correctly implemented.

protocol/app/flags/flags_test.go (3)

38-42: The tests correctly verify the presence of the new gRPC streaming flags in the command.


Line range hint 75-127: The validation tests for the new gRPC streaming flags are comprehensive, covering a range of scenarios to ensure robustness.


Line range hint 147-244: The tests for retrieving gRPC streaming flag values from options are thorough and effectively validate the functionality.

Comment on lines +1961 to +1962
appFlags.GrpcStreamingMaxBatchSize,
appFlags.GrpcStreamingMaxChannelBufferSize,
Copy link
Contributor

Choose a reason for hiding this comment

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

The GrpcStreamingManager constructor is called with incorrect parameters.

- return streaming.NewGrpcStreamingManager(
-     logger,
-     appFlags.GrpcStreamingFlushIntervalMs,
-     appFlags.GrpcStreamingMaxBatchSize,
-     appFlags.GrpcStreamingMaxChannelBufferSize,
- )
+ return streaming.NewGrpcStreamingManager(
+     logger,
+     time.Duration(appFlags.GrpcStreamingFlushIntervalMs) * time.Millisecond, // Ensure time duration is correctly formatted
+     appFlags.GrpcStreamingMaxBatchSize,
+     appFlags.GrpcStreamingMaxChannelBufferSize,
+ )
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
appFlags.GrpcStreamingMaxBatchSize,
appFlags.GrpcStreamingMaxChannelBufferSize,
return streaming.NewGrpcStreamingManager(
logger,
time.Duration(appFlags.GrpcStreamingFlushIntervalMs) * time.Millisecond, // Ensure time duration is correctly formatted
appFlags.GrpcStreamingMaxBatchSize,
appFlags.GrpcStreamingMaxChannelBufferSize,
)

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