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

[Observables] chore: add ReplayObservable#SubscribeFromLatestBufferedOffset() #647

Merged
merged 13 commits into from
Jul 12, 2024

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Jul 2, 2024

Summary

Add ReplayObservable#SubscribeFromLatestBufferedOffset() to support finer control over replay observable subscriptions.

Issue

Type of change

Select one or more:

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Documentation
  • Other (specify)

Testing

Documentation changes (only if making doc changes)

  • make docusaurus_start; only needed if you make doc changes

Local Testing (only if making code changes)

  • Unit Tests: make go_develop_and_test
  • LocalNet E2E Tests: make test_e2e
  • See quickstart guide for instructions

PR Testing (only if making code changes)

  • DevNet E2E Tests: Add the devnet-test-e2e label to the PR.
    • THIS IS VERY EXPENSIVE, so only do it after all the reviews are complete.
    • Optionally run make trigger_ci if you want to re-trigger tests without any code changes
    • If tests fail, try re-running failed tests only using the GitHub UI as shown here

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have commented my code
  • I have performed a self-review of my own code; both comments & source code
  • I create and reference any new tickets, if applicable
  • I have left TODOs throughout the codebase, if applicable

Summary by CodeRabbit

  • New Features
    • Introduced a method to subscribe from a specified offset in the replay buffer, improving flexibility in data observation.
  • Tests
    • Added tests to verify the new subscription functionality from the latest buffered offset.

@bryanchriswhite bryanchriswhite added off-chain Off-chain business logic code health Cleans up some code labels Jul 2, 2024
@bryanchriswhite bryanchriswhite self-assigned this Jul 2, 2024
Copy link

coderabbitai bot commented Jul 2, 2024

Walkthrough

The changes introduce a method called SubscribeFromLatestBufferedOffset in the replayObservable struct, allowing observers to receive values starting from a specified buffer offset. Additionally, corresponding test cases are added to validate the new functionality. This modification provides enhanced control over how buffered values are replayed to subscribers.

Changes

File Change Summary
pkg/observable/channel/replay.go Added SubscribeFromLatestBufferedOffset method allowing subscriptions from a specific buffer offset.
pkg/observable/interface.go Updated the ReplayObservable interface to include the new method.
pkg/observable/channel/replay_test.go Added tests to verify the behavior of subscribing from a specified buffer offset.

Sequence Diagram(s)

sequenceDiagram
    participant Observer
    participant ReplayObservable
    participant Buffer

    Observer->>ReplayObservable: SubscribeFromLatestBufferedOffset(offset)
    ReplayObservable->>Buffer: Check Offset
    Buffer-->>ReplayObservable: Valid/Invalid Offset
    alt Valid Offset
        ReplayObservable->>Observer: Emit Buffered Values from Offset
        ReplayObservable->>Observer: Subscribe to New Values
    else Invalid Offset
        ReplayObservable->>Observer: Error or Emit All Buffered Values
        ReplayObservable->>Observer: Subscribe to New Values
    end
Loading

Possibly related issues

Poem

In code's vast and winding bay,
New methods guide the clever way.
From offset's where observers start,
To gather data smart by part.
Buffers yield their secrets stored,
With tests that vouch, we're all on board.
A rabbit cheers in joyful stance,
For changes made to code’s dance.


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

github-actions bot commented Jul 2, 2024

The CI will now also run the e2e tests on devnet, which increases the time it takes to complete all CI checks.

You may need to run make trigger_ci to submit an empty commit that'll trigger the tests.

GCP workloads (requires changing the namespace to 647)
Grafana network dashboard for devnet-issue-{issue-id}

@github-actions github-actions bot added devnet push-image CI related - pushes images to ghcr.io labels Jul 2, 2024
@bryanchriswhite bryanchriswhite linked an issue Jul 2, 2024 that may be closed by this pull request
6 tasks
Copy link

@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 aec367e and f65b1bf.

Files selected for processing (3)
  • pkg/observable/channel/replay.go (2 hunks)
  • pkg/observable/channel/replay_test.go (2 hunks)
  • pkg/observable/interface.go (1 hunks)
Additional comments not posted (5)
pkg/observable/interface.go (1)

14-22: LGTM!

The addition of the SubscribeFromLatestBufferedOffset method to the ReplayObservable interface is consistent and well-documented.

pkg/observable/channel/replay.go (2)

125-127: LGTM!

The update to the Subscribe method to use SubscribeFromLatestBufferedOffset is straightforward and aligns with the new functionality.


Line range hint 129-169: LGTM!

The SubscribeFromLatestBufferedOffset method is well-implemented. The logic ensures that the offset is within bounds and replays the values accordingly. The use of goroutines and context management is appropriate.

pkg/observable/channel/replay_test.go (2)

305-360: LGTM!

The TestReplayObservable_SubscribeFromLatestBufferedOffset test function is comprehensive and covers various scenarios. The use of the accumulateValues helper function is appropriate.


362-379: LGTM!

