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: refactor consumer info metrics #66

Merged
merged 1 commit into from
Jun 25, 2024

Conversation

freak12techno
Copy link
Collaborator

@freak12techno freak12techno commented Jun 25, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced consumer info processing with more detailed nested data structures.
  • Bug Fixes

    • Improved accuracy in test assertions for consumer info fetcher and generator.
  • Refactor

    • Updated methods to use new data structure formats for improved data handling and scalability.
    • Modified consumer info generator to accept chain configurations for better flexibility.
  • Tests

    • Adjusted tests to align with new data structures and function parameter changes.

Copy link
Contributor

coderabbitai bot commented Jun 25, 2024

Walkthrough

The update primarily refactors how consumer information is managed and generated. The NewConsumerInfoGenerator function now takes a list of chains as a parameter, facilitating more detailed and structured information handling. Nested maps replace flat structures in the ConsumerInfoFetcher to better organize consumer data. Tests are updated accordingly to validate these structural changes, ensuring the system processes and retrieves consumer chain info correctly.

Changes

File Change Summary
pkg/app.go NewConsumerInfoGenerator function call updated to include appConfig.Chains as a parameter.
pkg/fetchers/consumer_info.go Changed allInfos and Info to use nested maps for detailed structuring; adjustments in processChain method to reflect this new structure.
pkg/fetchers/consumer_info_test.go Modified test assertions to match the new nested map structure in ConsumerInfoFetcher and validate empty states directly or through nested structures.
pkg/generators/consumer_info.go Constructor of ConsumerInfoGenerator updated to accept a slice of config.Chain; iterates over these chains for updating consumer metrics.
pkg/generators/consumer_info_test.go Import config added; tests updated to call NewConsumerInfoGenerator with slice of config.Chain and validate the generator against the nested map structure.

Sequence Diagram(s)

sequenceDiagram
    participant AppConfig
    participant App
    participant ConsumerInfoGenerator
    participant ConsumerInfoFetcher

    AppConfig->>App: Provide Chains
    App->>ConsumerInfoGenerator: Initialize with Chains
    ConsumerInfoGenerator->>ConsumerInfoFetcher: Fetch Consumer Data
    ConsumerInfoFetcher->>ConsumerInfoGenerator: Return Nested Map Data
    ConsumerInfoGenerator->>App: Return Generated Consumer Info
Loading

Poem

In fields of code, where logic meets delight,
Changes ripple, making the old new and bright.
Chains now flow through maps nested deep,
Fetchers and generators in sync, no secrets they keep.
Tests affirm the future, stable and strong,
In the world of code, we continue to belong. 🌱


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
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 448295e and 7d93834.

Files selected for processing (5)
  • pkg/app.go (1 hunks)
  • pkg/fetchers/consumer_info.go (3 hunks)
  • pkg/fetchers/consumer_info_test.go (2 hunks)
  • pkg/generators/consumer_info.go (4 hunks)
  • pkg/generators/consumer_info_test.go (3 hunks)
Additional context used
Learnings (3)
pkg/generators/consumer_info_test.go (1)
User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#64
File: pkg/config/consumer_chain_test.go:63-63
Timestamp: 2024-06-25T21:31:42.607Z
Learning: In `pkg/config/consumer_chain_test.go`, incomplete `DenomInfos` fields are intentionally set to trigger validation failures as part of testing error handling.
pkg/fetchers/consumer_info.go (1)
User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#63
File: pkg/fetchers/consumer_info.go:34-40
Timestamp: 2024-06-23T11:24:17.378Z
Learning: User freak12techno plans to add unit tests for the `NewConsumerInfoFetcher` constructor later.
pkg/fetchers/consumer_info_test.go (2)
User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#63
File: pkg/fetchers/consumer_validators.go:40-40
Timestamp: 2024-06-23T16:11:23.143Z
Learning: The `TestConsumerValidatorsFetcherBase` method in `pkg/fetchers/consumer_validators_test.go` tests the initialization of `ConsumerValidatorsFetcher` with the `Chains` parameter.
User: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#63
File: pkg/fetchers/consumer_info.go:34-40
Timestamp: 2024-06-23T11:24:17.378Z
Learning: User freak12techno plans to add unit tests for the `NewConsumerInfoFetcher` constructor later.
Additional comments not posted (12)
pkg/generators/consumer_info_test.go (3)

4-4: Added import statement for config.

This import is necessary for the updated constructor of ConsumerInfoGenerator that now requires a slice of config.Chain.


23-23: Updated constructor usage in TestConsumerInfoGeneratorNoState.

The test now correctly uses the new constructor signature by passing an empty slice of config.Chain.


33-51: Updated test setup in TestConsumerInfoGeneratorNotEmptyState.

The test now uses a nested map structure for ConsumerInfoData. This aligns with the changes in the data structure of ConsumerInfoFetcher. Also, the test correctly sets up a more complex state to reflect different scenarios.

pkg/generators/consumer_info.go (4)

4-4: Added import statement for config.

This import is necessary for the changes in the ConsumerInfoGenerator class to handle configurations.


13-13: Added Chains field to ConsumerInfoGenerator.

This field is crucial for the generator to maintain a list of chains, which is used in the Generate method to process consumer information based on configurations.


16-17: Updated constructor to initialize Chains field.

The constructor now properly initializes the Chains field with the passed argument, aligning with the new requirement to handle multiple chains.


Line range hint 36-74: Updated Generate method to use nested map structure and chain configurations.

The method now iterates over chains and their consumer chains to generate metrics. This is a significant change that aligns with the new data structures and requirements. Ensure that the metrics generated are correctly labeled and calculated based on the new structure.

pkg/fetchers/consumer_info.go (2)

25-25: Updated data structures to nested maps.

The allInfos and Info fields have been updated to use nested map structures. This change is crucial for supporting more complex data relationships as required by the new features.

Also applies to: 29-29


Line range hint 50-103: Refactored Fetch and processChain methods to initialize and populate nested maps.

These methods have been significantly updated to work with the new nested map structures. The Fetch method initializes the structure, and processChain populates it based on fetched data. Ensure that error handling and logging are adequately addressed in these methods.

pkg/fetchers/consumer_info_test.go (2)

114-114: Updated assertion in TestConsumerInfoFetcherQueryDisabled.

The test now correctly asserts that the Info field is empty, which is expected behavior when the query is disabled. This change is necessary due to the updated data structure.


240-240: Updated assertion in TestConsumerInfoFetcherQuerySuccess.

The test now checks the length of chainData to verify the correct handling of data in the new nested map structure. This is a crucial aspect to ensure the fetcher processes and stores data correctly.

pkg/app.go (1)

119-119: Updated NewConsumerInfoGenerator usage in App constructor.

The App constructor now correctly initializes the ConsumerInfoGenerator with the appConfig.Chains, aligning with the updated constructor requirements. This ensures that the generator has the necessary configuration data to operate.

@freak12techno freak12techno merged commit abe5308 into main Jun 25, 2024
8 checks passed
@freak12techno freak12techno deleted the refactor-consumer-metrics branch June 25, 2024 23:05
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