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(observability): add prometheus metrics and detailed logging #45

Merged
merged 12 commits into from
Jun 7, 2024

Conversation

k-yang
Copy link
Member

@k-yang k-yang commented Jun 6, 2024

  • add three custom prometheus metrics for tracking price fetching and price posting
  • add more detailed logging for when individual price sources fail
  • add README for new metrics

Summary by CodeRabbit

  • New Features

    • Introduced a command-line tool for a pricefeeder daemon that posts prices to Nibiru Chain.
    • Added Prometheus metrics for tracking price fetching, aggregation, and posting operations.
    • Added a version command to display the current version of the software.
    • Introduced comprehensive logging for error scenarios across various price sources.
  • Documentation

    • Updated README to reflect the latest version for running pricefeeder.
    • Added documentation for metrics in the new metrics/README.md.
  • Chores

    • Updated build configurations and paths in .goreleaser.yml, Dockerfile, and Makefile for improved build processes.
    • Added a new release-snapshot target in the Makefile for creating release snapshots.

@k-yang k-yang requested a review from a team as a code owner June 6, 2024 23:59
@k-yang k-yang self-assigned this Jun 6, 2024
Copy link
Contributor

coderabbitai bot commented Jun 7, 2024

Walkthrough

The recent updates introduce significant improvements to the pricefeeder project. The .goreleaser.yml and Dockerfile changes streamline the build process by simplifying the main path specification. The Makefile adjustments enhance debugging and add a new release snapshot target. Key updates in the cmd and feeder directories add Prometheus metrics for better tracking and error logging. The new metrics package provides detailed documentation and functionality for monitoring various operations.

Changes

File Path Summary
.goreleaser.yml, Dockerfile, Makefile Simplified build paths and added new Makefile target release-snapshot.
README.md Updated git checkout version from v1.0.0 to v1.0.3.
cmd/root.go Introduced command-line tool for pricefeeder daemon with logging and interruption handling.
cmd/version.go Added a new version command using Cobra CLI library.
feeder/priceposter/client.go Added Prometheus metrics for tracking price update transactions.
feeder/priceprovider/aggregateprovider.go Introduced Prometheus metrics for tracking provided prices.
feeder/priceprovider/sources/binance.go Added error logging and metrics for Binance API price fetching.
feeder/priceprovider/sources/bitfinex.go Enhanced error logging and metrics for Bitfinex API.
feeder/priceprovider/sources/bybit.go Added detailed logging and metrics for Bybit API.
feeder/priceprovider/sources/coingecko.go Implemented error logging and metrics for Coingecko API price fetching.
feeder/priceprovider/sources/coinmarketcap.go Added error logging and metrics for Coinmarketcap API.
feeder/priceprovider/sources/gateio.go Enhanced logging and metrics for GateIo API.
feeder/priceprovider/sources/okex.go Improved error logging and metrics for Okex API.
main.go Introduced a simple Go program to execute the cmd.Execute() function.
metrics/README.md, metrics/metrics.go Added documentation and functionality for Prometheus metrics related to price fetching and posting.

Poem

In code we weave a tale so grand,
With metrics new and builds at hand,
From Docker's depths to Makefile's cheer,
Our pricefeeder sings loud and clear.
Metrics track each price we post,
To Nibiru Chain, our proudest boast.
With every change, a brighter day,
For coders, dreamers, here to stay.


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

Outside diff range and nitpick comments (5)
feeder/priceprovider/sources/gateio.go (1)

28-29: Robust error handling and metrics integration.

Consider adding more detailed logging for successful operations to provide better observability.

Also applies to: 36-37, 44-45, 66-66

README.md (4)

Line range hint 79-79: Consider revising the sentence for clarity and grammatical correctness.