The accumulateValues helper function is well-implemented and aids in accumulating values from the observer.

@bryanchriswhite bryanchriswhite changed the title [Observables] chore: add ReplayObservable#SubscribeFromLatestBufferedOffset() [Observables] chore: add ReplayObservable#SubscribeFromLatestBufferedOffset() Jul 2, 2024
Copy link

@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 f65b1bf and 1ee0cdf.

Files selected for processing (3)
  • pkg/observable/channel/replay.go (1 hunks)
  • pkg/observable/channel/replay_test.go (2 hunks)
  • pkg/observable/interface.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • pkg/observable/channel/replay.go
  • pkg/observable/channel/replay_test.go
  • pkg/observable/interface.go

@bryanchriswhite bryanchriswhite removed push-image CI related - pushes images to ghcr.io devnet-test-e2e labels Jul 4, 2024
@github-actions github-actions bot removed the devnet label Jul 4, 2024
pkg/observable/interface.go Outdated Show resolved Hide resolved
pkg/observable/channel/replay_test.go Outdated Show resolved Hide resolved
pkg/observable/channel/replay_test.go Outdated Show resolved Hide resolved
name: "endOffset > replayBufferSize",
replayBufferSize: 8,
endOffset: 10,
expectedValues: values[2:],
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why this doesn't start at values[len(values)-1:]?

Copy link
Contributor Author

@bryanchriswhite bryanchriswhite Jul 5, 2024

Choose a reason for hiding this comment

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

It's values[len(values)-replayBufferSize].

// Published values
[ 1 2 3 4 5 ]

// Replay buffer
[ 5 4 3 2 1 ]

// SubscribeFromEndOffset(100)
[ 1 2 3 4 5 ]

// SubscribeFromLatestBufferedOffset(5)
[ 1 2 3 4 5 ]

// SubscribeFromLatestBufferedOffset(3)
[ 3 4 5 ]

