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

(DAL) Latest outgoing data from collector #1781

Merged
merged 3 commits into from
Jul 11, 2024

Conversation

nick-bisonai
Copy link
Collaborator

@nick-bisonai nick-bisonai commented Jul 11, 2024

Description

based on local test, this updates rest api response time from
200ms -> less than 10ms

AS - IS

rest api

  1. call redis db to get proof and global aggregate
  2. post process data into outgoing data
  3. return data

TO - BE

  • collector constantly stores latest data from redis subscription
  • rest api gets latest data from collector without any post processing and returns data

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.

Deployment

  • Should publish npm package
  • Should publish Docker image

@nick-bisonai nick-bisonai self-assigned this Jul 11, 2024
Copy link
Contributor

coderabbitai bot commented Jul 11, 2024

Warning

Rate limit exceeded

@nick-bisonai has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 33 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 597fbd7 and a9a64c8.

Walkthrough

Walkthrough

The recent updates streamline data retrieval and handling within the node's package, particularly focusing on submission data and feeds. Functions in the controller.go file have been replaced with new method calls to ApiController.Collector, simplifying and centralizing data management. Additionally, the Collector struct in collector.go has been enhanced with new fields and methods for improved data storage and retrieval. Test files have been updated accordingly to reflect these changes.

Changes

Files Change Summary
node/pkg/dal/api/controller.go Removed functions for data fetching, replaced with calls to ApiController.Collector methods.
node/pkg/dal/collector/collector.go Added LatestData field and methods for storing and retrieving the latest data in Collector.
node/pkg/dal/tests/api_test.go Updated tests to remove aggregator references and use a new testPublishData function.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ApiController
    participant Collector

    Client->>+ApiController: Request latest feeds
    ApiController->>+Collector: GetAllLatestData()
    Collector-->>-ApiController: AllLatestData
    ApiController-->>-Client: Return latest feeds

    Client->>+ApiController: Request latest feed for symbol
    ApiController->>+Collector: GetLatestData(symbol)
    Collector-->>-ApiController: LatestData(symbol)
    ApiController-->>-Client: Return latest feed for symbol
Loading

Poem

Changes in the code we see,
Streamlined paths to be worry-free.
Collectors store, controllers call,
Simplified processes for us all.
Tests revamped, data in the flow,
Code like rivers, now they go!


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.

@nick-bisonai nick-bisonai marked this pull request as ready for review July 11, 2024 01:38
@nick-bisonai nick-bisonai requested a review from a team as a code owner July 11, 2024 01:38
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 46be64c and 597fbd7.

Files selected for processing (3)
  • node/pkg/dal/api/controller.go (4 hunks)
  • node/pkg/dal/collector/collector.go (5 hunks)
  • node/pkg/dal/tests/api_test.go (7 hunks)
Additional comments not posted (9)
node/pkg/dal/api/controller.go (2)

163-165: LGTM! Verify the correctness of GetAllLatestData.

The function now uses ApiController.Collector.GetAllLatestData() to retrieve data, which aligns with the updated process to improve response time.

Ensure that GetAllLatestData is correctly implemented and tested.

Verification successful

The implementation of GetAllLatestData is correct.

  • The method is implemented in node/pkg/dal/collector/collector.go and correctly retrieves all latest data from c.LatestData.
  • The usage in your code snippet is appropriate.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of `GetAllLatestData` method in `Collector`.

# Test: Search for the implementation and references of `GetAllLatestData`. Expect: Correct implementation and usage.
ast-grep --lang go --pattern 'func ($_ *Collector) GetAllLatestData() []dalcommon.OutgoingSubmissionData { $$$ }'
rg --type go -A 5 $'GetAllLatestData()'

Length of output: 1826


188-193: LGTM! Verify the correctness of GetLatestData.

The function now uses ApiController.Collector.GetLatestData(symbol) to retrieve data, which aligns with the updated process to improve response time.

Ensure that GetLatestData is correctly implemented and tested.

Verification successful

Let's fix the ripgrep command and re-run it to gather more context about the usage of GetLatestData.


Let's fix the ripgrep command by avoiding special regex characters and re-run it to gather more context about the usage of GetLatestData.


LGTM!

The GetLatestData method in Collector is correctly implemented and used appropriately in ApiController.

  • The function handles data retrieval and error conditions properly.
  • The usage in controller.go aligns with the expected behavior.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of `GetLatestData` method in `Collector`.

# Test: Search for the implementation and references of `GetLatestData`. Expect: Correct implementation and usage.
ast-grep --lang go --pattern 'func ($_ *Collector) GetLatestData(symbol string) (*dalcommon.OutgoingSubmissionData, error) { $$$ }'
rg --type go -A 5 $'GetLatestData('

Length of output: 1128


Script:

#!/bin/bash
# Description: Verify the correctness of `GetLatestData` method in `Collector`.

