Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add per module latency metric for Begin, Mid, EndBlock #234

Merged
merged 1 commit into from
May 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import (
"encoding/json"
"fmt"
"sort"
"time"

"github.com/cosmos/cosmos-sdk/telemetry"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -497,10 +499,13 @@ func (m Manager) RunMigrations(ctx sdk.Context, cfg Configurator, fromVM Version
func (m *Manager) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
ctx = ctx.WithEventManager(sdk.NewEventManager())

defer telemetry.MeasureSince(time.Now(), "module", "total_begin_block")
for _, moduleName := range m.OrderBeginBlockers {
module, ok := m.Modules[moduleName].(BeginBlockAppModule)
if ok {
moduleStartTime := time.Now()
module.BeginBlock(ctx, req)
telemetry.ModuleMeasureSince(moduleName, moduleStartTime, "module", "begin_block")
}
}

Expand All @@ -515,12 +520,15 @@ func (m *Manager) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) abci.R
func (m *Manager) MidBlock(ctx sdk.Context, height int64) []abci.Event {
ctx = ctx.WithEventManager(sdk.NewEventManager())

defer telemetry.MeasureSince(time.Now(), "module", "total_mid_block")
for _, moduleName := range m.OrderMidBlockers {
module, ok := m.Modules[moduleName].(MidBlockAppModule)
if !ok {
continue
}
moduleStartTime := time.Now()
module.MidBlock(ctx, height)
telemetry.ModuleMeasureSince(moduleName, moduleStartTime, "module", "mid_block")
}

return ctx.EventManager().ABCIEvents()
Expand All @@ -532,14 +540,15 @@ func (m *Manager) MidBlock(ctx sdk.Context, height int64) []abci.Event {
func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
ctx = ctx.WithEventManager(sdk.NewEventManager())
validatorUpdates := []abci.ValidatorUpdate{}

defer telemetry.MeasureSince(time.Now(), "module", "total_end_block")
for _, moduleName := range m.OrderEndBlockers {
module, ok := m.Modules[moduleName].(EndBlockAppModule)
if !ok {
continue
}
moduleStartTime := time.Now()
moduleValUpdates := module.EndBlock(ctx, req)

telemetry.ModuleMeasureSince(moduleName, moduleStartTime, "module", "end_block")
// use these validator updates if provided, the module manager assumes
// only one module will update the validator set
if len(moduleValUpdates) > 0 {
Expand All @@ -549,6 +558,7 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo

validatorUpdates = moduleValUpdates
}

}

return abci.ResponseEndBlock{
Expand Down