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

Export wallet address for Prometheus metrics #1206

Merged
merged 6 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions relayer/chains/cosmos/cosmos_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,22 +516,25 @@ func (ccp *CosmosChainProcessor) CurrentRelayerBalance(ctx context.Context) {
}

// Get the balance for the chain provider's key
relayerWalletBalance, err := ccp.chainProvider.QueryBalance(ctx, ccp.chainProvider.Key())
relayerWalletBalances, err := ccp.chainProvider.QueryBalance(ctx, ccp.chainProvider.Key())
if err != nil {
ccp.log.Error(
"Failed to query relayer balance",
zap.Error(err),
)
}

address, err := ccp.chainProvider.Address()
if err != nil {
ccp.log.Error(
"Failed to get relayer bech32 wallet addresss",
zap.Error(err),
)
}
// Print the relevant gas prices
for _, gasDenom := range *ccp.parsedGasPrices {
for _, balance := range relayerWalletBalance {
if balance.Denom == gasDenom.Denom {
// Convert to a big float to get a float64 for metrics
f, _ := big.NewFloat(0.0).SetInt(balance.Amount.BigInt()).Float64()
ccp.metrics.SetWalletBalance(ccp.chainProvider.ChainId(), ccp.chainProvider.Key(), balance.Denom, f)
}
}
bal := relayerWalletBalances.AmountOf(gasDenom.Denom)
// Convert to a big float to get a float64 for metrics
f, _ := big.NewFloat(0.0).SetInt(bal.BigInt()).Float64()
ccp.metrics.SetWalletBalance(ccp.chainProvider.ChainId(), ccp.chainProvider.Key(), address, gasDenom.Denom, f)
}
}
14 changes: 10 additions & 4 deletions relayer/chains/cosmos/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,14 @@ func (cc *CosmosProvider) broadcastTx(
cc.LogFailedTx(rlyResp, err, msgs)
return err
}

cc.UpdateFeesSpent(cc.ChainId(), cc.Key(), fees)
address, err := cc.Address()
if err != nil {
cc.log.Error(
"failed to get relayer bech32 wallet addresss",
zap.Error(err),
)
}
cc.UpdateFeesSpent(cc.ChainId(), cc.Key(), address, fees)

// TODO: maybe we need to check if the node has tx indexing enabled?
// if not, we need to find a new way to block until inclusion in a block
Expand Down Expand Up @@ -1257,7 +1263,7 @@ func (cc *CosmosProvider) NewClientState(
}, nil
}

func (cc *CosmosProvider) UpdateFeesSpent(chain, key string, fees sdk.Coins) {
func (cc *CosmosProvider) UpdateFeesSpent(chain, key, address string, fees sdk.Coins) {
// Don't set the metrics in testing
if cc.metrics == nil {
return
Expand All @@ -1270,7 +1276,7 @@ func (cc *CosmosProvider) UpdateFeesSpent(chain, key string, fees sdk.Coins) {
for _, fee := range cc.TotalFees {
// Convert to a big float to get a float64 for metrics
f, _ := big.NewFloat(0.0).SetInt(fee.Amount.BigInt()).Float64()
cc.metrics.SetFeesSpent(chain, key, fee.GetDenom(), f)
cc.metrics.SetFeesSpent(chain, key, address, fee.GetDenom(), f)
}
}

Expand Down
10 changes: 5 additions & 5 deletions relayer/processor/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ func (m *PrometheusMetrics) SetLatestHeight(chain string, height int64) {
m.LatestHeightGauge.WithLabelValues(chain).Set(float64(height))
}

func (m *PrometheusMetrics) SetWalletBalance(chain, key, denom string, balance float64) {
m.WalletBalance.WithLabelValues(chain, key, denom).Set(balance)
func (m *PrometheusMetrics) SetWalletBalance(chain, key, address, denom string, balance float64) {
m.WalletBalance.WithLabelValues(chain, key, address, denom).Set(balance)
}

func (m *PrometheusMetrics) SetFeesSpent(chain, key, denom string, amount float64) {
m.FeesSpent.WithLabelValues(chain, key, denom).Set(amount)
func (m *PrometheusMetrics) SetFeesSpent(chain, key, address, denom string, amount float64) {
m.FeesSpent.WithLabelValues(chain, key, address, denom).Set(amount)
}

func NewPrometheusMetrics() *PrometheusMetrics {
packetLabels := []string{"path", "chain", "channel", "port", "type"}
heightLabels := []string{"chain"}
walletLabels := []string{"chain", "key", "denom"}
walletLabels := []string{"chain", "key", "address", "denom"}
registry := prometheus.NewRegistry()
registerer := promauto.With(registry)
return &PrometheusMetrics{
Expand Down