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

feat(promexporter): add pagination to dfk [SLT-332] #3292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

golangisfun123
Copy link
Collaborator

@golangisfun123 golangisfun123 commented Oct 15, 2024

Description
A clear and concise description of the features you're adding in this pull request.

Additional context
Add any other context about the problem you're solving.

Metadata

  • Fixes #[Link to Issue]

Summary by CodeRabbit

  • New Features

    • Enhanced pagination for retrieving stuck heroes, allowing users to fetch results in increments of 100.
    • Added a parameter to specify the limit on results returned for stuck heroes.
  • Bug Fixes

    • Improved data retrieval to ensure all relevant stuck hero data is captured effectively.

Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

Walkthrough

The changes involve modifications to the stuckHeroCountStats function in the exporters package to implement pagination for retrieving stuck heroes. The previous single count retrieval has been replaced with a loop that uses a limit of 100 to fetch results incrementally. Additionally, the StuckHeroes method in the Client struct has been updated to accept a new limit parameter, allowing callers to specify the number of results returned. These changes enhance the data retrieval process for stuck heroes.

Changes

File Path Change Summary
contrib/promexporter/exporters/dfk.go Modified stuckHeroCountStats to implement pagination with a loop, using totalStuckHeroes and skip for managing results.
contrib/promexporter/internal/gql/dfk/client.gen.go Updated StuckHeroes method to include a new limit *int64 parameter for specifying the number of results in the GraphQL query.

Poem

In the fields where heroes tread,
A count of stuck ones now widespread.
With limits set and pages turned,
New tales of triumph will be learned.
Hopping forth, we cheer and play,
For every hero finds their way! 🐇✨


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@github-actions github-actions bot added go Pull requests that update Go code size/xs labels Oct 15, 2024
Copy link

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3f6dc6e
Status: ✅  Deploy successful!
Preview URL: https://2fc5eb36.sanguine-fe.pages.dev
Branch Preview URL: https://dfk-pagination.sanguine-fe.pages.dev

View logs

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 0% with 16 lines in your changes missing coverage. Please review.

Project coverage is 43.66137%. Comparing base (ea0154c) to head (3f6dc6e).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
contrib/promexporter/exporters/dfk.go 0.00000% 14 Missing ⚠️
...ontrib/promexporter/internal/gql/dfk/client.gen.go 0.00000% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (ea0154c) and HEAD (3f6dc6e). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (ea0154c) HEAD (3f6dc6e)
solidity 1 0
Additional details and impacted files
@@                 Coverage Diff                  @@
##              master       #3292          +/-   ##
====================================================
- Coverage   91.48936%   43.66137%   -47.82800%     
====================================================
  Files             59          74          +15     
  Lines           1269        2327        +1058     
  Branches         158          82          -76     
====================================================
- Hits            1161        1016         -145     
- Misses           104        1305        +1201     
- Partials           4           6           +2     
Flag Coverage Δ
promexporter 6.76403% <0.00000%> (?)
solidity ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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: 4

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b09b41c and 3f6dc6e.

