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: add inflation metric #77

Merged
merged 2 commits into from
Jul 28, 2024
Merged

feat: add inflation metric #77

merged 2 commits into from
Jul 28, 2024

Conversation

freak12techno
Copy link
Collaborator

@freak12techno freak12techno commented Jul 28, 2024

Summary by CodeRabbit

  • New Features

    • Introduced inflation data fetching and generation capabilities.
    • Added a new JSON configuration file for inflation rates.
    • Implemented new methods to retrieve inflation data via RPC.
  • Bug Fixes

    • Enhanced error handling and testing for inflation data fetching.
  • Tests

    • Added comprehensive unit tests for inflation fetching and generating functionalities.
  • Documentation

    • Updated documentation to reflect new constants and methods related to inflation.

Copy link
Contributor

coderabbitai bot commented Jul 28, 2024

Walkthrough

The recent changes introduce robust functionalities for handling inflation data within the application. Key additions include an inflation JSON configuration file, a dedicated fetcher and generator for inflation data, and an enhanced RPC structure for querying inflation metrics. These updates streamline data retrieval and monitoring, laying the groundwork for comprehensive financial analysis capabilities.

Changes

Files Change Summary
assets/inflation.json Added a JSON file with a high-precision inflation rate.
pkg/app.go Enhanced NewApp function by adding inflation fetcher and generator instances.
pkg/constants/constants.go Introduced FetcherNameInflation constant for improved data fetching.
pkg/fetchers/inflation.go Implemented InflationFetcher for fetching inflation data; added methods and struct definitions.
pkg/fetchers/inflation_test.go Added unit tests for the InflationFetcher functionality.
pkg/generators/inflation.go Defined InflationGenerator for generating inflation metrics; included methods for metric collection.
pkg/generators/inflation_test.go Added unit tests for the InflationGenerator functionality.
pkg/tendermint/rpc.go Introduced GetInflation method in RPC struct to fetch inflation data from a URL.
pkg/types/tendermint.go Added InflationResponse type to model inflation data responses.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App as Application
    participant Fetcher as InflationFetcher
    participant RPC as RPC Client
    participant Generator as InflationGenerator
    participant Metrics as Prometheus

    User->>App: Request Inflation Data
    App->>Fetcher: Fetch Inflation Data
    Fetcher->>RPC: GetInflation()
    RPC-->>Fetcher: Return InflationResponse
    Fetcher-->>App: Provide Inflation Data
    App->>Generator: Generate Metrics
    Generator->>Metrics: Collect Inflation Metrics
    Metrics-->>App: Metrics Updated
    App-->>User: Respond with Inflation Data
Loading

Poem

🐇 In fields of data, I hop and play,
With inflation metrics brightening the day.
Fetchers and generators, a wondrous sight,
Helping us measure with all of their might!
So let’s cheer for changes, both big and small,
A leap in our app, we celebrate all! 🎉


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 Configuration 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 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (058a297) to head (4a1f2c4).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #77   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           63        65    +2     
  Lines         2585      2657   +72     
=========================================
+ Hits          2585      2657   +72     

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

Outside diff range, codebase verification and nitpick comments (2)
pkg/app.go (2)

98-98: Add a comment for the new inflation fetcher.

Consider adding a comment to explain the purpose of the new NewInflationFetcher for consistency with other fetchers.

// NewInflationFetcher fetches inflation data
fetchersPkg.NewInflationFetcher(logger, appConfig.Chains, rpcs, tracer),

124-124: Add a comment for the new inflation generator.

Consider adding a comment to explain the purpose of the new NewInflationGenerator for consistency with other generators.

// NewInflationGenerator generates inflation metrics
generatorsPkg.NewInflationGenerator(),
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 058a297 and 4a1f2c4.

Files selected for processing (9)
  • assets/inflation.json (1 hunks)
  • pkg/app.go (2 hunks)
  • pkg/constants/constants.go (1 hunks)
  • pkg/fetchers/inflation.go (1 hunks)
  • pkg/fetchers/inflation_test.go (1 hunks)
  • pkg/generators/inflation.go (1 hunks)
  • pkg/generators/inflation_test.go (1 hunks)
  • pkg/tendermint/rpc.go (1 hunks)
  • pkg/types/tendermint.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • assets/inflation.json
