@ -2,7 +2,9 @@ package proxy
import (
import (
"context"
"context"
"time"
"github.com/go-kit/kit/metrics"
abciclient "github.com/tendermint/tendermint/abci/client"
abciclient "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/abci/types"
)
)
@ -56,11 +58,13 @@ type AppConnSnapshot interface {
// Implements AppConnConsensus (subset of abciclient.Client)
// Implements AppConnConsensus (subset of abciclient.Client)
type appConnConsensus struct {
type appConnConsensus struct {
metrics * Metrics
appConn abciclient . Client
appConn abciclient . Client
}
}
func NewAppConnConsensus ( appConn abciclient . Client ) AppConnConsensus {
func NewAppConnConsensus ( appConn abciclient . Client , metrics * Metrics ) AppConnConsensus {
return & appConnConsensus {
return & appConnConsensus {
metrics : metrics ,
appConn : appConn ,
appConn : appConn ,
}
}
}
}
@ -77,6 +81,7 @@ func (app *appConnConsensus) InitChainSync(
ctx context . Context ,
ctx context . Context ,
req types . RequestInitChain ,
req types . RequestInitChain ,
) ( * types . ResponseInitChain , error ) {
) ( * types . ResponseInitChain , error ) {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "init_chain" , "type" , "sync" ) ) ( )
return app . appConn . InitChainSync ( ctx , req )
return app . appConn . InitChainSync ( ctx , req )
}
}
@ -84,6 +89,7 @@ func (app *appConnConsensus) BeginBlockSync(
ctx context . Context ,
ctx context . Context ,
req types . RequestBeginBlock ,
req types . RequestBeginBlock ,
) ( * types . ResponseBeginBlock , error ) {
) ( * types . ResponseBeginBlock , error ) {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "begin_block" , "type" , "sync" ) ) ( )
return app . appConn . BeginBlockSync ( ctx , req )
return app . appConn . BeginBlockSync ( ctx , req )
}
}
@ -91,6 +97,7 @@ func (app *appConnConsensus) DeliverTxAsync(
ctx context . Context ,
ctx context . Context ,
req types . RequestDeliverTx ,
req types . RequestDeliverTx ,
) ( * abciclient . ReqRes , error ) {
) ( * abciclient . ReqRes , error ) {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "deliver_tx" , "type" , "async" ) ) ( )
return app . appConn . DeliverTxAsync ( ctx , req )
return app . appConn . DeliverTxAsync ( ctx , req )
}
}
@ -98,10 +105,12 @@ func (app *appConnConsensus) EndBlockSync(
ctx context . Context ,
ctx context . Context ,
req types . RequestEndBlock ,
req types . RequestEndBlock ,
) ( * types . ResponseEndBlock , error ) {
) ( * types . ResponseEndBlock , error ) {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "deliver_tx" , "type" , "sync" ) ) ( )
return app . appConn . EndBlockSync ( ctx , req )
return app . appConn . EndBlockSync ( ctx , req )
}
}
func ( app * appConnConsensus ) CommitSync ( ctx context . Context ) ( * types . ResponseCommit , error ) {
func ( app * appConnConsensus ) CommitSync ( ctx context . Context ) ( * types . ResponseCommit , error ) {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "commit" , "type" , "sync" ) ) ( )
return app . appConn . CommitSync ( ctx )
return app . appConn . CommitSync ( ctx )
}
}
@ -109,11 +118,13 @@ func (app *appConnConsensus) CommitSync(ctx context.Context) (*types.ResponseCom
// Implements AppConnMempool (subset of abciclient.Client)
// Implements AppConnMempool (subset of abciclient.Client)
type appConnMempool struct {
type appConnMempool struct {
metrics * Metrics
appConn abciclient . Client
appConn abciclient . Client
}
}
func NewAppConnMempool ( appConn abciclient . Client ) AppConnMempool {
func NewAppConnMempool ( appConn abciclient . Client , metrics * Metrics ) AppConnMempool {
return & appConnMempool {
return & appConnMempool {
metrics : metrics ,
appConn : appConn ,
appConn : appConn ,
}
}
}
}
@ -127,18 +138,22 @@ func (app *appConnMempool) Error() error {
}
}
func ( app * appConnMempool ) FlushAsync ( ctx context . Context ) ( * abciclient . ReqRes , error ) {
func ( app * appConnMempool ) FlushAsync ( ctx context . Context ) ( * abciclient . ReqRes , error ) {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "flush" , "type" , "async" ) ) ( )
return app . appConn . FlushAsync ( ctx )
return app . appConn . FlushAsync ( ctx )
}
}
func ( app * appConnMempool ) FlushSync ( ctx context . Context ) error {
func ( app * appConnMempool ) FlushSync ( ctx context . Context ) error {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "flush" , "type" , "sync" ) ) ( )
return app . appConn . FlushSync ( ctx )
return app . appConn . FlushSync ( ctx )
}
}
func ( app * appConnMempool ) CheckTxAsync ( ctx context . Context , req types . RequestCheckTx ) ( * abciclient . ReqRes , error ) {
func ( app * appConnMempool ) CheckTxAsync ( ctx context . Context , req types . RequestCheckTx ) ( * abciclient . ReqRes , error ) {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "check_tx" , "type" , "async" ) ) ( )
return app . appConn . CheckTxAsync ( ctx , req )
return app . appConn . CheckTxAsync ( ctx , req )
}
}
func ( app * appConnMempool ) CheckTxSync ( ctx context . Context , req types . RequestCheckTx ) ( * types . ResponseCheckTx , error ) {
func ( app * appConnMempool ) CheckTxSync ( ctx context . Context , req types . RequestCheckTx ) ( * types . ResponseCheckTx , error ) {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "check_tx" , "type" , "sync" ) ) ( )
return app . appConn . CheckTxSync ( ctx , req )
return app . appConn . CheckTxSync ( ctx , req )
}
}
@ -146,11 +161,13 @@ func (app *appConnMempool) CheckTxSync(ctx context.Context, req types.RequestChe
// Implements AppConnQuery (subset of abciclient.Client)
// Implements AppConnQuery (subset of abciclient.Client)
type appConnQuery struct {
type appConnQuery struct {
metrics * Metrics
appConn abciclient . Client
appConn abciclient . Client
}
}
func NewAppConnQuery ( appConn abciclient . Client ) AppConnQuery {
func NewAppConnQuery ( appConn abciclient . Client , metrics * Metrics ) AppConnQuery {
return & appConnQuery {
return & appConnQuery {
metrics : metrics ,
appConn : appConn ,
appConn : appConn ,
}
}
}
}
@ -160,14 +177,17 @@ func (app *appConnQuery) Error() error {
}
}
func ( app * appConnQuery ) EchoSync ( ctx context . Context , msg string ) ( * types . ResponseEcho , error ) {
func ( app * appConnQuery ) EchoSync ( ctx context . Context , msg string ) ( * types . ResponseEcho , error ) {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "echo" , "type" , "sync" ) ) ( )
return app . appConn . EchoSync ( ctx , msg )
return app . appConn . EchoSync ( ctx , msg )
}
}
func ( app * appConnQuery ) InfoSync ( ctx context . Context , req types . RequestInfo ) ( * types . ResponseInfo , error ) {
func ( app * appConnQuery ) InfoSync ( ctx context . Context , req types . RequestInfo ) ( * types . ResponseInfo , error ) {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "info" , "type" , "sync" ) ) ( )
return app . appConn . InfoSync ( ctx , req )
return app . appConn . InfoSync ( ctx , req )
}
}
func ( app * appConnQuery ) QuerySync ( ctx context . Context , reqQuery types . RequestQuery ) ( * types . ResponseQuery , error ) {
func ( app * appConnQuery ) QuerySync ( ctx context . Context , reqQuery types . RequestQuery ) ( * types . ResponseQuery , error ) {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "query" , "type" , "sync" ) ) ( )
return app . appConn . QuerySync ( ctx , reqQuery )
return app . appConn . QuerySync ( ctx , reqQuery )
}
}
@ -175,11 +195,13 @@ func (app *appConnQuery) QuerySync(ctx context.Context, reqQuery types.RequestQu
// Implements AppConnSnapshot (subset of abciclient.Client)
// Implements AppConnSnapshot (subset of abciclient.Client)
type appConnSnapshot struct {
type appConnSnapshot struct {
metrics * Metrics
appConn abciclient . Client
appConn abciclient . Client
}
}
func NewAppConnSnapshot ( appConn abciclient . Client ) AppConnSnapshot {
func NewAppConnSnapshot ( appConn abciclient . Client , metrics * Metrics ) AppConnSnapshot {
return & appConnSnapshot {
return & appConnSnapshot {
metrics : metrics ,
appConn : appConn ,
appConn : appConn ,
}
}
}
}
@ -192,6 +214,7 @@ func (app *appConnSnapshot) ListSnapshotsSync(
ctx context . Context ,
ctx context . Context ,
req types . RequestListSnapshots ,
req types . RequestListSnapshots ,
) ( * types . ResponseListSnapshots , error ) {
) ( * types . ResponseListSnapshots , error ) {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "list_snapshots" , "type" , "sync" ) ) ( )
return app . appConn . ListSnapshotsSync ( ctx , req )
return app . appConn . ListSnapshotsSync ( ctx , req )
}
}
@ -199,17 +222,29 @@ func (app *appConnSnapshot) OfferSnapshotSync(
ctx context . Context ,
ctx context . Context ,
req types . RequestOfferSnapshot ,
req types . RequestOfferSnapshot ,
) ( * types . ResponseOfferSnapshot , error ) {
) ( * types . ResponseOfferSnapshot , error ) {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "offer_snapshot" , "type" , "sync" ) ) ( )
return app . appConn . OfferSnapshotSync ( ctx , req )
return app . appConn . OfferSnapshotSync ( ctx , req )
}
}
func ( app * appConnSnapshot ) LoadSnapshotChunkSync (
func ( app * appConnSnapshot ) LoadSnapshotChunkSync (
ctx context . Context ,
ctx context . Context ,
req types . RequestLoadSnapshotChunk ) ( * types . ResponseLoadSnapshotChunk , error ) {
req types . RequestLoadSnapshotChunk ) ( * types . ResponseLoadSnapshotChunk , error ) {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "load_snapshot_chunk" , "type" , "sync" ) ) ( )
return app . appConn . LoadSnapshotChunkSync ( ctx , req )
return app . appConn . LoadSnapshotChunkSync ( ctx , req )
}
}
func ( app * appConnSnapshot ) ApplySnapshotChunkSync (
func ( app * appConnSnapshot ) ApplySnapshotChunkSync (
ctx context . Context ,
ctx context . Context ,
req types . RequestApplySnapshotChunk ) ( * types . ResponseApplySnapshotChunk , error ) {
req types . RequestApplySnapshotChunk ) ( * types . ResponseApplySnapshotChunk , error ) {
defer addTimeSample ( app . metrics . MethodTiming . With ( "method" , "apply_snapshot_chunk" , "type" , "sync" ) ) ( )
return app . appConn . ApplySnapshotChunkSync ( ctx , req )
return app . appConn . ApplySnapshotChunkSync ( ctx , 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 ( ) ) }
}