# Test: Search for the implementation and references of `GetLatestData`. Expect: Correct implementation and usage.
ast-grep --lang go --pattern 'func ($_ *Collector) GetLatestData(symbol string) (*dalcommon.OutgoingSubmissionData, error) { $$$ }'
rg --type go -A 5 'GetLatestData('

Length of output: 1128


Script:

#!/bin/bash
# Description: Verify the correctness of `GetLatestData` method in `Collector`.

# Test: Search for the implementation and references of `GetLatestData`. Expect: Correct implementation and usage.
ast-grep --lang go --pattern 'func ($_ *Collector) GetLatestData(symbol string) (*dalcommon.OutgoingSubmissionData, error) { $$$ }'
rg --type go -A 5 'GetLatestData'

Length of output: 1765

node/pkg/dal/tests/api_test.go (2)

139-143: LGTM! Verify the correctness of testPublishData.

The test case now uses testPublishData to publish sample submission data, which aligns with the updated data handling methods.

Ensure that testPublishData is correctly implemented and tested.

Verification successful

Verification successful!

The testPublishData function is correctly implemented and consistently used across different test files to publish sample submission data.

  • Implementation found in node/pkg/dal/tests/main_test.go:

    func testPublishData(ctx context.Context, submissionData aggregator.SubmissionData) error {
        return db.Publish(ctx, keys.SubmissionDataStreamKey(submissionData.GlobalAggregate.ConfigID), submissionData)
    }
  • Usage found in:

    • node/pkg/dal/tests/api_test.go
    • node/pkg/dal/tests/collector_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of `testPublishData` function.

# Test: Search for the implementation and references of `testPublishData`. Expect: Correct implementation and usage.
ast-grep --lang go --pattern 'func testPublishData($_, $_) error { $$$ }'
rg --type go -A 5 'testPublishData'

Length of output: 2445


62-66: LGTM! Verify the correctness of testPublishData.

The test case now uses testPublishData to publish sample submission data, which aligns with the updated data handling methods.

Ensure that testPublishData is correctly implemented and tested.

Verification successful

LGTM! Verify the correctness of db.Publish.

The testPublishData function is correctly implemented and aligns with the updated data handling methods. Now, ensure that db.Publish is correctly implemented and handles the passed parameters properly.


LGTM! Verify the correctness of db.Publish.

Correct the rg command and ensure that the method signature pattern is accurate to find the implementation and references of db.Publish.


Verified: The testPublishData method and its usage are correct. The db.Publish method is implemented with necessary checks and is well-tested.

  • Implementation and references of testPublishData in node/pkg/dal/tests/main_test.go and other files are correct.
  • db.Publish method in node/pkg/db/redis.go is correctly implemented and includes parameter checks.
  • Multiple test cases in node/pkg/db/redis_test.go confirm the robustness of db.Publish.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of `testPublishData` function.

# Test: Search for the implementation and references of `testPublishData`. Expect: Correct implementation and usage.
ast-grep --lang go --pattern 'func testPublishData($_, $_) error { $$$ }'
rg --type go -A 5 'testPublishData'

Length of output: 2445


Script:

#!/bin/bash
# Description: Verify the correctness of the `db.Publish` method.

# Test: Search for the implementation and references of `db.Publish`. Expect: Correct implementation and usage.
ast-grep --lang go --pattern 'func ($_).Publish($_, $_, $_) error { $$$ }'
rg --type go -A 5 'Publish('

Length of output: 174


Script:

#!/bin/bash
# Description: Verify the correctness of the `db.Publish` method.

# Test: Search for the implementation and references of `db.Publish`. Expect: Correct implementation and usage.
ast-grep --lang go --pattern 'func ($_).Publish($_, $_, $_) error { $$$ }'
rg --type go -A 5 'Publish\('

Length of output: 4698

node/pkg/dal/collector/collector.go (5)

71-71: LGTM! Verify the correctness of LatestData initialization.

The LatestData field is correctly initialized in the Collector struct.

Ensure that LatestData is correctly initialized and used.

Verification successful

Verified: Initialization and Usage of LatestData are Correct

  • The LatestData field in the Collector struct is correctly initialized as sync.Map{}.
  • The usage of LatestData in methods like GetLatestData, GetAllLatestData, and Store is consistent and appropriate.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of `LatestData` initialization and usage.

# Test: Search for the initialization and references of `LatestData`. Expect: Correct initialization and usage.
ast-grep --lang go --pattern 'LatestData: $_'
rg --type go -A 5 'LatestData'

Length of output: 6237


230-232: LGTM! Verify the correctness of storeLatest.

The method stores the latest data in LatestData, which aligns with the updated process to improve response time.

Ensure that storeLatest is correctly implemented and tested.

Verification successful

Verified: The storeLatest method is correctly implemented and used.

