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): Grafana usdc balances #3034

Merged
merged 2 commits into from
Aug 16, 2024
Merged

Conversation

golangisfun123
Copy link
Collaborator

@golangisfun123 golangisfun123 commented Aug 16, 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 relayer metadata to include USDC balance tracking.
    • Updated monitoring capabilities to include real-time tracking of USDC balances.
    • Added functionality to fetch and return USDC balances alongside existing relayer balances.
  • Bug Fixes

    • Improved error handling during metric registration to ensure stability.
  • Documentation

    • Updated comments and descriptions to reflect new USDC balance functionality.

@github-actions github-actions bot added go Pull requests that update Go code size/s labels Aug 16, 2024
Copy link
Contributor

coderabbitai bot commented Aug 16, 2024

Walkthrough

The changes enhance the Prometheus exporter by introducing support for tracking USDC balances alongside existing relayer balance metrics. This involves modifying data structures to include USDC balance fields, updating methods for fetching and recording balances, and integrating new metrics for monitoring. Overall, these updates improve the financial tracking capabilities of the application.

Changes

Files Change Summary
contrib/promexporter/exporters/otel.go Modified relayerMetadata and otelRecorder to include USDC balance tracking, updated methods for observing new metrics.
contrib/promexporter/exporters/relayer.go Enhanced fetchRelayerBalances to retrieve USDC balances, added mapping for USDC addresses, and updated balance retrieval logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Relayer
    participant MetricSystem

    User->>Relayer: Request relayer balances
    Relayer->>MetricSystem: Fetch standard balances
    Relayer->>MetricSystem: Fetch USDC balances
    MetricSystem-->>Relayer: Return balances
    Relayer-->>User: Send combined balance report
Loading

🐰 In the meadow where balances grow,
USDC now joins the flow!
With metrics to track, both near and far,
A bright new path for every star.
Hop and cheer, the changes are here,
Financial insights, loud and clear! 🌟


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

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR enhances the Prometheus exporter to track and report USDC balances for relayers across different chains, improving monitoring capabilities.

  • Added usdcBalance field to relayerMetadata struct and new relayerUSDCBalanceGuage metric in contrib/promexporter/exporters/otel.go
  • Introduced map of USDC addresses for various chain IDs in contrib/promexporter/exporters/relayer.go
  • Modified fetchRelayerBalances function to fetch and record both native token and USDC balances
  • Updated recordRelayerBalance function to observe and report USDC balances alongside native token balances

2 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings

relayerBalanceGauge metric.Float64ObservableGauge
relayerBalance *hashmap.Map[int, []relayerMetadata]
relayerBalanceGauge metric.Float64ObservableGauge
relayerUSDCBalanceGuage metric.Float64ObservableGauge
Copy link

Choose a reason for hiding this comment

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

syntax: Typo in variable name: 'Guage' should be 'Gauge'

@@ -110,6 +112,10 @@ func newOtelRecorder(meterHandler metrics.Handler) iOtelRecorder {
log.Warnf("failed to create relayerBalance gauge: %v", err)
}

if otr.relayerUSDCBalanceGuage, err = otr.meter.Float64ObservableGauge("relayer_usdc_balance"); err != nil {
Copy link

Choose a reason for hiding this comment

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

syntax: Typo in variable name: 'Guage' should be 'Gauge'

@@ -140,7 +146,7 @@ func newOtelRecorder(meterHandler metrics.Handler) iOtelRecorder {
}

// The Relayer code of interest.
if _, err = otr.meter.RegisterCallback(otr.recordRelayerBalance, otr.relayerBalanceGauge); err != nil {
if _, err = otr.meter.RegisterCallback(otr.recordRelayerBalance, otr.relayerBalanceGauge, otr.relayerUSDCBalanceGuage); err != nil {
Copy link

Choose a reason for hiding this comment

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

syntax: Typo in variable name: 'Guage' should be 'Gauge'

decoders.FuncBalanceOf(),
common.HexToAddress(usdcAddresses[chainID]),
common.HexToAddress(relayer)).Returns(usdcBalances[i]),
)
}

