diff --git a/baseapp/abci.go b/baseapp/abci.go index 4c58a70e437..e5784479e7b 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -104,7 +104,7 @@ func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery { // BeginBlock implements the ABCI application interface. func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) { - defer telemetry.MeasureSince(time.Now().UTC(), "abci", "begin_block") + defer telemetry.MeasureSince(time.Now(), "abci", "begin_block") if app.cms.TracingEnabled() { app.cms.SetTracingContext(sdk.TraceContext( @@ -149,7 +149,7 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg // EndBlock implements the ABCI interface. func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBlock) { - defer telemetry.MeasureSince(time.Now().UTC(), "abci", "end_block") + defer telemetry.MeasureSince(time.Now(), "abci", "end_block") if app.deliverState.ms.TracingEnabled() { app.deliverState.ms = app.deliverState.ms.SetTracingContext(nil).(sdk.CacheMultiStore) @@ -169,7 +169,7 @@ func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBloc // will contain releveant error information. Regardless of tx execution outcome, // the ResponseCheckTx will contain relevant gas execution context. func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { - defer telemetry.MeasureSince(time.Now().UTC(), "abci", "check_tx") + defer telemetry.MeasureSince(time.Now(), "abci", "check_tx") tx, err := app.txDecoder(req.Tx) if err != nil { @@ -209,7 +209,7 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { // Regardless of tx execution outcome, the ResponseDeliverTx will contain relevant // gas execution context. func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx { - defer telemetry.MeasureSince(time.Now().UTC(), "abci", "deliver_tx") + defer telemetry.MeasureSince(time.Now(), "abci", "deliver_tx") tx, err := app.txDecoder(req.Tx) if err != nil { @@ -249,7 +249,7 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx // against that height and gracefully halt if it matches the latest committed // height. func (app *BaseApp) Commit() (res abci.ResponseCommit) { - defer telemetry.MeasureSince(time.Now().UTC(), "abci", "commit") + defer telemetry.MeasureSince(time.Now(), "abci", "commit") header := app.deliverState.ctx.BlockHeader() @@ -317,7 +317,7 @@ func (app *BaseApp) halt() { // Query implements the ABCI interface. It delegates to CommitMultiStore if it // implements Queryable. func (app *BaseApp) Query(req abci.RequestQuery) abci.ResponseQuery { - defer telemetry.MeasureSince(time.Now().UTC(), "abci", "query") + defer telemetry.MeasureSince(time.Now(), "abci", "query") // handle gRPC routes first rather than calling splitPath because '/' characters // are used as part of gRPC paths diff --git a/docs/architecture/adr-013-metrics.md b/docs/architecture/adr-013-metrics.md index 29cf30a9917..cf27d89648c 100644 --- a/docs/architecture/adr-013-metrics.md +++ b/docs/architecture/adr-013-metrics.md @@ -139,7 +139,7 @@ additional lifting required by modules to leverage profiling metrics. To do so, ```go func (k BaseKeeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error { - defer metrics.MeasureSince([]string{"MintCoins"}, time.Now().UTC()) + defer metrics.MeasureSince(time.Now(), "MintCoins") // ... } ``` diff --git a/docs/core/telemetry.md b/docs/core/telemetry.md index 951ba86c54f..c218658dbad 100644 --- a/docs/core/telemetry.md +++ b/docs/core/telemetry.md @@ -20,7 +20,7 @@ Example: ```go func EndBlocker(ctx sdk.Context, k keeper.Keeper) { - defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.MetricKeyEndBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) // ... } diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 3262e161645..4b519b7a70b 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -53,7 +53,7 @@ func (store *Store) GetStoreType() types.StoreType { func (store *Store) Get(key []byte) (value []byte) { store.mtx.Lock() defer store.mtx.Unlock() - defer telemetry.MeasureSince(time.Now().UTC(), "store", "cachekv", "get") + defer telemetry.MeasureSince(time.Now(), "store", "cachekv", "get") types.AssertValidKey(key) @@ -72,7 +72,7 @@ func (store *Store) Get(key []byte) (value []byte) { func (store *Store) Set(key []byte, value []byte) { store.mtx.Lock() defer store.mtx.Unlock() - defer telemetry.MeasureSince(time.Now().UTC(), "store", "cachekv", "set") + defer telemetry.MeasureSince(time.Now(), "store", "cachekv", "set") types.AssertValidKey(key) types.AssertValidValue(value) @@ -90,7 +90,7 @@ func (store *Store) Has(key []byte) bool { func (store *Store) Delete(key []byte) { store.mtx.Lock() defer store.mtx.Unlock() - defer telemetry.MeasureSince(time.Now().UTC(), "store", "cachekv", "delete") + defer telemetry.MeasureSince(time.Now(), "store", "cachekv", "delete") types.AssertValidKey(key) store.setCacheValue(key, nil, true, true) @@ -100,7 +100,7 @@ func (store *Store) Delete(key []byte) { func (store *Store) Write() { store.mtx.Lock() defer store.mtx.Unlock() - defer telemetry.MeasureSince(time.Now().UTC(), "store", "cachekv", "write") + defer telemetry.MeasureSince(time.Now(), "store", "cachekv", "write") // We need a copy of all of the keys. // Not the best, but probably not a bottleneck depending. diff --git a/store/gaskv/store.go b/store/gaskv/store.go index 7d014b16196..c53a07af31e 100644 --- a/store/gaskv/store.go +++ b/store/gaskv/store.go @@ -36,7 +36,7 @@ func (gs *Store) GetStoreType() types.StoreType { // Implements KVStore. func (gs *Store) Get(key []byte) (value []byte) { - defer telemetry.MeasureSince(time.Now().UTC(), "store", "gaskv", "get") + defer telemetry.MeasureSince(time.Now(), "store", "gaskv", "get") gs.gasMeter.ConsumeGas(gs.gasConfig.ReadCostFlat, types.GasReadCostFlatDesc) value = gs.parent.Get(key) @@ -49,7 +49,7 @@ func (gs *Store) Get(key []byte) (value []byte) { // Implements KVStore. func (gs *Store) Set(key []byte, value []byte) { - defer telemetry.MeasureSince(time.Now().UTC(), "store", "gaskv", "set") + defer telemetry.MeasureSince(time.Now(), "store", "gaskv", "set") types.AssertValidValue(value) gs.gasMeter.ConsumeGas(gs.gasConfig.WriteCostFlat, types.GasWriteCostFlatDesc) @@ -60,14 +60,14 @@ func (gs *Store) Set(key []byte, value []byte) { // Implements KVStore. func (gs *Store) Has(key []byte) bool { - defer telemetry.MeasureSince(time.Now().UTC(), "store", "gaskv", "has") + defer telemetry.MeasureSince(time.Now(), "store", "gaskv", "has") gs.gasMeter.ConsumeGas(gs.gasConfig.HasCost, types.GasHasDesc) return gs.parent.Has(key) } // Implements KVStore. func (gs *Store) Delete(key []byte) { - defer telemetry.MeasureSince(time.Now().UTC(), "store", "gaskv", "delete") + defer telemetry.MeasureSince(time.Now(), "store", "gaskv", "delete") // charge gas to prevent certain attack vectors even though space is being freed gs.gasMeter.ConsumeGas(gs.gasConfig.DeleteCost, types.GasDeleteDesc) gs.parent.Delete(key) diff --git a/store/iavl/store.go b/store/iavl/store.go index bd6bbd43151..628df8ed75f 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -97,7 +97,7 @@ func (st *Store) GetImmutable(version int64) (*Store, error) { // Commit commits the current store state and returns a CommitID with the new // version and hash. func (st *Store) Commit() types.CommitID { - defer telemetry.MeasureSince(time.Now().UTC(), "store", "iavl", "commit") + defer telemetry.MeasureSince(time.Now(), "store", "iavl", "commit") hash, version, err := st.tree.SaveVersion() if err != nil { @@ -146,27 +146,27 @@ func (st *Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.Ca // Implements types.KVStore. func (st *Store) Set(key, value []byte) { - defer telemetry.MeasureSince(time.Now().UTC(), "store", "iavl", "set") + defer telemetry.MeasureSince(time.Now(), "store", "iavl", "set") types.AssertValidValue(value) st.tree.Set(key, value) } // Implements types.KVStore. func (st *Store) Get(key []byte) []byte { - defer telemetry.MeasureSince(time.Now().UTC(), "store", "iavl", "get") + defer telemetry.MeasureSince(time.Now(), "store", "iavl", "get") _, value := st.tree.Get(key) return value } // Implements types.KVStore. func (st *Store) Has(key []byte) (exists bool) { - defer telemetry.MeasureSince(time.Now().UTC(), "store", "iavl", "has") + defer telemetry.MeasureSince(time.Now(), "store", "iavl", "has") return st.tree.Has(key) } // Implements types.KVStore. func (st *Store) Delete(key []byte) { - defer telemetry.MeasureSince(time.Now().UTC(), "store", "iavl", "delete") + defer telemetry.MeasureSince(time.Now(), "store", "iavl", "delete") st.tree.Remove(key) } @@ -227,7 +227,7 @@ func getHeight(tree Tree, req abci.RequestQuery) int64 { // if you care to have the latest data to see a tx results, you must // explicitly set the height you want to see func (st *Store) Query(req abci.RequestQuery) (res abci.ResponseQuery) { - defer telemetry.MeasureSince(time.Now().UTC(), "store", "iavl", "query") + defer telemetry.MeasureSince(time.Now(), "store", "iavl", "query") if len(req.Data) == 0 { return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrTxDecode, "query cannot be zero length")) diff --git a/telemetry/wrapper.go b/telemetry/wrapper.go index 925ef4dd2d5..56584e296e7 100644 --- a/telemetry/wrapper.go +++ b/telemetry/wrapper.go @@ -23,7 +23,7 @@ func NewLabel(name, value string) metrics.Label { func ModuleMeasureSince(module string, start time.Time, keys ...string) { metrics.MeasureSinceWithLabels( keys, - start, + start.UTC(), append([]metrics.Label{NewLabel(MetricLabelNameModule, module)}, globalLabels...), ) } @@ -66,5 +66,5 @@ func SetGaugeWithLabels(keys []string, val float32, labels []metrics.Label) { // MeasureSince provides a wrapper functionality for emitting a a time measure // metric with global labels (if any). func MeasureSince(start time.Time, keys ...string) { - metrics.MeasureSinceWithLabels(keys, start, globalLabels) + metrics.MeasureSinceWithLabels(keys, start.UTC(), globalLabels) } diff --git a/x/crisis/abci.go b/x/crisis/abci.go index 42eed9513f7..fa1b932b8f6 100644 --- a/x/crisis/abci.go +++ b/x/crisis/abci.go @@ -11,7 +11,7 @@ import ( // check all registered invariants func EndBlocker(ctx sdk.Context, k keeper.Keeper) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyEndBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) if k.InvCheckPeriod() == 0 || ctx.BlockHeight()%int64(k.InvCheckPeriod()) != 0 { // skip running the invariant check diff --git a/x/distribution/abci.go b/x/distribution/abci.go index 7386871675e..7c612c1665f 100644 --- a/x/distribution/abci.go +++ b/x/distribution/abci.go @@ -14,7 +14,7 @@ import ( // BeginBlocker sets the proposer for determining distribution during endblock // and distribute rewards for the previous block func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyBeginBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) // determine the total power signing the block var previousTotalPower, sumPreviousPrecommitPower int64 diff --git a/x/evidence/abci.go b/x/evidence/abci.go index 39c4e81e558..c59ccccd1af 100644 --- a/x/evidence/abci.go +++ b/x/evidence/abci.go @@ -17,7 +17,7 @@ import ( // BeginBlocker iterates through and handles any newly discovered evidence of // misbehavior submitted by Tendermint. Currently, only equivocation is handled. func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyBeginBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) for _, tmEvidence := range req.ByzantineValidators { switch tmEvidence.Type { diff --git a/x/gov/abci.go b/x/gov/abci.go index 2984941e20b..0835f5b0c28 100644 --- a/x/gov/abci.go +++ b/x/gov/abci.go @@ -12,7 +12,7 @@ import ( // EndBlocker called every block, process inflation, update validator set. func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyEndBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) logger := keeper.Logger(ctx) diff --git a/x/mint/abci.go b/x/mint/abci.go index affa0ebd3bf..ca91f465060 100644 --- a/x/mint/abci.go +++ b/x/mint/abci.go @@ -11,7 +11,7 @@ import ( // BeginBlocker mints new tokens for the previous block. func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyBeginBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) // fetch stored minter & params minter := k.GetMinter(ctx) diff --git a/x/slashing/abci.go b/x/slashing/abci.go index a04cd3c1868..26a3c687564 100644 --- a/x/slashing/abci.go +++ b/x/slashing/abci.go @@ -14,7 +14,7 @@ import ( // BeginBlocker check for infraction evidence or downtime of validators // on every begin block func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyBeginBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) // Iterate over all the validators which *should* have signed this block // store whether or not they have actually signed it and slash/unbond any diff --git a/x/staking/abci.go b/x/staking/abci.go index 9a289acda9f..28253b5bd3f 100644 --- a/x/staking/abci.go +++ b/x/staking/abci.go @@ -14,14 +14,14 @@ import ( // BeginBlocker will persist the current header and validator set as a historical entry // and prune the oldest entry based on the HistoricalEntries parameter func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyBeginBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) k.TrackHistoricalInfo(ctx) } // Called every block, update validator set func EndBlocker(ctx sdk.Context, k keeper.Keeper) []abci.ValidatorUpdate { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyEndBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) return k.BlockValidatorUpdates(ctx) } diff --git a/x/upgrade/abci.go b/x/upgrade/abci.go index 38e5082429f..23645d60264 100644 --- a/x/upgrade/abci.go +++ b/x/upgrade/abci.go @@ -21,7 +21,7 @@ import ( // a migration to be executed if needed upon this switch (migration defined in the new binary) // skipUpgradeHeightArray is a set of block heights for which the upgrade must be skipped func BeginBlocker(k keeper.Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyBeginBlocker) + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) plan, found := k.GetUpgradePlan(ctx) if !found {