Skip to content

Commit

Permalink
feat(mempool): add metric size of pool in bytes (backport #1195) (#1220)
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] committed Feb 9, 2024
1 parent 6ea7f18 commit 0246db1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mempool/cat/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ func (txmp *TxPool) Update(
// transactions are left.
size := txmp.Size()
txmp.metrics.Size.Set(float64(size))
txmp.metrics.SizeBytes.Set(float64(txmp.SizeBytes()))
if size > 0 {
if txmp.config.Recheck {
txmp.recheckTransactions()
Expand Down Expand Up @@ -576,6 +577,7 @@ func (txmp *TxPool) addNewTransaction(wtx *wrappedTx, checkTxRes *abci.ResponseC

txmp.metrics.TxSizeBytes.Observe(float64(wtx.size()))
txmp.metrics.Size.Set(float64(txmp.Size()))
txmp.metrics.SizeBytes.Set(float64(txmp.SizeBytes()))
txmp.logger.Debug(
"inserted new valid transaction",
"priority", wtx.priority,
Expand Down Expand Up @@ -628,6 +630,7 @@ func (txmp *TxPool) handleRecheckResult(wtx *wrappedTx, checkTxRes *abci.Respons
}
txmp.metrics.FailedTxs.Add(1)
txmp.metrics.Size.Set(float64(txmp.Size()))
txmp.metrics.SizeBytes.Set(float64(txmp.SizeBytes()))
}

// recheckTransactions initiates re-CheckTx ABCI calls for all the transactions
Expand Down
11 changes: 11 additions & 0 deletions mempool/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type Metrics struct {
// Size of the mempool.
Size metrics.Gauge

// Total size of the mempool in bytes.
SizeBytes metrics.Gauge

// Histogram of transaction sizes, in bytes.
TxSizeBytes metrics.Histogram

Expand Down Expand Up @@ -81,6 +84,13 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
Help: "Size of the mempool (number of uncommitted transactions).",
}, labels).With(labelsAndValues...),

SizeBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Namespace: namespace,
Subsystem: MetricsSubsystem,
Name: "size_bytes",
Help: "Total size of the mempool in bytes.",
}, labels).With(labelsAndValues...),

TxSizeBytes: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
Namespace: namespace,
Subsystem: MetricsSubsystem,
Expand Down Expand Up @@ -144,6 +154,7 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
func NopMetrics() *Metrics {
return &Metrics{
Size: discard.NewGauge(),
SizeBytes: discard.NewGauge(),
TxSizeBytes: discard.NewHistogram(),
FailedTxs: discard.NewCounter(),
EvictedTxs: discard.NewCounter(),
Expand Down
3 changes: 3 additions & 0 deletions mempool/v0/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ func (mem *CListMempool) globalCb(req *abci.Request, res *abci.Response) {

// update metrics
mem.metrics.Size.Set(float64(mem.Size()))
mem.metrics.SizeBytes.Set(float64(mem.SizeBytes()))
}

// Request specific callback that should be set on individual reqRes objects
Expand Down Expand Up @@ -304,6 +305,7 @@ func (mem *CListMempool) reqResCb(

// update metrics
mem.metrics.Size.Set(float64(mem.Size()))
mem.metrics.SizeBytes.Set(float64(mem.SizeBytes()))

// passed in by the caller of CheckTx, eg. the RPC
if externalCb != nil {
Expand Down Expand Up @@ -653,6 +655,7 @@ func (mem *CListMempool) Update(

// Update metrics
mem.metrics.Size.Set(float64(mem.Size()))
mem.metrics.SizeBytes.Set(float64(mem.SizeBytes()))

return nil
}
Expand Down
3 changes: 3 additions & 0 deletions mempool/v1/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ func (txmp *TxMempool) Update(
// transactions are left.
size := txmp.Size()
txmp.metrics.Size.Set(float64(size))
txmp.metrics.SizeBytes.Set(float64(txmp.SizeBytes()))
if size > 0 {
if txmp.config.Recheck {
txmp.recheckTransactions()
Expand Down Expand Up @@ -608,6 +609,7 @@ func (txmp *TxMempool) addNewTransaction(wtx *WrappedTx, checkTxRes *abci.Respon

txmp.metrics.TxSizeBytes.Observe(float64(wtx.Size()))
txmp.metrics.Size.Set(float64(txmp.Size()))
txmp.metrics.SizeBytes.Set(float64(txmp.SizeBytes()))
txmp.logger.Debug(
"inserted new valid transaction",
"priority", wtx.Priority(),
Expand Down Expand Up @@ -675,6 +677,7 @@ func (txmp *TxMempool) handleRecheckResult(tx types.Tx, checkTxRes *abci.Respons
}
}
txmp.metrics.Size.Set(float64(txmp.Size()))
txmp.metrics.SizeBytes.Set(float64(txmp.SizeBytes()))
}

// recheckTransactions initiates re-CheckTx ABCI calls for all the transactions
Expand Down

0 comments on commit 0246db1

Please sign in to comment.