_ = e.batchCalls(ctx, client, callsForCurrentChainID)
Copy link

Choose a reason for hiding this comment

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

logic: Ignoring the error returned by e.batchCalls may hide important issues. Consider proper error handling.

Comment on lines +83 to +84
balanceFloat, _ := new(big.Float).SetInt(relayerBalances[i]).Float64()
usdcBalanceFloat, _ := new(big.Float).SetInt(usdcBalances[i]).Float64()
Copy link

Choose a reason for hiding this comment

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

style: Error values from Float64() calls are discarded. Consider handling these errors.

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, codebase verification and nitpick comments (1)
contrib/promexporter/exporters/relayer.go (1)

Line range hint 30-88: Balance fetching logic looks good, but consider refactoring.

The integration of USDC balance fetching is well-implemented. However, the function is doing multiple tasks, which increases its complexity. Consider breaking it down into smaller functions to improve readability and maintainability.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b8b895f and 6223a1d.

Files selected for processing (2)
  • contrib/promexporter/exporters/otel.go (5 hunks)
  • contrib/promexporter/exporters/relayer.go (3 hunks)
Additional comments not posted (4)
contrib/promexporter/exporters/otel.go (4)

24-26: Addition of usdcBalance field is appropriate.

The usdcBalance field in relayerMetadata is a necessary addition for tracking USDC balances alongside other metrics.


59-61: Addition of relayerUSDCBalanceGuage is well-implemented.

The relayerUSDCBalanceGuage is a valuable addition for monitoring USDC balances. Ensure that it is correctly registered and used in the system.


115-117: Gauge initialization is correct.

The initialization of relayerUSDCBalanceGuage is handled correctly with appropriate error logging.


365-372: Observation of usdcBalance is correctly implemented.

The logic for observing usdcBalance in recordRelayerBalance is correctly integrated and aligns with the existing structure.

Comment on lines +20 to +28
// TODO: This is ugly. We can probably get this from the config.
var usdcAddresses = map[int]string{
1: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
10: "0x0b2c639c533813f4aa9d7837caf62653d097ff85",
42161: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
8453: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
534352: "0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4",
59144: "0x176211869cA2b568f2A7D4EE941E073a821EE1ff",
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider externalizing USDC addresses.

The usdcAddresses map is hardcoded, which may lead to difficulties in updating or managing these values. Consider moving this configuration to an external file or environment variable for better maintainability.

Copy link

cloudflare-workers-and-pages bot commented Aug 16, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6223a1d
Status: ✅  Deploy successful!
Preview URL: https://6e0b165a.sanguine-fe.pages.dev
Branch Preview URL: https://grafana-usdc-balances.sanguine-fe.pages.dev

View logs

Copy link

codecov bot commented Aug 16, 2024

Codecov Report

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

Project coverage is 23.37642%. Comparing base (317c07d) to head (6223a1d).
Report is 3 commits behind head on master.

Files Patch % Lines
contrib/promexporter/exporters/relayer.go 0.00000% 15 Missing ⚠️
contrib/promexporter/exporters/otel.go 0.00000% 12 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #3034         +/-   ##
===================================================
- Coverage   23.38668%   23.37642%   -0.01026%     
===================================================
  Files            644         644                 
  Lines          50114       50136         +22     
  Branches          82          82                 
===================================================
  Hits           11720       11720                 
- Misses         37231       37253         +22     
  Partials        1163        1163                 
Flag Coverage Δ
promexporter 6.94006% <0.00000%> (-0.12254%) ⬇️

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.

@trajan0x trajan0x merged commit e32854b into master Aug 16, 2024
28 of 29 checks passed
@trajan0x trajan0x deleted the grafana-usdc-balances branch August 16, 2024 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code size/s
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants