-
Notifications
You must be signed in to change notification settings - Fork 30
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
Conversation
WalkthroughThe 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
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
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this 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 torelayerMetadata
struct and newrelayerUSDCBalanceGuage
metric incontrib/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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
balanceFloat, _ := new(big.Float).SetInt(relayerBalances[i]).Float64() | ||
usdcBalanceFloat, _ := new(big.Float).SetInt(usdcBalances[i]).Float64() |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
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 ofusdcBalance
field is appropriate.The
usdcBalance
field inrelayerMetadata
is a necessary addition for tracking USDC balances alongside other metrics.
59-61
: Addition ofrelayerUSDCBalanceGuage
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 ofusdcBalance
is correctly implemented.The logic for observing
usdcBalance
inrecordRelayerBalance
is correctly integrated and aligns with the existing structure.
// 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", | ||
} |
There was a problem hiding this comment.
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.
Deploying sanguine-fe with Cloudflare Pages
|
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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
Summary by CodeRabbit
New Features
Bug Fixes
Documentation