pkg/observable/channel/replay.go Show resolved Hide resolved
for i := len(ro.replayBuffer) - 1; i >= 0; i-- {

// Ensure that the offset is within the bounds of the replay buffer.
if endOffset > len(ro.replayBuffer) {
Copy link
Member

Choose a reason for hiding this comment

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

This makes it a bit confusing if endOffset is number of elements from the start or the end of the buffer.

Should we PUC that "it points to the last element in the replayBuffer"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's an offset from the "latest buffered" value. I thought the name and godoc comment would make it sufficiently clear. I'm not sure I understand your suggestion; what is pointing to the last element in the replayBuffer? And by last do you mean "latest" or largest index?

bryanchriswhite and others added 2 commits July 5, 2024 23:38
Co-authored-by: Daniel Olshansky <olshansky.daniel@gmail.com>
Co-authored-by: Daniel Olshansky <olshansky.daniel@gmail.com>
Copy link

@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 1ee0cdf and 27a0d00.

Files selected for processing (3)
  • pkg/observable/channel/replay.go (1 hunks)
  • pkg/observable/channel/replay_test.go (2 hunks)
  • pkg/observable/interface.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • pkg/observable/channel/replay_test.go
Additional context used
golangci-lint
pkg/observable/interface.go

19-19: File is not goimports-ed

(goimports)

pkg/observable/channel/replay.go

133-133: File is not goimports-ed

(goimports)

Additional comments not posted (5)
pkg/observable/interface.go (1)

14-24: LGTM! Clear and detailed documentation.

The documentation for SubscribeFromLatestBufferedOffset is clear and provides detailed information about the method's behavior.

Tools
golangci-lint

19-19: File is not goimports-ed

(goimports)

pkg/observable/channel/replay.go (4)

125-126: LGTM! The changes to the Subscribe method are correct.

The Subscribe method now calls SubscribeFromLatestBufferedOffset with ro.replayBufferSize, which is appropriate.


128-138: LGTM! Clear and detailed documentation.

The documentation for SubscribeFromLatestBufferedOffset is clear and provides detailed information about the method's behavior.

Tools
golangci-lint

133-133: File is not goimports-ed

(goimports)


138-153: LGTM! The implementation of SubscribeFromLatestBufferedOffset is correct.

The method implementation correctly handles subscribing from the latest buffered offset and ensures the offset is within bounds.


153-154: LGTM! The loop logic is correct.

The loop correctly replays values from the buffer in reverse order.

pkg/observable/interface.go Show resolved Hide resolved
Copy link

@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 27a0d00 and fac9952.

Files selected for processing (2)
  • pkg/observable/channel/replay.go (1 hunks)
  • pkg/observable/interface.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • pkg/observable/channel/replay.go
  • pkg/observable/interface.go

@bryanchriswhite bryanchriswhite added push-image CI related - pushes images to ghcr.io devnet-test-e2e labels Jul 8, 2024
Copy link

github-actions bot commented Jul 8, 2024

The image is going to be pushed after the next commit.

You can use make trigger_ci to push an empty commit.

If you also want to run E2E tests, please add devnet-test-e2e label.

Copy link

github-actions bot commented Jul 8, 2024

The CI will now also run the e2e tests on devnet, which increases the time it takes to complete all CI checks.

You may need to run make trigger_ci to submit an empty commit that'll trigger the tests.

GCP workloads (requires changing the namespace to 647)
Grafana network dashboard for devnet-issue-{issue-id}

@github-actions github-actions bot added the devnet label Jul 8, 2024
Copy link
Contributor

@red-0ne red-0ne left a comment

Choose a reason for hiding this comment

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

Love it!

@bryanchriswhite bryanchriswhite merged commit 208a228 into main Jul 12, 2024
10 checks passed
bryanchriswhite added a commit that referenced this pull request Jul 12, 2024
…session-manager

* pokt/main:
  [Observables] chore: add `ReplayObservable#SubscribeFromLatestBufferedOffset()` (#647)
  [Observability] Add claim relays counter (#644)
  [Code Health] chore: log unused error when updating relay mining difficulty (#683)
  [Testing] chore: uncomment proof CLI query tests (#668)
@bryanchriswhite bryanchriswhite deleted the issues/553/fix/replay-observable branch July 12, 2024 09:38
bryanchriswhite added a commit that referenced this pull request Jul 15, 2024
…ent-balances

* pokt/main:
  [TODOs] refactor: proof path calculation (#659)
  [Dependencies] bump go-getter and ibc-go (#691)
  [Relayminer] refactor: `relayerSessionsManager#waitForBlock()` (#648)
  [Observables] chore: add `ReplayObservable#SubscribeFromLatestBufferedOffset()` (#647)
  [Observability] Add claim relays counter (#644)
  [Code Health] chore: log unused error when updating relay mining difficulty (#683)
  [Testing] chore: uncomment proof CLI query tests (#668)
  build(deps): bump ws from 7.5.9 to 7.5.10 in /docusaurus (#686)
  build(deps): bump webpack-dev-middleware from 5.3.3 to 5.3.4 in /docusaurus (#688)
  build(deps): bump express from 4.18.2 to 4.19.2 in /docusaurus (#687)
  build(deps): bump follow-redirects from 1.15.3 to 1.15.6 in /docusaurus (#685)
  build(deps): bump braces from 3.0.2 to 3.0.3 in /docusaurus (#689)
  [CosmosSDK] Bump to v0.50.7 (#682)
bryanchriswhite added a commit that referenced this pull request Jul 15, 2024
…ation-overserviced

* pokt/main:
  [TODOs] refactor: proof path calculation (#659)
  [Dependencies] bump go-getter and ibc-go (#691)
  [Relayminer] refactor: `relayerSessionsManager#waitForBlock()` (#648)
  [Observables] chore: add `ReplayObservable#SubscribeFromLatestBufferedOffset()` (#647)
  [Observability] Add claim relays counter (#644)
  [Code Health] chore: log unused error when updating relay mining difficulty (#683)
  [Testing] chore: uncomment proof CLI query tests (#668)
  build(deps): bump ws from 7.5.9 to 7.5.10 in /docusaurus (#686)
  build(deps): bump webpack-dev-middleware from 5.3.3 to 5.3.4 in /docusaurus (#688)
  build(deps): bump express from 4.18.2 to 4.19.2 in /docusaurus (#687)
  build(deps): bump follow-redirects from 1.15.3 to 1.15.6 in /docusaurus (#685)
  build(deps): bump braces from 3.0.2 to 3.0.3 in /docusaurus (#689)
  [CosmosSDK] Bump to v0.50.7 (#682)
bryanchriswhite added a commit that referenced this pull request Jul 15, 2024
…ation-use-index

* pokt/main:
  [TODOs] refactor: proof path calculation (#659)
  [Dependencies] bump go-getter and ibc-go (#691)
  [Relayminer] refactor: `relayerSessionsManager#waitForBlock()` (#648)
  [Observables] chore: add `ReplayObservable#SubscribeFromLatestBufferedOffset()` (#647)
  [Observability] Add claim relays counter (#644)
  [Code Health] chore: log unused error when updating relay mining difficulty (#683)
  [Testing] chore: uncomment proof CLI query tests (#668)
  build(deps): bump ws from 7.5.9 to 7.5.10 in /docusaurus (#686)
  build(deps): bump webpack-dev-middleware from 5.3.3 to 5.3.4 in /docusaurus (#688)
  build(deps): bump express from 4.18.2 to 4.19.2 in /docusaurus (#687)
  build(deps): bump follow-redirects from 1.15.3 to 1.15.6 in /docusaurus (#685)
  build(deps): bump braces from 3.0.2 to 3.0.3 in /docusaurus (#689)
  [CosmosSDK] Bump to v0.50.7 (#682)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code health Cleans up some code devnet devnet-test-e2e off-chain Off-chain business logic push-image CI related - pushes images to ghcr.io
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[Relayminer] Add ReplayObservable#SubscribeFromBufferEndOffset() method
3 participants