mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 06:54:41 +00:00
mempool size metric
This commit is contained in:
+6
-1
@@ -83,10 +83,12 @@ type Mempool struct {
|
||||
wal *auto.AutoFile
|
||||
|
||||
logger log.Logger
|
||||
|
||||
metrics *Metrics
|
||||
}
|
||||
|
||||
// NewMempool returns a new Mempool with the given configuration and connection to an application.
|
||||
func NewMempool(config *cfg.MempoolConfig, proxyAppConn proxy.AppConnMempool, height int64) *Mempool {
|
||||
func NewMempool(config *cfg.MempoolConfig, proxyAppConn proxy.AppConnMempool, height int64, metrics *Metrics) *Mempool {
|
||||
mempool := &Mempool{
|
||||
config: config,
|
||||
proxyAppConn: proxyAppConn,
|
||||
@@ -98,6 +100,7 @@ func NewMempool(config *cfg.MempoolConfig, proxyAppConn proxy.AppConnMempool, he
|
||||
recheckEnd: nil,
|
||||
logger: log.NewNopLogger(),
|
||||
cache: newTxCache(config.CacheSize),
|
||||
metrics: metrics,
|
||||
}
|
||||
proxyAppConn.SetResponseCallback(mempool.resCb)
|
||||
return mempool
|
||||
@@ -250,6 +253,7 @@ func (mem *Mempool) resCb(req *abci.Request, res *abci.Response) {
|
||||
} else {
|
||||
mem.resCbRecheck(req, res)
|
||||
}
|
||||
mem.metrics.Size.Set(float64(mem.Size()))
|
||||
}
|
||||
|
||||
func (mem *Mempool) resCbNormal(req *abci.Request, res *abci.Response) {
|
||||
@@ -393,6 +397,7 @@ func (mem *Mempool) Update(height int64, txs types.Txs) error {
|
||||
// mem.recheckCursor re-scans mem.txs and possibly removes some txs.
|
||||
// Before mem.Reap(), we should wait for mem.recheckCursor to be nil.
|
||||
}
|
||||
mem.metrics.Size.Set(float64(mem.Size()))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ func newMempoolWithApp(cc proxy.ClientCreator) *Mempool {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
mempool := NewMempool(config.Mempool, appConnMem, 0)
|
||||
mempool := NewMempool(config.Mempool, appConnMem, 0, NopMetrics())
|
||||
mempool.SetLogger(log.TestingLogger())
|
||||
return mempool
|
||||
}
|
||||
@@ -241,7 +241,7 @@ func TestMempoolCloseWAL(t *testing.T) {
|
||||
app := kvstore.NewKVStoreApplication()
|
||||
cc := proxy.NewLocalClientCreator(app)
|
||||
appConnMem, _ := cc.NewABCIClient()
|
||||
mempool := NewMempool(wcfg, appConnMem, 10)
|
||||
mempool := NewMempool(wcfg, appConnMem, 10, NopMetrics())
|
||||
mempool.InitWAL()
|
||||
|
||||
// 4. Ensure that the directory contains the WAL file
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package mempool
|
||||
|
||||
import "github.com/go-kit/kit/metrics"
|
||||
import "github.com/go-kit/kit/metrics/discard"
|
||||
|
||||
// Metrics contains metrics exposed by this package.
|
||||
// see MetricsProvider for descriptions.
|
||||
type Metrics struct {
|
||||
Size metrics.Gauge
|
||||
}
|
||||
|
||||
// NopMetrics returns no-op Metrics.
|
||||
func NopMetrics() *Metrics {
|
||||
return &Metrics{
|
||||
Size: discard.NewGauge(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user