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: allow ignoring denoms #73

Merged
merged 1 commit into from
Jul 10, 2024
Merged

feat: allow ignoring denoms #73

merged 1 commit into from
Jul 10, 2024

Conversation

freak12techno
Copy link
Collaborator

@freak12techno freak12techno commented Jul 9, 2024

Summary by CodeRabbit

  • New Features

    • Introduced an "ignore" field in denominators configuration to exclude specific denominations from metrics.
  • Bug Fixes

    • Added conditional checks to skip processing when certain values are nil, ensuring more robust and error-free metric generation.
  • Tests

    • Added tests to verify the behavior of token generation, balance, commission, and validator information with the new "ignore" field.
  • Chores

    • Included new import dependencies necessary for handling nullable fields in the configuration and tests.

Copy link
Contributor

coderabbitai bot commented Jul 9, 2024

Walkthrough

This update introduces the ability to ignore specific denominations (denoms) in various configurations and metric exports. By adding an ignore flag to the denoms array in the configuration, you can now exclude certain denominational data from metrics and processing logic. The changes span multiple files, adding checks to ensure exclusions and adjusted validations accordingly.

Changes

File/Group Change Summary
config.example.toml Added ignore field to denoms array to mark denominations for exclusion.
pkg/config/denom_info.go Updated DenomInfo struct and methods to handle the Ignore field.
pkg/generators/active_set_tokens.go Added checks to skip processing if the denomination should be ignored.
pkg/generators/balance.go Enhanced loops to skip balances with ignored denominations.
pkg/generators/commission.go Modified to bypass processing for ignored denominations.
pkg/generators/rewards.go Added conditions to skip ignored denomination rewards.
pkg/generators/self_delegation.go Implemented nil checks and ignored denomination logic.
pkg/generators/single_validator_info.go Incorporated new checks for delegations of ignored denominations.
pkg/generators/validators_info.go Added a new conditional to handle ignored denomination totals.
Test updates in pkg/generators/..._test.go Included tests for the new ignore functionality across different generators. Updated imports and assertions to align with new logic.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant ConfigParser as Config Parser
    participant DenomInfo as DenomInfo Struct
    participant MetricsExporter as Metrics Exporter

    User->>ConfigParser: Provide config with denoms
    ConfigParser->>DenomInfo: Parse denoms with `ignore` field
    DenomInfo->>MetricsExporter: Skip denoms with `ignore=true`
    MetricsExporter-->>User: Export metrics excluding ignored denoms
Loading

Poem

In the den of code, some coins take flight,
An option to ignore them feels just right.
With careful checks, we ensure our task,
Denominations hidden, no need to ask.
Metrics clean and crisp, with ease they flow,
A rabbit's touch in the silence of code. 🐇✨


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

codecov bot commented Jul 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (3a4edb8) to head (b1262f4).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #73   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           63        63           
  Lines         2567      2585   +18     
=========================================
+ Hits          2567      2585   +18     

☔ 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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3a4edb8 and b1262f4.

Files selected for processing (16)
  • config.example.toml (1 hunks)
  • pkg/config/denom_info.go (2 hunks)
  • pkg/generators/active_set_tokens.go (1 hunks)
  • pkg/generators/active_set_tokens_test.go (2 hunks)
  • pkg/generators/balance.go (2 hunks)
  • pkg/generators/balance_test.go (4 hunks)
  • pkg/generators/commission.go (1 hunks)
  • pkg/generators/commission_test.go (4 hunks)
  • pkg/generators/rewards.go (1 hunks)
  • pkg/generators/rewards_test.go (4 hunks)
  • pkg/generators/self_delegation.go (1 hunks)
  • pkg/generators/self_delegations_test.go (4 hunks)
  • pkg/generators/single_validator_info.go (1 hunks)
  • pkg/generators/single_validator_info_test.go (2 hunks)
  • pkg/generators/validators_info.go (1 hunks)
  • pkg/generators/validators_info_test.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • pkg/generators/self_delegation.go
Additional context used
Learnings (2)
pkg/generators/active_set_tokens.go (1)
Learnt from: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#62
File: pkg/generators/active_set_tokens.go:61-61
Timestamp: 2024-06-22T22:57:51.216Z
Learning: The indirect testing method used in `ActiveSetTokensGenerator`, which verifies the outcome by checking the metric's value against the expected stake of the last active validator, is considered sufficient by the user for reflecting the intended behavior of the sorting logic.
pkg/generators/active_set_tokens_test.go (1)
Learnt from: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#62
File: pkg/generators/active_set_tokens.go:61-61
Timestamp: 2024-06-22T22:57:51.216Z
Learning: The indirect testing method used in `ActiveSetTokensGenerator`, which verifies the outcome by checking the metric's value against the expected stake of the last active validator, is considered sufficient by the user for reflecting the intended behavior of the sorting logic.
Additional comments not posted (24)
pkg/config/denom_info.go (3)

