internal/proxy: add initial set of abci metrics backport (#7342)
* internal/proxy: add initial set of abci metrics (#7115)
This PR adds an initial set of metrics for use ABCI. The initial metrics enable the calculation of timing histograms and call counts for each of the ABCI methods. The metrics are also labeled as either 'sync' or 'async' to determine if the method call was performed using ABCI's `*Async` methods.
An example of these metrics is included here for reference:
```
tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0001"} 0
tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.0004"} 5
tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.002"} 12
tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.009"} 13
tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.02"} 13
tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.1"} 13
tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="0.65"} 13
tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="2"} 13
tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="6"} 13
tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="25"} 13
tendermint_abci_connection_method_timing_bucket{chain_id="ci",method="commit",type="sync",le="+Inf"} 13
tendermint_abci_connection_method_timing_sum{chain_id="ci",method="commit",type="sync"} 0.007802058000000001
tendermint_abci_connection_method_timing_count{chain_id="ci",method="commit",type="sync"} 13
```
These metrics can easily be graphed using prometheus's `histogram_quantile(...)` method to pick out a particular quantile to graph or examine. I chose buckets that were somewhat of an estimate of expected range of times for ABCI operations. They start at .0001 seconds and range to 25 seconds. The hope is that this range captures enough possible times to be useful for us and operators.
* lint++
* docs: add abci timing metrics to the metrics docs (#7311)
* cherry-pick fixup 3 years ago |
|
- package consensus
-
- import (
- "context"
-
- abciclient "github.com/tendermint/tendermint/abci/client"
- abci "github.com/tendermint/tendermint/abci/types"
- "github.com/tendermint/tendermint/internal/libs/clist"
- "github.com/tendermint/tendermint/internal/mempool"
- "github.com/tendermint/tendermint/internal/proxy"
- tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
- "github.com/tendermint/tendermint/types"
- )
-
- //-----------------------------------------------------------------------------
-
- type emptyMempool struct{}
-
- var _ mempool.Mempool = emptyMempool{}
-
- func (emptyMempool) Lock() {}
- func (emptyMempool) Unlock() {}
- func (emptyMempool) Size() int { return 0 }
- func (emptyMempool) CheckTx(_ context.Context, _ types.Tx, _ func(*abci.Response), _ mempool.TxInfo) error {
- return nil
- }
- func (emptyMempool) RemoveTxByKey(txKey types.TxKey) error { return nil }
- func (emptyMempool) ReapMaxBytesMaxGas(_, _ int64) types.Txs { return types.Txs{} }
- func (emptyMempool) ReapMaxTxs(n int) types.Txs { return types.Txs{} }
- func (emptyMempool) Update(
- _ int64,
- _ types.Txs,
- _ []*abci.ResponseDeliverTx,
- _ mempool.PreCheckFunc,
- _ mempool.PostCheckFunc,
- ) error {
- return nil
- }
- func (emptyMempool) Flush() {}
- func (emptyMempool) FlushAppConn() error { return nil }
- func (emptyMempool) TxsAvailable() <-chan struct{} { return make(chan struct{}) }
- func (emptyMempool) EnableTxsAvailable() {}
- func (emptyMempool) SizeBytes() int64 { return 0 }
-
- func (emptyMempool) TxsFront() *clist.CElement { return nil }
- func (emptyMempool) TxsWaitChan() <-chan struct{} { return nil }
-
- func (emptyMempool) InitWAL() error { return nil }
- func (emptyMempool) CloseWAL() {}
-
- //-----------------------------------------------------------------------------
- // mockProxyApp uses ABCIResponses to give the right results.
- //
- // Useful because we don't want to call Commit() twice for the same block on
- // the real app.
-
- func newMockProxyApp(appHash []byte, abciResponses *tmstate.ABCIResponses) proxy.AppConnConsensus {
- clientCreator := abciclient.NewLocalCreator(&mockProxyApp{
- appHash: appHash,
- abciResponses: abciResponses,
- })
- cli, _ := clientCreator()
- err := cli.Start()
- if err != nil {
- panic(err)
- }
- return proxy.NewAppConnConsensus(cli, proxy.NopMetrics())
- }
-
- type mockProxyApp struct {
- abci.BaseApplication
-
- appHash []byte
- txCount int
- abciResponses *tmstate.ABCIResponses
- }
-
- func (mock *mockProxyApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {
- r := mock.abciResponses.DeliverTxs[mock.txCount]
- mock.txCount++
- if r == nil {
- return abci.ResponseDeliverTx{}
- }
- return *r
- }
-
- func (mock *mockProxyApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock {
- mock.txCount = 0
- return *mock.abciResponses.EndBlock
- }
-
- func (mock *mockProxyApp) Commit() abci.ResponseCommit {
- return abci.ResponseCommit{Data: mock.appHash}
- }
|