Skip to content
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
20 changes: 13 additions & 7 deletions metrics/txm.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ var (
float64(100),
},
}, []string{"chainID"})
promNumInsufficientFunds = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "tx_manager_insufficient_funds_tx_count",
Help: "Number of transaction broadcast attempts rejected by an RPC node because the sending address had insufficient funds. Increments on every retry while the address remains underfunded, so a sustained rate indicates the address needs topping up.",
}, []string{"chainID", "senderAddress"})
promAttemptError = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "tx_manager_attempt_error_total",
Comment thread
amit-momin marked this conversation as resolved.
Help: "Number of transaction broadcast/confirm attempts that failed, labelled by cause. For cause=\"insufficient_funds\" the sending address was rejected by an RPC node for insufficient funds; it increments on every retry while the address remains underfunded, so a sustained rate indicates the address needs topping up.",
}, []string{"chainID", "senderAddress", "cause"})
)

// Attempt error causes, used as the `cause` label on tx_manager_attempt_error_total.
const (
attemptErrorCauseInsufficientFunds = "insufficient_funds"
)

type GenericTXMMetrics interface {
Expand Down Expand Up @@ -136,9 +141,9 @@ func NewGenericTxmMetrics(chainID string) (GenericTXMMetrics, error) {
return nil, fmt.Errorf("failed to register blocks until tx confirmed metric: %w", err)
}

numInsufficientFundsTxs, err := beholder.GetMeter().Int64Counter("tx_manager_insufficient_funds_tx_count")
numInsufficientFundsTxs, err := beholder.GetMeter().Int64Counter("tx_manager_attempt_error_total")
if err != nil {
return nil, fmt.Errorf("failed to register insufficient funds txs metric: %w", err)
return nil, fmt.Errorf("failed to register attempt error metric: %w", err)
}

return &txmMetrics{
Expand Down Expand Up @@ -190,9 +195,10 @@ func (m *txmMetrics) RecordBlocksUntilTxConfirmed(ctx context.Context, blocksEla
}

func (m *txmMetrics) IncrementNumInsufficientFundsForTx(ctx context.Context, fromAddress string) {
promNumInsufficientFunds.WithLabelValues(m.chainID, fromAddress).Add(1)
promAttemptError.WithLabelValues(m.chainID, fromAddress, attemptErrorCauseInsufficientFunds).Add(1)
m.numInsufficientFundsTxs.Add(ctx, 1, metric.WithAttributes(
attribute.String("chainID", m.chainID),
attribute.String("senderAddress", fromAddress),
attribute.String("cause", attemptErrorCauseInsufficientFunds),
))
}
2 changes: 1 addition & 1 deletion metrics/txm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestTxmMetrics_IncrementNumInsufficientFundsForTx(t *testing.T) {

require.InEpsilon(t,
2.0,
testutil.ToFloat64(promNumInsufficientFunds.WithLabelValues("1", "0xSenderAddress")),
testutil.ToFloat64(promAttemptError.WithLabelValues("1", "0xSenderAddress", "insufficient_funds")),
0.001,
)
}
Loading