Additional context used
Learnings (1)
pkg/fetchers/inflation_test.go (2)
Learnt from: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#63
File: pkg/fetchers/validators.go:28-34
Timestamp: 2024-06-23T11:24:50.154Z
Learning: The constructor function `NewValidatorsFetcher` in `pkg/fetchers/validators.go` is now covered by tests in `validators_test.go`.
Learnt from: freak12techno
PR: QuokkaStake/cosmos-validators-exporter#63
File: pkg/fetchers/soft_opt_out_threshold.go:28-34
Timestamp: 2024-06-23T11:25:06.862Z
Learning: The `NewSoftOptOutThresholdFetcher` constructor function in `pkg/fetchers/soft_opt_out_threshold.go` is now covered by tests as verified by the presence of its usage in `pkg/fetchers/soft_opt_out_threshold_test.go`.
Additional comments not posted (17)
pkg/generators/inflation.go (3)

11-16: LGTM!

The InflationGenerator struct and NewInflationGenerator function are correctly defined.


24-40: LGTM!

The Prometheus gauge creation and data population are correctly implemented.


40-41: LGTM!

The return statement is correct.

pkg/generators/inflation_test.go (2)

17-24: LGTM!

The TestInflationGeneratorNoState test is correctly written and follows best practices.


26-45: LGTM!

The TestInflationGeneratorNotEmptyState test is well-structured and covers the necessary assertions.

pkg/constants/constants.go (1)

24-24: LGTM!

The new constant FetcherNameInflation is correctly added and follows the existing pattern.

pkg/fetchers/inflation.go (5)

17-22: LGTM! Struct definition is well-defined.

The InflationFetcher struct is well-defined with appropriate fields for logger, chains, RPCs, and tracer.


24-26: LGTM! Struct definition is simple and well-defined.

The InflationData struct is simple and well-defined with a single field for inflation data.


28-39: LGTM! Constructor function is well-implemented.

The NewInflationFetcher function is well-implemented. It initializes the fields and returns a new instance of InflationFetcher.


42-89: LGTM! Function implementation is well-implemented.

The Fetch function retrieves inflation data for multiple chains concurrently. It uses goroutines and a wait group to fetch data concurrently. It handles errors and logs them appropriately. The use of mutex ensures thread safety when updating shared data.


92-94: LGTM! Function implementation is simple and well-implemented.

The Name function returns the name of the fetcher.

pkg/types/tendermint.go (1)

203-206: LGTM! Type definition is simple and well-implemented.

The InflationResponse type definition has fields for code and inflation.

pkg/fetchers/inflation_test.go (5)

20-50: LGTM! Test function is well-implemented.

The TestInflationFetcherBase function tests the basic functionality of InflationFetcher. It checks the initialization and name of the fetcher.


52-81: LGTM! Test function is well-implemented.

The TestInflationFetcherQueryDisabled function tests the behavior when the inflation query is disabled. It checks that no queries are made and the inflation data is empty.


83-120: LGTM! Test function is well-implemented.

The TestInflationFetcherQueryError function tests the behavior when there is an error querying the inflation data. It checks that the query is marked as unsuccessful and the inflation data is empty.


122-159: LGTM! Test function is well-implemented.

The TestInflationFetcherNodeError function tests the behavior when the node returns an error response. It checks that the query is marked as unsuccessful and the inflation data is empty.


161-205: LGTM! Test function is well-implemented.

The TestInflationFetcherQuerySuccess function tests the behavior when the inflation query is successful. It checks that the query is marked as successful and the inflation data is correctly populated.

pkg/tendermint/rpc.go Show resolved Hide resolved
pkg/generators/inflation.go Show resolved Hide resolved
pkg/generators/inflation.go Show resolved Hide resolved
@freak12techno freak12techno merged commit 8b331e8 into main Jul 28, 2024
8 checks passed
@freak12techno freak12techno deleted the add-inflation branch July 28, 2024 17:20
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