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

Full Node Streaming Recurring snapshots #2079

Merged
merged 2 commits into from
Aug 13, 2024
Merged

Conversation

jonfung-dydx
Copy link
Contributor

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

  • used to help debug streams
  • emit snapshots every X blocks after initial snapshot

Summary by CodeRabbit

  • New Features

    • Expanded workflow triggers to include branches starting with jonfung/, enhancing deployment flexibility.
    • Introduced configurable snapshot intervals for orderbook updates, improving data handling efficiency.
  • Bug Fixes

    • Addressed validation issues related to the new snapshot interval configuration.
  • Documentation

    • Updated comments to reflect enhancements and configurations related to snapshot management.

Copy link
Contributor

coderabbitai bot commented Aug 12, 2024

Walkthrough

This update enhances the GitHub Actions workflows by adding triggers for branches prefixed with jonfung/, allowing more flexible deployments. Additionally, it introduces configurable snapshot intervals in the streaming manager, optimizing orderbook updates. Together, these changes improve the responsiveness and manageability of the protocol's operations.

Changes

Files Change Summary
.github/workflows/protocol-build-and-push.yml
.github/workflows/protocol-build-and-push-snapshot.yml
Added branch pattern jonfung/** to trigger workflows on new development branches, enhancing deployment flexibility.
protocol/app/app.go Enhanced logging in getFullNodeStreamingManagerFromOptions to include new snapshot interval configuration.
protocol/app/flags/flags.go Introduced FullNodeStreamingSnapshotInterval to control snapshot intervals, including validation logic and default values.
protocol/app/flags/flags_test.go Updated test cases to cover the new flag for snapshot intervals, ensuring proper validation and retrieval functionality.
protocol/streaming/full_node_streaming_manager.go Enhanced FullNodeStreamingManagerImpl and OrderbookSubscription with fields for configurable snapshot intervals, improving update efficiency.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant GitHub Actions
    participant AWS ECR
    participant Streaming Manager

    Developer->>GitHub Actions: Push to jonfung/** branch
    GitHub Actions->>AWS ECR: Build & Push Image
    GitHub Actions->>Streaming Manager: Initialize Streaming with new interval
    Streaming Manager-->>Streaming Manager: Set snapshotBlockInterval
    Streaming Manager->>OrderbookSubscription: Emit Snapshots
Loading

Poem

🐇 In fields of code, where changes bloom,
New branches sprout, dispelling gloom.
With snapshots sent at intervals fair,
The protocol dances, light as air!
Hops of joy, in updates we trust,
For every push, a leap, a gust! 🌱✨


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 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
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 6e5673e and 6a39c22.

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/app/app.go (1 hunks)
  • protocol/streaming/full_node_streaming_manager.go (7 hunks)
Additional comments not posted (11)
.github/workflows/protocol-build-and-push.yml (1)

6-6: Branch pattern jonfung/** added to workflow triggers.

This addition allows the workflow to trigger on branches prefixed with jonfung/, enhancing flexibility for development and testing.

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

6-6: Branch pattern jonfung/** added to workflow triggers.

This addition allows the workflow to trigger on branches prefixed with jonfung/, enhancing flexibility for development and testing.

protocol/streaming/full_node_streaming_manager.go (8)

51-51: New field snapshotBlockInterval added to FullNodeStreamingManagerImpl.

This field allows configuration of block intervals for emitting snapshots, improving control over data streaming.


59-59: New field initialize added to OrderbookSubscription.

The sync.Once instance ensures that initialization logic runs only once, unless reset, enhancing control over subscription initialization.


75-75: New field snapshotDelayBlock added to OrderbookSubscription.

This field tracks the block height for initial snapshots, adjusted by snapshotBlockInterval, enabling precise snapshot timing.


83-83: Updated constructor NewFullNodeStreamingManager to accept snapshotBlockInterval.

This change ensures that the streaming manager can be initialized with the new snapshot interval functionality.


100-100: Initialization of snapshotBlockInterval in NewFullNodeStreamingManager.

The constructor correctly initializes the new field, ensuring the snapshot interval is set upon manager creation.


163-163: Use of sync.Once in Subscribe method.

The sync.Once instance is initialized for each subscription, ensuring that initialization logic is executed only once per subscription.


691-697: Resetting sync.Once based on snapshotBlockInterval.

This logic ensures that snapshots are re-sent at specified intervals, enhancing the responsiveness of orderbook updates.


714-716: Setting snapshotDelayBlock after sending snapshots.

This logic updates the snapshotDelayBlock to track the block height modulo the snapshot interval, maintaining correct snapshot timing.

protocol/app/app.go (1)

2033-2034: Consider making the hardcoded value configurable.

The hardcoded value 50 should be replaced with a configurable option to enhance flexibility and maintainability. The TODO comment already suggests this improvement.

-			50,
+			appFlags.YourConfigurableOption,

Ensure that the configuration option is properly defined and documented.

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 6a39c22 and cbc94e6.

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/app/app.go (1 hunks)
  • protocol/streaming/full_node_streaming_manager.go (7 hunks)
Files skipped from review as they are similar to previous changes (4)
  • .github/workflows/protocol-build-and-push-snapshot.yml
  • .github/workflows/protocol-build-and-push.yml
  • protocol/app/app.go
  • protocol/streaming/full_node_streaming_manager.go

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

Outside diff range, codebase verification and nitpick comments (3)
protocol/app/flags/flags.go (3)

28-28: Add documentation for the new field.

Consider adding a comment to explain the purpose of FullNodeStreamingSnapshotInterval in the Flags struct for better maintainability.

// Interval for emitting snapshots in full node streaming.
FullNodeStreamingSnapshotInterval uint32

51-51: Ensure consistency in naming conventions.

The constant FullNodeStreamingSnapshotInterval should follow the naming pattern of other constants, such as prefixing with Flag for clarity.

- FullNodeStreamingSnapshotInterval = "fns-snapshot-interval"
+ FlagFullNodeStreamingSnapshotInterval = "fns-snapshot-interval"

71-71: Clarify the default value's purpose.

Consider adding a comment to explain why the default value for FullNodeStreamingSnapshotInterval is 0, indicating the behavior of sending one initial snapshot.

// Default value for snapshot interval, 0 means one initial snapshot.
DefaultFullNodeStreamingSnapshotInterval = 0
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cbc94e6 and 48a297c.

Files selected for processing (4)
  • protocol/app/app.go (1 hunks)
  • protocol/app/flags/flags.go (7 hunks)
  • protocol/app/flags/flags_test.go (8 hunks)
  • protocol/streaming/full_node_streaming_manager.go (7 hunks)
Files skipped from review as they are similar to previous changes (2)
  • protocol/app/app.go
  • protocol/streaming/full_node_streaming_manager.go
Additional comments not posted (10)
protocol/app/flags/flags.go (3)

123-128: LGTM! Ensure correct flag registration.

The registration of FullNodeStreamingSnapshotInterval in AddFlagsToCmd looks good. Ensure that the flag is correctly parsed and utilized elsewhere in the application.


167-169: Ensure error message clarity.

The error message in the validation logic is clear and informative, ensuring that users understand the constraint on FullNodeStreamingSnapshotInterval.


194-194: Verify retrieval logic.

The retrieval of FullNodeStreamingSnapshotInterval in GetFlagValuesFromOptions is consistent with other flags. Ensure that this value is correctly used in the application logic.

Verification successful

Retrieval and Usage of FullNodeStreamingSnapshotInterval Verified

The FullNodeStreamingSnapshotInterval is consistently retrieved and used across the application logic. It is checked and utilized in app.go, and its behavior is validated through tests in flags_test.go. No issues found with its integration.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `FullNodeStreamingSnapshotInterval` in the application logic.

# Test: Search for the usage of `FullNodeStreamingSnapshotInterval`. Expect: Correct usage in logic handling.
rg --type go $'FullNodeStreamingSnapshotInterval'

Length of output: 1933

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

41-43: LGTM! Test coverage for flag registration.

The addition of FullNodeStreamingSnapshotInterval to TestAddFlagsToCommand ensures that the flag is correctly registered. This test coverage is appropriate.


66-72: LGTM! Default values in validation tests.

The inclusion of FullNodeStreamingSnapshotInterval in the default values test case ensures that the default behavior is correctly validated.


152-163: LGTM! Validation error test case.

The test case for invalid FullNodeStreamingSnapshotInterval values correctly checks the enforcement of the minimum threshold, ensuring robustness.


164-174: LGTM! Validation success test case.

The test case for a valid FullNodeStreamingSnapshotInterval value of 50 ensures that the application logic correctly handles valid configurations.


Line range hint 203-216:
LGTM! Retrieval test for default values.

The test case Sets to default if unset correctly verifies that FullNodeStreamingSnapshotInterval defaults to 0 when not set, ensuring expected behavior.


Line range hint 230-242:
LGTM! Retrieval test for set values.

The test case Sets values from options verifies that FullNodeStreamingSnapshotInterval is correctly retrieved from options, ensuring accurate configuration handling.


296-300: LGTM! Retrieval assertion for new flag.

The assertion for FullNodeStreamingSnapshotInterval in TestGetFlagValuesFromOptions ensures that the retrieved value matches the expected configuration.

@jonfung-dydx jonfung-dydx merged commit 14fffa4 into main Aug 13, 2024
17 of 18 checks passed
@jonfung-dydx jonfung-dydx deleted the jonfung/fns_recur_snapshot branch August 13, 2024 20:51
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.

3 participants