📒 Files selected for processing (2)
  • contrib/promexporter/exporters/dfk.go (1 hunks)
  • contrib/promexporter/internal/gql/dfk/client.gen.go (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
contrib/promexporter/exporters/dfk.go

[warning] 30-41: contrib/promexporter/exporters/dfk.go#L30-L41
Added lines #L30 - L41 were not covered by tests


[warning] 43-43: contrib/promexporter/exporters/dfk.go#L43
Added line #L43 was not covered by tests


[warning] 46-46: contrib/promexporter/exporters/dfk.go#L46
Added line #L46 was not covered by tests

contrib/promexporter/internal/gql/dfk/client.gen.go

[warning] 62-62: contrib/promexporter/internal/gql/dfk/client.gen.go#L62
Added line #L62 was not covered by tests


[warning] 65-65: contrib/promexporter/internal/gql/dfk/client.gen.go#L65
Added line #L65 was not covered by tests

Comment on lines +62 to +65
func (c *Client) StuckHeroes(ctx context.Context, skip *int64, limit *int64, owner *string, httpRequestOptions ...client.HTTPRequestOption) (*StuckHeroes, error) {
vars := map[string]interface{}{
"skip": skip,
"limit": limit,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Added lines not covered by tests

The static analysis tool indicates that the added lines are not covered by tests. This lack of test coverage may lead to undetected issues in the future.

Consider adding or updating tests to cover the new limit parameter in the StuckHeroes method. This will ensure that the pagination functionality works as expected.

Would you like assistance in generating test cases for the updated StuckHeroes method?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 62-62: contrib/promexporter/internal/gql/dfk/client.gen.go#L62
Added line #L62 was not covered by tests


[warning] 65-65: contrib/promexporter/internal/gql/dfk/client.gen.go#L65
Added line #L65 was not covered by tests


💡 Codebase verification

⚠️ Potential issue

Inconsistency between method signature and GraphQL query

The limit parameter has been added to the method signature and the vars map, but the GraphQL query string (StuckHeroesDocument) doesn't use this parameter. This inconsistency may lead to unexpected behavior.

Recommendation:

Update the GraphQL query to include the limit parameter:

const StuckHeroesDocument = `query StuckHeroes ($skip: Int, $owner: String, $limit: Int) {
-	heroes(skip: $skip, where: {owner:$owner}) {
+	heroes(skip: $skip, first: $limit, where: {owner:$owner}) {
		id
	}
}
`

Note: Since this is generated code, you may need to update the source from which the code is generated to ensure consistency across the codebase.

🔗 Analysis chain

Inconsistency between method signature and GraphQL query

The limit parameter has been added to the method signature and the vars map, but the GraphQL query string (StuckHeroesDocument) doesn't use this parameter. This inconsistency may lead to unexpected behavior.

Consider updating the GraphQL query to include the limit parameter:

const StuckHeroesDocument = `query StuckHeroes ($skip: Int, $owner: String) {
-	heroes(skip: $skip, where: {owner:$owner}) {
+	heroes(skip: $skip, first: $limit, where: {owner:$owner}) {
		id
	}
}
`

Note: Since this is generated code, you may need to update the source of the generation instead.

To confirm if this change is necessary, please run the following command to check if there are any other occurrences of the StuckHeroes query in the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other occurrences of the StuckHeroes query
rg --type go 'query StuckHeroes'

Length of output: 164

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 62-62: contrib/promexporter/internal/gql/dfk/client.gen.go#L62
Added line #L62 was not covered by tests


[warning] 65-65: contrib/promexporter/internal/gql/dfk/client.gen.go#L65
Added line #L65 was not covered by tests

Comment on lines +30 to +43
var totalStuckHeroes int64
var skip int64
var limit int64 = 100

for {
stuckHeroes, err := dfkClient.StuckHeroes(ctx, core.PtrTo(skip), core.PtrTo(limit), core.PtrTo(owner.String()))
if err != nil {
return fmt.Errorf("could not get stuck hero count: %w", err)
}
totalStuckHeroes += int64(len(stuckHeroes.Heroes))
if len(stuckHeroes.Heroes) < int(limit) {
break
}
skip += limit
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add unit tests for the new pagination logic

The newly introduced pagination logic in the stuckHeroCountStats function is critical for accurately accumulating the total number of stuck heroes. Currently, the code from lines 30 to 43 is not covered by tests, as indicated by the static analysis tools. To ensure the reliability and correctness of this functionality, please add unit tests that cover various scenarios, such as:

  • When the total number of stuck heroes is less than the limit.
  • When the total number of stuck heroes is exactly a multiple of the limit.
  • When the total number of stuck heroes exceeds the limit.
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 30-41: contrib/promexporter/exporters/dfk.go#L30-L41
Added lines #L30 - L41 were not covered by tests


[warning] 43-43: contrib/promexporter/exporters/dfk.go#L43
Added line #L43 was not covered by tests

}

e.otelRecorder.RecordStuckHeroCount(int64(len(stuckHeroes.Heroes)), chainName)
e.otelRecorder.RecordStuckHeroCount(totalStuckHeroes, chainName)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure metric recording is tested

The call to e.otelRecorder.RecordStuckHeroCount(totalStuckHeroes, chainName) on line 46 is essential for recording the total count of stuck heroes. However, this line is not currently covered by tests, as per the static analysis report. Please add tests to verify that the metric recording functions correctly with the accumulated totalStuckHeroes value.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 46-46: contrib/promexporter/exporters/dfk.go#L46
Added line #L46 was not covered by tests

@trajan0x trajan0x changed the title [SLT-332] feat(promexporter): add pagination to dfk feat(promexporter): add pagination to dfk [SLT-332] Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant