-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add balance checker #17
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ import ( | |||||||||
| "github.com/evstack/ev-metrics/internal/clients/celestia" | ||||||||||
| "github.com/evstack/ev-metrics/internal/clients/evm" | ||||||||||
| "github.com/evstack/ev-metrics/internal/clients/evnode" | ||||||||||
| "github.com/evstack/ev-metrics/pkg/exporters/balance" | ||||||||||
| "github.com/evstack/ev-metrics/pkg/exporters/drift" | ||||||||||
| "github.com/evstack/ev-metrics/pkg/exporters/jsonrpc" | ||||||||||
| "github.com/evstack/ev-metrics/pkg/exporters/verifier" | ||||||||||
|
|
@@ -38,6 +39,9 @@ const ( | |||||||||
| flagFullNodes = "full-nodes" | ||||||||||
| flagPollingInterval = "polling-interval" | ||||||||||
| flagJsonRpcScrapeInterval = "jsonrpc-scrape-interval" | ||||||||||
| flagBalanceAddresses = "balance.addresses" | ||||||||||
| flagBalanceRpcUrls = "balance.consensus-rpc-urls" | ||||||||||
| flagBalanceScrapeInterval = "balance.scrape-interval" | ||||||||||
|
|
||||||||||
| metricsPath = "/metrics" | ||||||||||
| ) | ||||||||||
|
|
@@ -60,6 +64,9 @@ type flagValues struct { | |||||||||
| fullNodes string | ||||||||||
| pollingInterval int | ||||||||||
| jsonRpcScrapeInterval int | ||||||||||
| balanceAddresses string | ||||||||||
| balanceRpcUrls string | ||||||||||
| balanceScrapeInterval int | ||||||||||
| } | ||||||||||
|
|
||||||||||
| func NewMonitorCmd() *cobra.Command { | ||||||||||
|
|
@@ -89,6 +96,9 @@ func NewMonitorCmd() *cobra.Command { | |||||||||
| cmd.Flags().StringVar(&flags.fullNodes, flagFullNodes, "", "Comma-separated list of full node RPC endpoint URLs for drift monitoring") | ||||||||||
| cmd.Flags().IntVar(&flags.pollingInterval, flagPollingInterval, 10, "Polling interval in seconds for checking node block heights (default: 10)") | ||||||||||
| cmd.Flags().IntVar(&flags.jsonRpcScrapeInterval, flagJsonRpcScrapeInterval, 10, "JSON-RPC health check scrape interval in seconds (default: 10)") | ||||||||||
| cmd.Flags().StringVar(&flags.balanceAddresses, flagBalanceAddresses, "", "Comma-separated celestia addresses to monitor (enables balance checking)") | ||||||||||
| cmd.Flags().StringVar(&flags.balanceRpcUrls, flagBalanceRpcUrls, "", "Comma-separated consensus rpc urls for balance queries (required if balance.addresses is set)") | ||||||||||
| cmd.Flags().IntVar(&flags.balanceScrapeInterval, flagBalanceScrapeInterval, 30, "Balance check scrape interval in seconds (default: 30)") | ||||||||||
|
|
||||||||||
| if err := cmd.MarkFlagRequired(flagHeaderNS); err != nil { | ||||||||||
| panic(err) | ||||||||||
|
|
@@ -208,6 +218,30 @@ func monitorAndExportMetrics(_ *cobra.Command, _ []string) error { | |||||||||
| exporters = append(exporters, jsonrpc.NewMetricsExporter(flags.chainID, cfg.EvmClient, flags.jsonRpcScrapeInterval, logger)) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // start balance monitoring if balance.addresses is provided | ||||||||||
| if flags.balanceAddresses != "" { | ||||||||||
| if flags.balanceRpcUrls == "" { | ||||||||||
| return fmt.Errorf("--balance.consensus-rpc-urls is required when --balance.addresses is set") | ||||||||||
| } | ||||||||||
|
|
||||||||||
| addressList := strings.Split(flags.balanceAddresses, ",") | ||||||||||
| rpcUrls := strings.Split(flags.balanceRpcUrls, ",") | ||||||||||
|
Comment on lines
+227
to
+228
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While splitting comma-separated strings is a common pattern, it can be brittle if users accidentally add extra spaces (e.g.,
Suggested change
|
||||||||||
|
|
||||||||||
| exporters = append(exporters, balance.NewMetricsExporter( | ||||||||||
| flags.chainID, | ||||||||||
| addressList, | ||||||||||
| rpcUrls, | ||||||||||
| flags.balanceScrapeInterval, | ||||||||||
| logger, | ||||||||||
| )) | ||||||||||
|
|
||||||||||
| logger.Info(). | ||||||||||
| Strs("addresses", addressList). | ||||||||||
| Strs("rpc_urls", rpcUrls). | ||||||||||
| Int("scrape_interval", flags.balanceScrapeInterval). | ||||||||||
| Msg("balance monitoring enabled") | ||||||||||
| } | ||||||||||
|
|
||||||||||
| err = metrics.StartServer(ctx, metricsPath, flags.port, logger, exporters...) | ||||||||||
|
|
||||||||||
| // context.Canceled is expected during graceful shutdown, not an error | ||||||||||
|
|
||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The namespaces in this example (
collect_testnet_header,collect_testnet_data) are inconsistent with the changes made elsewhere in this README, where they were updated totestnet_headerandtestnet_data. For consistency, this example should also use the updated namespace names.