The storeLatest method is properly implemented and invoked within the collector.go file, ensuring that the latest data is stored as intended.

  • Implementation found at node/pkg/dal/collector/collector.go:230-232.
  • Usage found at node/pkg/dal/collector/collector.go: defer c.storeLatest(result).
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of `storeLatest` method in `Collector`.

# Test: Search for the implementation and references of `storeLatest`. Expect: Correct implementation and usage.
ast-grep --lang go --pattern 'func ($_ *Collector) storeLatest(data *dalcommon.OutgoingSubmissionData) { $$$ }'
rg --type go -A 5 $'storeLatest('

Length of output: 464


Script:

#!/bin/bash
# Description: Verify the correctness of `storeLatest` method in `Collector`.

# Test: Search for the implementation and references of `storeLatest`. Expect: Correct implementation and usage.

# Corrected rg command to avoid regex parse error
rg --type go 'storeLatest\(' -A 5

Length of output: 728


102-114: LGTM! Verify the correctness of GetLatestData.

The method retrieves the latest data for a given symbol from LatestData, which aligns with the updated process to improve response time.

Ensure that GetLatestData is correctly implemented and tested.

Verification successful

Verified: The GetLatestData method is correctly implemented and used.

  • Implementation found in node/pkg/dal/collector/collector.go
  • Usage reference found in node/pkg/dal/api/controller.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of `GetLatestData` method in `Collector`.

# Test: Search for the implementation and references of `GetLatestData`. Expect: Correct implementation and usage.
ast-grep --lang go --pattern 'func ($_ *Collector) GetLatestData(symbol string) (*dalcommon.OutgoingSubmissionData, error) { $$$ }'
rg --type go -A 5 $'GetLatestData('

Length of output: 1128


Script:

#!/bin/bash
# Description: Verify the correctness of `GetLatestData` method in `Collector`.

# Test: Search for the implementation and references of `GetLatestData`. Expect: Correct implementation and usage.
ast-grep --lang go --pattern 'func ($_ *Collector) GetLatestData(symbol string) (*dalcommon.OutgoingSubmissionData, error) { $$$ }'

# Correcting the regex pattern for `rg` to search for references to `GetLatestData`.
rg --type go -A 5 'GetLatestData('

Length of output: 1128


Script:

#!/bin/bash
# Description: Verify the correctness of `GetLatestData` method in `Collector`.

# Test: Search for the implementation and references of `GetLatestData`. Expect: Correct implementation and usage.
ast-grep --lang go --pattern 'func ($_ *Collector) GetLatestData(symbol string) (*dalcommon.OutgoingSubmissionData, error) { $$$ }'

# Correcting the regex pattern for `rg` to search for references to `GetLatestData`.
rg --type go -A 5 'GetLatestData\('

Length of output: 1769


167-167: LGTM! Verify the correctness of storeLatest.

The method now calls storeLatest to store the latest data, which aligns with the updated process to improve response time.

Ensure that storeLatest is correctly implemented and tested.

Verification successful

The implementation and usage of storeLatest are correct.

  • The method storeLatest is properly defined and used within node/pkg/dal/collector/collector.go.
  • The LatestData is correctly defined as a sync.Map and used appropriately.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of `storeLatest` method in `Collector`.

# Test: Search for the implementation and references of `storeLatest`. Expect: Correct implementation and usage.
ast-grep --lang go --pattern 'func ($_ *Collector) storeLatest(data *dalcommon.OutgoingSubmissionData) { $$$ }'
rg --type go -A 5 $'storeLatest('

Length of output: 464


Script:

#!/bin/bash
# Description: Verify the definition and usage of `LatestData` and correct the rg command to find all references to `storeLatest`.

# Test 1: Search for the definition of `LatestData`.
rg --type go 'LatestData'

# Test 2: Correct and run the `rg` command to find all references to `storeLatest`.
rg --type go 'storeLatest('

Length of output: 1843


Script:

#!/bin/bash
# Description: Correct the `rg` command to find all references to `storeLatest`.

# Test: Correct and run the `rg` command to find all references to `storeLatest`.
rg --type go 'storeLatest\('

Length of output: 205


116-127: LGTM! Verify the correctness of GetAllLatestData.

The method retrieves all the latest data from LatestData, which aligns with the updated process to improve response time.

Ensure that GetAllLatestData is correctly implemented and tested.

@nick-bisonai nick-bisonai force-pushed the feat/store-latest-outgoing-data-from-collector branch from c61c9a9 to a9a64c8 Compare July 11, 2024 03:00
@nick-bisonai nick-bisonai merged commit 858686f into master Jul 11, 2024
2 checks passed
@nick-bisonai nick-bisonai deleted the feat/store-latest-outgoing-data-from-collector branch July 11, 2024 03:46
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.

1 participant