16-16: Ensure Ignore field default value is correctly set.

The Ignore field is added to the DenomInfo struct with a default value of false. Verify that the null.Bool type is correctly initialized with this default value.


24-24: Update validation condition to handle Ignore field correctly.

The condition in the Validate method now checks if DisplayDenom is empty only if Ignore is not true. This logic seems correct.


61-63: Correctly handle ignored denominations in Convert method.

The Convert method now skips processing if Ignore is true. Ensure that this logic is consistent with the intended behavior of ignoring certain denominations.

pkg/generators/rewards.go (1)

50-52: Correctly handle nil values for amountConverted.

The check for amountConverted being nil ensures that the code skips processing when the conversion result is nil. This logic is correct and prevents potential runtime errors.

pkg/generators/commission.go (1)

50-52: Correctly handle nil values for amountConverted.

The check for amountConverted being nil ensures that the code skips processing when the conversion result is nil. This logic is correct and prevents potential runtime errors.

pkg/generators/rewards_test.go (3)

11-12: Import null package to handle null.Bool type.

The import of github.com/guregu/null/v5 is necessary for handling the null.Bool type used in the Ignore field.


50-50: Test case for ignored denomination.

The new test case correctly sets up a scenario where a denomination is ignored and verifies that the metrics are not generated for the ignored denomination.


64-64: Verify the count of collected metrics.

The assertion for the count of collected metrics ensures that the ignored denomination is not included in the results. This is a good practice to verify the correct behavior of the ignoring logic.

pkg/generators/commission_test.go (2)

11-12: Import is appropriate.

The github.com/guregu/null/v5 package is necessary for handling the null.Bool type.


38-38: Test updates are appropriate.

The test function now includes a scenario where a denomination is ignored, ensuring the new functionality is covered.

Also applies to: 50-50, 64-64

pkg/generators/self_delegations_test.go (2)

11-12: Import is appropriate.

The github.com/guregu/null/v5 package is necessary for handling the null.Bool type.


37-37: Test updates are appropriate.

The test function now includes a scenario where a denomination is ignored, ensuring the new functionality is covered.

Also applies to: 49-49, 53-53, 67-67

pkg/generators/balance.go (1)

51-53: Conditional checks are appropriate.

The Generate method now includes checks to skip processing if amountConverted is nil, ensuring robustness.

Also applies to: 77-79

pkg/generators/active_set_tokens.go (1)

70-72: Conditional check is appropriate.

The Generate method now includes a check to skip processing if lastValidatorAmount is nil, ensuring robustness.

pkg/generators/validators_info.go (1)

79-81: LGTM! Ensure proper verification of the new logic.

The new conditional check ensures that processing is skipped if totalBondedAmountConverted is nil. This change is approved.

However, verify that the totalBondedAmountConverted can indeed be nil and that this condition is necessary.

pkg/generators/balance_test.go (3)

11-12: Import necessary for handling null values.

The import of github.com/guregu/null/v5 is necessary for handling the null.Bool type for the Ignore field.


38-38: Ensure ignored denominations are not counted in metrics.

The test state includes an ignored denomination to verify that it is not counted in the metrics. This change is approved.

However, ensure that the logic for ignoring denominations is consistently applied across all relevant tests.

Also applies to: 45-45


81-81: LGTM! Ensure proper verification of the new logic.

The new assertion ensures that the ignored denomination is not counted in the collected metrics. This change is approved.

However, verify that the logic for ignoring denominations is correctly implemented in the generator.

pkg/generators/single_validator_info.go (1)

151-153: LGTM! Ensure proper verification of the new logic.

The new conditional check ensures that processing is skipped if delegationsAmount is nil. This change is approved.

However, verify that the delegationsAmount can indeed be nil and that this condition is necessary.

pkg/generators/validators_info_test.go (2)

11-12: Import necessary for handling null values.

The import of github.com/guregu/null/v5 is necessary for handling the null.Bool type for the Ignore field.


90-136: LGTM! Ensure proper verification of the new logic.

The new test ensures that ignored base denominations are not counted in the collected metrics. This change is approved.

However, verify that the logic for ignoring base denominations is correctly implemented in the generator.

pkg/generators/active_set_tokens_test.go (1)

153-187: LGTM!

The test correctly verifies the behavior when a denomination is ignored.

config.example.toml (1)

39-53: LGTM!

The addition of the ignore field is well-documented and the default value is appropriately set to false.

pkg/generators/single_validator_info_test.go (1)

168-255: LGTM!

The test correctly verifies the behavior when a base denomination is ignored.

@freak12techno freak12techno merged commit 1f51763 into main Jul 10, 2024
8 checks passed
@freak12techno freak12techno deleted the allow-ignoring-denoms branch July 10, 2024 00:52
@coderabbitai coderabbitai bot mentioned this pull request Sep 25, 2024
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