Skip to content

Commit

Permalink
feat: metrics around block execution + trace flight recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
kakysha committed Jan 27, 2025
1 parent 481d264 commit 738074d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
19 changes: 19 additions & 0 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"time"

"github.com/InjectiveLabs/metrics"
abcitypes "github.com/cometbft/cometbft/abci/types"
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
Expand Down Expand Up @@ -529,6 +530,15 @@ func (app *BaseApp) ProcessProposal(req *abci.ProcessProposalRequest) (resp *abc
app.setState(execModeFinalize, header)
}

// metrics and trace
heightStr := strconv.Itoa(int(req.Height))
metricsCtx, doneFn := metrics.ReportFuncCallAndTimingSdkCtx(app.processProposalState.Context(), metrics.Tags{"svc": "app", "height": heightStr})
defer doneFn()
if app.traceFlightRecorder != nil {
defer app.traceFlightRecorder.StartRegion("process-proposal", heightStr)() //nolint:errcheck // debug only
}
app.processProposalState.SetContext(metricsCtx)

app.processProposalState.SetContext(app.getContextForProposal(app.processProposalState.Context(), req.Height).
WithVoteInfos(req.ProposedLastCommit.Votes). // this is a set of votes that are not finalized yet, wait for commit
WithBlockHeight(req.Height).
Expand Down Expand Up @@ -779,6 +789,15 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz
app.setState(execModeFinalize, header)
}

// metrics and trace
heightStr := strconv.Itoa(int(req.Height))
metricsCtx, doneFn := metrics.ReportFuncCallAndTimingSdkCtx(app.finalizeBlockState.Context(), metrics.Tags{"svc": "app", "height": heightStr})
defer doneFn()
if app.traceFlightRecorder != nil {
defer app.traceFlightRecorder.StartRegion("finalize-block", heightStr)() //nolint:errcheck // debug only
}
app.finalizeBlockState.SetContext(metricsCtx)

// Context is now updated with Header information.
app.finalizeBlockState.SetContext(app.finalizeBlockState.Context().
WithBlockHeader(header).
Expand Down
3 changes: 3 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"sync"

"github.com/InjectiveLabs/metrics"
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
"github.com/cometbft/cometbft/crypto/tmhash"
Expand Down Expand Up @@ -192,6 +193,8 @@ type BaseApp struct {
// StreamEvents
EnableStreamer bool
StreamEvents chan StreamEvents

traceFlightRecorder *metrics.TraceRecorder
}

// NewBaseApp returns a reference to an initialized BaseApp. It accepts a
Expand Down
14 changes: 12 additions & 2 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"io"
"math"

"github.com/InjectiveLabs/metrics"

"cosmossdk.io/core/server"
corestore "cosmossdk.io/core/store"
"cosmossdk.io/store/metrics"
storemetrics "cosmossdk.io/store/metrics"
pruningtypes "cosmossdk.io/store/pruning/types"
"cosmossdk.io/store/snapshots"
snapshottypes "cosmossdk.io/store/snapshots/types"
Expand Down Expand Up @@ -385,7 +387,7 @@ func (app *BaseApp) SetVerifyVoteExtensionHandler(handler sdk.VerifyVoteExtensio
}

// SetStoreMetrics sets the prepare proposal function for the BaseApp.
func (app *BaseApp) SetStoreMetrics(gatherer metrics.StoreMetrics) {
func (app *BaseApp) SetStoreMetrics(gatherer storemetrics.StoreMetrics) {
if app.sealed {
panic("SetStoreMetrics() on sealed BaseApp")
}
Expand All @@ -407,3 +409,11 @@ func (app *BaseApp) SetMsgServiceRouter(msgServiceRouter *MsgServiceRouter) {
func (app *BaseApp) SetGRPCQueryRouter(grpcQueryRouter *GRPCQueryRouter) {
app.grpcQueryRouter = grpcQueryRouter
}

func (app *BaseApp) SetTraceFlightRecorder(tr *metrics.TraceRecorder) {
app.traceFlightRecorder = tr
}

func SetTraceFlightRecorder(tr *metrics.TraceRecorder) func(*BaseApp) {
return func(app *BaseApp) { app.traceFlightRecorder = tr }
}

0 comments on commit 738074d

Please sign in to comment.