mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-05 04:55:18 +00:00
Merge branch main into feature/abci++ppp
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/go-kit/kit/metrics"
|
||||
abcicli "github.com/tendermint/tendermint/abci/client"
|
||||
"github.com/tendermint/tendermint/abci/types"
|
||||
)
|
||||
|
||||
//go:generate mockery --case underscore --name AppConnConsensus|AppConnMempool|AppConnQuery|AppConnSnapshot
|
||||
//go:generate ../scripts/mockery_generate.sh AppConnConsensus|AppConnMempool|AppConnQuery|AppConnSnapshot
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
// Enforce which abci msgs can be sent on a connection at the type level
|
||||
@@ -57,13 +60,15 @@ type AppConnSnapshot interface {
|
||||
// Implements AppConnConsensus (subset of abcicli.Client)
|
||||
|
||||
type appConnConsensus struct {
|
||||
metrics *Metrics
|
||||
appConn abcicli.Client
|
||||
}
|
||||
|
||||
var _ AppConnConsensus = (*appConnConsensus)(nil)
|
||||
|
||||
func NewAppConnConsensus(appConn abcicli.Client) AppConnConsensus {
|
||||
func NewAppConnConsensus(appConn abcicli.Client, metrics *Metrics) AppConnConsensus {
|
||||
return &appConnConsensus{
|
||||
metrics: metrics,
|
||||
appConn: appConn,
|
||||
}
|
||||
}
|
||||
@@ -77,31 +82,38 @@ func (app *appConnConsensus) Error() error {
|
||||
}
|
||||
|
||||
func (app *appConnConsensus) InitChainSync(req types.RequestInitChain) (*types.ResponseInitChain, error) {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "init_chain", "type", "sync"))()
|
||||
return app.appConn.InitChainSync(req)
|
||||
}
|
||||
|
||||
func (app *appConnConsensus) PrepareProposalSync(
|
||||
req types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error) {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "prepare_proposal", "type", "sync"))()
|
||||
return app.appConn.PrepareProposalSync(req)
|
||||
}
|
||||
|
||||
func (app *appConnConsensus) ProcessProposalSync(req types.RequestProcessProposal) (*types.ResponseProcessProposal, error) {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "process_proposal", "type", "sync"))()
|
||||
return app.appConn.ProcessProposalSync(req)
|
||||
}
|
||||
|
||||
func (app *appConnConsensus) BeginBlockSync(req types.RequestBeginBlock) (*types.ResponseBeginBlock, error) {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "begin_block", "type", "sync"))()
|
||||
return app.appConn.BeginBlockSync(req)
|
||||
}
|
||||
|
||||
func (app *appConnConsensus) DeliverTxAsync(req types.RequestDeliverTx) *abcicli.ReqRes {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "deliver_tx", "type", "async"))()
|
||||
return app.appConn.DeliverTxAsync(req)
|
||||
}
|
||||
|
||||
func (app *appConnConsensus) EndBlockSync(req types.RequestEndBlock) (*types.ResponseEndBlock, error) {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "end_block", "type", "sync"))()
|
||||
return app.appConn.EndBlockSync(req)
|
||||
}
|
||||
|
||||
func (app *appConnConsensus) CommitSync() (*types.ResponseCommit, error) {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "commit", "type", "sync"))()
|
||||
return app.appConn.CommitSync()
|
||||
}
|
||||
|
||||
@@ -109,11 +121,13 @@ func (app *appConnConsensus) CommitSync() (*types.ResponseCommit, error) {
|
||||
// Implements AppConnMempool (subset of abcicli.Client)
|
||||
|
||||
type appConnMempool struct {
|
||||
metrics *Metrics
|
||||
appConn abcicli.Client
|
||||
}
|
||||
|
||||
func NewAppConnMempool(appConn abcicli.Client) AppConnMempool {
|
||||
func NewAppConnMempool(appConn abcicli.Client, metrics *Metrics) AppConnMempool {
|
||||
return &appConnMempool{
|
||||
metrics: metrics,
|
||||
appConn: appConn,
|
||||
}
|
||||
}
|
||||
@@ -127,18 +141,22 @@ func (app *appConnMempool) Error() error {
|
||||
}
|
||||
|
||||
func (app *appConnMempool) FlushAsync() *abcicli.ReqRes {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "flush", "type", "async"))()
|
||||
return app.appConn.FlushAsync()
|
||||
}
|
||||
|
||||
func (app *appConnMempool) FlushSync() error {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "flush", "type", "sync"))()
|
||||
return app.appConn.FlushSync()
|
||||
}
|
||||
|
||||
func (app *appConnMempool) CheckTxAsync(req types.RequestCheckTx) *abcicli.ReqRes {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "check_tx", "type", "async"))()
|
||||
return app.appConn.CheckTxAsync(req)
|
||||
}
|
||||
|
||||
func (app *appConnMempool) CheckTxSync(req types.RequestCheckTx) (*types.ResponseCheckTx, error) {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "check_tx", "type", "sync"))()
|
||||
return app.appConn.CheckTxSync(req)
|
||||
}
|
||||
|
||||
@@ -146,11 +164,13 @@ func (app *appConnMempool) CheckTxSync(req types.RequestCheckTx) (*types.Respons
|
||||
// Implements AppConnQuery (subset of abcicli.Client)
|
||||
|
||||
type appConnQuery struct {
|
||||
metrics *Metrics
|
||||
appConn abcicli.Client
|
||||
}
|
||||
|
||||
func NewAppConnQuery(appConn abcicli.Client) AppConnQuery {
|
||||
func NewAppConnQuery(appConn abcicli.Client, metrics *Metrics) AppConnQuery {
|
||||
return &appConnQuery{
|
||||
metrics: metrics,
|
||||
appConn: appConn,
|
||||
}
|
||||
}
|
||||
@@ -160,14 +180,17 @@ func (app *appConnQuery) Error() error {
|
||||
}
|
||||
|
||||
func (app *appConnQuery) EchoSync(msg string) (*types.ResponseEcho, error) {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "echo", "type", "sync"))()
|
||||
return app.appConn.EchoSync(msg)
|
||||
}
|
||||
|
||||
func (app *appConnQuery) InfoSync(req types.RequestInfo) (*types.ResponseInfo, error) {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "info", "type", "sync"))()
|
||||
return app.appConn.InfoSync(req)
|
||||
}
|
||||
|
||||
func (app *appConnQuery) QuerySync(reqQuery types.RequestQuery) (*types.ResponseQuery, error) {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "query", "type", "sync"))()
|
||||
return app.appConn.QuerySync(reqQuery)
|
||||
}
|
||||
|
||||
@@ -175,11 +198,13 @@ func (app *appConnQuery) QuerySync(reqQuery types.RequestQuery) (*types.Response
|
||||
// Implements AppConnSnapshot (subset of abcicli.Client)
|
||||
|
||||
type appConnSnapshot struct {
|
||||
metrics *Metrics
|
||||
appConn abcicli.Client
|
||||
}
|
||||
|
||||
func NewAppConnSnapshot(appConn abcicli.Client) AppConnSnapshot {
|
||||
func NewAppConnSnapshot(appConn abcicli.Client, metrics *Metrics) AppConnSnapshot {
|
||||
return &appConnSnapshot{
|
||||
metrics: metrics,
|
||||
appConn: appConn,
|
||||
}
|
||||
}
|
||||
@@ -189,19 +214,32 @@ func (app *appConnSnapshot) Error() error {
|
||||
}
|
||||
|
||||
func (app *appConnSnapshot) ListSnapshotsSync(req types.RequestListSnapshots) (*types.ResponseListSnapshots, error) {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "list_snapshots", "type", "sync"))()
|
||||
return app.appConn.ListSnapshotsSync(req)
|
||||
}
|
||||
|
||||
func (app *appConnSnapshot) OfferSnapshotSync(req types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "offer_snapshot", "type", "sync"))()
|
||||
return app.appConn.OfferSnapshotSync(req)
|
||||
}
|
||||
|
||||
func (app *appConnSnapshot) LoadSnapshotChunkSync(
|
||||
req types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "load_snapshot_chunk", "type", "sync"))()
|
||||
return app.appConn.LoadSnapshotChunkSync(req)
|
||||
}
|
||||
|
||||
func (app *appConnSnapshot) ApplySnapshotChunkSync(
|
||||
req types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
|
||||
defer addTimeSample(app.metrics.MethodTimingSeconds.With("method", "apply_snapshot_chunk", "type", "sync"))()
|
||||
return app.appConn.ApplySnapshotChunkSync(req)
|
||||
}
|
||||
|
||||
// addTimeSample returns a function that, when called, adds an observation to m.
|
||||
// The observation added to m is the number of seconds ellapsed since addTimeSample
|
||||
// was initially called. addTimeSample is meant to be called in a defer to calculate
|
||||
// the amount of time a function takes to complete.
|
||||
func addTimeSample(m metrics.Histogram) func() {
|
||||
start := time.Now()
|
||||
return func() { m.Observe(time.Since(start).Seconds()) }
|
||||
}
|
||||
|
||||
@@ -4,14 +4,13 @@ import (
|
||||
"fmt"
|
||||
|
||||
abcicli "github.com/tendermint/tendermint/abci/client"
|
||||
"github.com/tendermint/tendermint/abci/example/counter"
|
||||
"github.com/tendermint/tendermint/abci/example/kvstore"
|
||||
"github.com/tendermint/tendermint/abci/types"
|
||||
tmsync "github.com/tendermint/tendermint/libs/sync"
|
||||
e2e "github.com/tendermint/tendermint/test/e2e/app"
|
||||
)
|
||||
|
||||
//go:generate mockery --case underscore --name ClientCreator
|
||||
//go:generate ../scripts/mockery_generate.sh ClientCreator
|
||||
|
||||
// ClientCreator creates new ABCI clients.
|
||||
type ClientCreator interface {
|
||||
@@ -70,14 +69,10 @@ func (r *remoteClientCreator) NewABCIClient() (abcicli.Client, error) {
|
||||
}
|
||||
|
||||
// DefaultClientCreator returns a default ClientCreator, which will create a
|
||||
// local client if addr is one of: 'counter', 'counter_serial', 'kvstore',
|
||||
// local client if addr is one of: 'kvstore',
|
||||
// 'persistent_kvstore' or 'noop', otherwise - a remote client.
|
||||
func DefaultClientCreator(addr, transport, dbDir string) ClientCreator {
|
||||
switch addr {
|
||||
case "counter":
|
||||
return NewLocalClientCreator(counter.NewApplication(false))
|
||||
case "counter_serial":
|
||||
return NewLocalClientCreator(counter.NewApplication(true))
|
||||
case "kvstore":
|
||||
return NewLocalClientCreator(kvstore.NewApplication())
|
||||
case "persistent_kvstore":
|
||||
|
||||
32
proxy/metrics.gen.go
Normal file
32
proxy/metrics.gen.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// Code generated by metricsgen. DO NOT EDIT.
|
||||
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/metrics/discard"
|
||||
prometheus "github.com/go-kit/kit/metrics/prometheus"
|
||||
stdprometheus "github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
|
||||
labels := []string{}
|
||||
for i := 0; i < len(labelsAndValues); i += 2 {
|
||||
labels = append(labels, labelsAndValues[i])
|
||||
}
|
||||
return &Metrics{
|
||||
MethodTimingSeconds: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: MetricsSubsystem,
|
||||
Name: "method_timing_seconds",
|
||||
Help: "Timing for each ABCI method.",
|
||||
|
||||
Buckets: []float64{.0001, .0004, .002, .009, .02, .1, .65, 2, 6, 25},
|
||||
}, append(labels, "method", "type")).With(labelsAndValues...),
|
||||
}
|
||||
}
|
||||
|
||||
func NopMetrics() *Metrics {
|
||||
return &Metrics{
|
||||
MethodTimingSeconds: discard.NewHistogram(),
|
||||
}
|
||||
}
|
||||
19
proxy/metrics.go
Normal file
19
proxy/metrics.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"github.com/go-kit/kit/metrics"
|
||||
)
|
||||
|
||||
const (
|
||||
// MetricsSubsystem is a subsystem shared by all metrics exposed by this
|
||||
// package.
|
||||
MetricsSubsystem = "abci_connection"
|
||||
)
|
||||
|
||||
//go:generate go run ../scripts/metricsgen -struct=Metrics
|
||||
|
||||
// Metrics contains the prometheus metrics exposed by the proxy package.
|
||||
type Metrics struct {
|
||||
// Timing for each ABCI method.
|
||||
MethodTimingSeconds metrics.Histogram `metrics_bucketsizes:".0001,.0004,.002,.009,.02,.1,.65,2,6,25" metrics_labels:"method, type"`
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.14.0. DO NOT EDIT.
|
||||
// Code generated by mockery. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.14.0. DO NOT EDIT.
|
||||
// Code generated by mockery. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.14.0. DO NOT EDIT.
|
||||
// Code generated by mockery. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.14.0. DO NOT EDIT.
|
||||
// Code generated by mockery. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Code generated by mockery v2.14.0. DO NOT EDIT.
|
||||
// Code generated by mockery. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ type AppConns interface {
|
||||
}
|
||||
|
||||
// NewAppConns calls NewMultiAppConn.
|
||||
func NewAppConns(clientCreator ClientCreator) AppConns {
|
||||
return NewMultiAppConn(clientCreator)
|
||||
func NewAppConns(clientCreator ClientCreator, metrics *Metrics) AppConns {
|
||||
return NewMultiAppConn(clientCreator, metrics)
|
||||
}
|
||||
|
||||
// multiAppConn implements AppConns.
|
||||
@@ -44,6 +44,7 @@ func NewAppConns(clientCreator ClientCreator) AppConns {
|
||||
type multiAppConn struct {
|
||||
service.BaseService
|
||||
|
||||
metrics *Metrics
|
||||
consensusConn AppConnConsensus
|
||||
mempoolConn AppConnMempool
|
||||
queryConn AppConnQuery
|
||||
@@ -58,8 +59,9 @@ type multiAppConn struct {
|
||||
}
|
||||
|
||||
// NewMultiAppConn makes all necessary abci connections to the application.
|
||||
func NewMultiAppConn(clientCreator ClientCreator) AppConns {
|
||||
func NewMultiAppConn(clientCreator ClientCreator, metrics *Metrics) AppConns {
|
||||
multiAppConn := &multiAppConn{
|
||||
metrics: metrics,
|
||||
clientCreator: clientCreator,
|
||||
}
|
||||
multiAppConn.BaseService = *service.NewBaseService(nil, "multiAppConn", multiAppConn)
|
||||
@@ -88,7 +90,7 @@ func (app *multiAppConn) OnStart() error {
|
||||
return err
|
||||
}
|
||||
app.queryConnClient = c
|
||||
app.queryConn = NewAppConnQuery(c)
|
||||
app.queryConn = NewAppConnQuery(c, app.metrics)
|
||||
|
||||
c, err = app.abciClientFor(connSnapshot)
|
||||
if err != nil {
|
||||
@@ -96,7 +98,7 @@ func (app *multiAppConn) OnStart() error {
|
||||
return err
|
||||
}
|
||||
app.snapshotConnClient = c
|
||||
app.snapshotConn = NewAppConnSnapshot(c)
|
||||
app.snapshotConn = NewAppConnSnapshot(c, app.metrics)
|
||||
|
||||
c, err = app.abciClientFor(connMempool)
|
||||
if err != nil {
|
||||
@@ -104,7 +106,7 @@ func (app *multiAppConn) OnStart() error {
|
||||
return err
|
||||
}
|
||||
app.mempoolConnClient = c
|
||||
app.mempoolConn = NewAppConnMempool(c)
|
||||
app.mempoolConn = NewAppConnMempool(c, app.metrics)
|
||||
|
||||
c, err = app.abciClientFor(connConsensus)
|
||||
if err != nil {
|
||||
@@ -112,7 +114,7 @@ func (app *multiAppConn) OnStart() error {
|
||||
return err
|
||||
}
|
||||
app.consensusConnClient = c
|
||||
app.consensusConn = NewAppConnConsensus(c)
|
||||
app.consensusConn = NewAppConnConsensus(c, app.metrics)
|
||||
|
||||
// Kill Tendermint if the ABCI application crashes.
|
||||
go app.killTMOnClientError()
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestAppConns_Start_Stop(t *testing.T) {
|
||||
|
||||
clientCreatorMock.On("NewABCIClient").Return(clientMock, nil).Times(4)
|
||||
|
||||
appConns := NewAppConns(clientCreatorMock)
|
||||
appConns := NewAppConns(clientCreatorMock, NopMetrics())
|
||||
|
||||
err := appConns.Start()
|
||||
require.NoError(t, err)
|
||||
@@ -68,7 +68,7 @@ func TestAppConns_Failure(t *testing.T) {
|
||||
|
||||
clientCreatorMock.On("NewABCIClient").Return(clientMock, nil)
|
||||
|
||||
appConns := NewAppConns(clientCreatorMock)
|
||||
appConns := NewAppConns(clientCreatorMock, NopMetrics())
|
||||
|
||||
err := appConns.Start()
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user