- Votes for exchange rates in the [Oracle Module](https://nibiru.fi/docs/ecosystem/oracle/) are posted by validator nodes, however a validator can give consent a `feeder`...
+ Votes for exchange rates in the [Oracle Module](https://nibiru.fi/docs/ecosystem/oracle/) are posted by validator nodes. However, a validator can delegate a `feeder`...

Line range hint 80-80: Simplify the sentence to enhance readability.

- In order to be able to delegate consent to post prices, you need to set the `VALIDATOR_ADDRESS` env variable to the "valoper" address the `feeder` will represent.
+ To delegate consent, set the `VALIDATOR_ADDRESS` env variable to the "valoper" address the `feeder` will represent.

Line range hint 115-115: Revise the sentence to correct the grammatical error.

- Coingecko source allows to use paid api key to get more requests per minute.
+ Coingecko source allows the use of a paid API key to get more requests per minute.

Line range hint 116-116: Avoid repetition to enhance the document's readability.

- In order to configure it, you need to set env var:
+ To configure it, set the env var:
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0408661 and 9b3a3bd.

Files ignored due to path filters (1)
  • go.mod is excluded by !**/*.mod
Files selected for processing (18)
  • .goreleaser.yml (2 hunks)
  • Dockerfile (1 hunks)
  • Makefile (2 hunks)
  • README.md (1 hunks)
  • cmd/root.go (1 hunks)
  • cmd/version.go (1 hunks)
  • feeder/priceposter/client.go (3 hunks)
  • feeder/priceprovider/aggregateprovider.go (3 hunks)
  • feeder/priceprovider/sources/binance.go (3 hunks)
  • feeder/priceprovider/sources/bitfinex.go (3 hunks)
  • feeder/priceprovider/sources/bybit.go (3 hunks)
  • feeder/priceprovider/sources/coingecko.go (2 hunks)
  • feeder/priceprovider/sources/coinmarketcap.go (2 hunks)
  • feeder/priceprovider/sources/gateio.go (3 hunks)
  • feeder/priceprovider/sources/okex.go (3 hunks)
  • main.go (1 hunks)
  • metrics/README.md (1 hunks)
  • metrics/metrics.go (1 hunks)
Files skipped from review due to trivial changes (4)
  • .goreleaser.yml
  • Dockerfile
  • main.go
  • metrics/metrics.go
Additional context used
LanguageTool
metrics/README.md

[uncategorized] ~11-~11: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION)
Context: ...e data sources. labels: - source: The data source from which the price wa...


[uncategorized] ~12-~12: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION)
Context: ...e was fetched, e.g. Bybit. - success: The result of the fetch operation. Poss...


[uncategorized] ~20-~20: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION)
Context: ...videris called. **labels**: -pair`: The pair for which the price was aggreg...


[uncategorized] ~21-~21: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION)
Context: ...ich the price was aggregated. - source: The data source from which the price wa...


[uncategorized] ~22-~22: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION)
Context: ...e was fetched, e.g. Bybit. - success: The result of the fetch operation. Poss...


[uncategorized] ~30-~30: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION)
Context: ...oracle module. labels: - success: The result of the post operation. Possi...

README.md

[typographical] ~79-~79: The word “however” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence. (HOWEVER_SENTENCE)
Context: ...m/oracle/) are posted by validator nodes, however a validator can give consent a feeder...


[style] ~80-~80: Consider a shorter alternative to avoid wordiness. (IN_ORDER_TO_PREMIUM)
Context: ...tor's mnemonic to send transactions. In order to be able to delegate consent to post pri...


[grammar] ~115-~115: Did you mean “using”? Or maybe you should add a pronoun? In active voice, ‘allow’ + ‘to’ takes an object, usually a pronoun. (ALLOW_TO)
Context: ...#### CoinGecko Coingecko source allows to use paid api key to get more requests per m...


[style] ~115-~115: Consider a shorter alternative to avoid wordiness. (IN_ORDER_TO_PREMIUM)
Context: ...pi key to get more requests per minute. In order to configure it, you need to set env var: ...


[style] ~116-~116: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing. (REP_NEED_TO_VB)
Context: ...r minute. In order to configure it, you need to set env var: ```ini DATASOURCE_CONFIG_...

Markdownlint
README.md

3-3: null (MD045, no-alt-text)
Images should have alternate text (alt text)

Additional comments not posted (19)
metrics/README.md (1)

1-30: Documentation is clear and well-structured.

This will help users understand the metrics being collected and their significance.

Tools
LanguageTool

[uncategorized] ~11-~11: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION)
Context: ...e data sources. labels: - source: The data source from which the price wa...


[uncategorized] ~12-~12: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION)
Context: ...e was fetched, e.g. Bybit. - success: The result of the fetch operation. Poss...


[uncategorized] ~20-~20: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION)
Context: ...videris called. **labels**: -pair`: The pair for which the price was aggreg...


[uncategorized] ~21-~21: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION)
Context: ...ich the price was aggregated. - source: The data source from which the price wa...


[uncategorized] ~22-~22: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION)
Context: ...e was fetched, e.g. Bybit. - success: The result of the fetch operation. Poss...


[uncategorized] ~30-~30: Loose punctuation mark. (UNLIKELY_OPENING_PUNCTUATION)
Context: ...oracle module. labels: - success: The result of the post operation. Possi...

Makefile (1)

14-14: Changes to the Makefile are appropriate and align with the new directory structure.

Also applies to: 17-17, 49-58

feeder/priceprovider/sources/binance.go (2)

9-9: Proper integration of Prometheus metrics and enhanced error logging aligns with the PR objectives.

Also applies to: 40-41, 48-49, 57-58


67-67: Correct placement of metric incrementation for successful operations.

feeder/priceprovider/sources/okex.go (2)

11-11: Effective use of Prometheus metrics and enhanced error logging for better observability.

Also applies to: 38-39, 46-47, 54-55


77-77: Correct implementation of metric incrementation upon successful price fetch.

feeder/priceprovider/sources/bybit.go (2)

10-10: Effective integration of Prometheus metrics and enhanced error logging for improved observability.

Also applies to: 37-38, 45-46, 53-54


73-73: Proper implementation of metric incrementation upon successful price fetch.

feeder/priceprovider/sources/bitfinex.go (2)

10-10: Effective integration of Prometheus metrics and enhanced error logging for improved observability.

Also applies to: 39-40, 47-48, 55-56


72-72: Proper implementation of metric incrementation upon successful price fetch.

cmd/root.go (3)

21-32: The setupLogger function is well-implemented and correctly sets the log level based on the debug flag.


34-45: The handleInterrupt function correctly implements a graceful shutdown process for the application.


78-83: The Execute function is correctly implemented to handle command execution and error management.

feeder/priceprovider/aggregateprovider.go (1)

43-47: The integration of Prometheus metrics in the AggregatePriceProvider is correctly implemented to track the number of prices provided, with appropriate labels for success status.

Also applies to: 58-58, 65-65

feeder/priceprovider/sources/coingecko.go (1)

35-36: The error handling and Prometheus metrics updates in the CoingeckoPriceUpdate function are well-implemented, providing detailed logs and metrics for different failure scenarios.

Also applies to: 42-43, 50-51, 57-58, 62-62

feeder/priceposter/client.go (1)

108-112: The integration of Prometheus metrics in the Client class is correctly implemented to track the number of price update transactions sent to the chain, with appropriate labels for success status.

Also applies to: 124-124, 130-130

feeder/priceprovider/sources/coinmarketcap.go (2)

12-12: Ensure the new import is used effectively throughout the file.


48-49: Enhanced error handling and metrics tracking are well-implemented.

Also applies to: 55-56, 63-64, 71-72, 78-79, 83-83

README.md (1)

39-39: Updated version in git checkout command aligns with the PR description.

Comment on lines +13 to +20
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of Hugo",
Long: `All software has versions. This is Hugo's`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("v1.0.3")
},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider fetching the version dynamically from a configuration file or environment variable.

This would allow easier updates and consistency across deployments without needing to recompile the binary.

@k-yang k-yang merged commit 48905d3 into main Jun 7, 2024
1 of 2 checks passed
@k-yang k-yang deleted the feat/version-command branch June 7, 2024 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Completed
Development

Successfully merging this pull request may close these issues.

1 participant