Fix measure since (#6759)

Co-authored-by: Alessio Treglia <alessio@tendermint.com>
This commit is contained in:
Alexander Bezobchuk 2020-07-17 11:34:37 -04:00 committed by GitHub
parent c37f683cc1
commit 5c86ecd1f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 50 additions and 33 deletions

View File

@ -6,6 +6,7 @@ import (
"sort"
"strings"
"syscall"
"time"
abci "github.com/tendermint/tendermint/abci/types"
@ -103,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("abci", "begin_block")
defer telemetry.MeasureSince(time.Now().UTC(), "abci", "begin_block")
if app.cms.TracingEnabled() {
app.cms.SetTracingContext(sdk.TraceContext(
@ -148,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("abci", "end_block")
defer telemetry.MeasureSince(time.Now().UTC(), "abci", "end_block")
if app.deliverState.ms.TracingEnabled() {
app.deliverState.ms = app.deliverState.ms.SetTracingContext(nil).(sdk.CacheMultiStore)
@ -168,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("abci", "check_tx")
defer telemetry.MeasureSince(time.Now().UTC(), "abci", "check_tx")
tx, err := app.txDecoder(req.Tx)
if err != nil {
@ -208,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("abci", "deliver_tx")
defer telemetry.MeasureSince(time.Now().UTC(), "abci", "deliver_tx")
tx, err := app.txDecoder(req.Tx)
if err != nil {
@ -248,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("abci", "commit")
defer telemetry.MeasureSince(time.Now().UTC(), "abci", "commit")
header := app.deliverState.ctx.BlockHeader()
@ -316,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("abci", "query")
defer telemetry.MeasureSince(time.Now().UTC(), "abci", "query")
// handle gRPC routes first rather than calling splitPath because '/' characters
// are used as part of gRPC paths

View File

@ -6,6 +6,7 @@ import (
"io"
"sort"
"sync"
"time"
tmkv "github.com/tendermint/tendermint/libs/kv"
dbm "github.com/tendermint/tm-db"
@ -52,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("store", "cachekv", "get")
defer telemetry.MeasureSince(time.Now().UTC(), "store", "cachekv", "get")
types.AssertValidKey(key)
@ -71,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("store", "cachekv", "set")
defer telemetry.MeasureSince(time.Now().UTC(), "store", "cachekv", "set")
types.AssertValidKey(key)
types.AssertValidValue(value)
@ -89,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("store", "cachekv", "delete")
defer telemetry.MeasureSince(time.Now().UTC(), "store", "cachekv", "delete")
types.AssertValidKey(key)
store.setCacheValue(key, nil, true, true)
@ -99,7 +100,7 @@ func (store *Store) Delete(key []byte) {
func (store *Store) Write() {
store.mtx.Lock()
defer store.mtx.Unlock()
defer telemetry.MeasureSince("store", "cachekv", "write")
defer telemetry.MeasureSince(time.Now().UTC(), "store", "cachekv", "write")
// We need a copy of all of the keys.
// Not the best, but probably not a bottleneck depending.

View File

@ -2,6 +2,7 @@ package gaskv
import (
"io"
"time"
"github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/telemetry"
@ -35,7 +36,7 @@ func (gs *Store) GetStoreType() types.StoreType {
// Implements KVStore.
func (gs *Store) Get(key []byte) (value []byte) {
defer telemetry.MeasureSince("store", "gaskv", "get")
defer telemetry.MeasureSince(time.Now().UTC(), "store", "gaskv", "get")
gs.gasMeter.ConsumeGas(gs.gasConfig.ReadCostFlat, types.GasReadCostFlatDesc)
value = gs.parent.Get(key)
@ -48,7 +49,7 @@ func (gs *Store) Get(key []byte) (value []byte) {
// Implements KVStore.
func (gs *Store) Set(key []byte, value []byte) {
defer telemetry.MeasureSince("store", "gaskv", "set")
defer telemetry.MeasureSince(time.Now().UTC(), "store", "gaskv", "set")
types.AssertValidValue(value)
gs.gasMeter.ConsumeGas(gs.gasConfig.WriteCostFlat, types.GasWriteCostFlatDesc)
@ -59,14 +60,14 @@ func (gs *Store) Set(key []byte, value []byte) {
// Implements KVStore.
func (gs *Store) Has(key []byte) bool {
defer telemetry.MeasureSince("store", "gaskv", "has")
defer telemetry.MeasureSince(time.Now().UTC(), "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("store", "gaskv", "delete")
defer telemetry.MeasureSince(time.Now().UTC(), "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)

View File

@ -4,6 +4,7 @@ import (
"fmt"
"io"
"sync"
"time"
ics23iavl "github.com/confio/ics23-iavl"
ics23 "github.com/confio/ics23/go"
@ -96,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("store", "iavl", "commit")
defer telemetry.MeasureSince(time.Now().UTC(), "store", "iavl", "commit")
hash, version, err := st.tree.SaveVersion()
if err != nil {
@ -145,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("store", "iavl", "set")
defer telemetry.MeasureSince(time.Now().UTC(), "store", "iavl", "set")
types.AssertValidValue(value)
st.tree.Set(key, value)
}
// Implements types.KVStore.
func (st *Store) Get(key []byte) []byte {
defer telemetry.MeasureSince("store", "iavl", "get")
defer telemetry.MeasureSince(time.Now().UTC(), "store", "iavl", "get")
_, value := st.tree.Get(key)
return value
}
// Implements types.KVStore.
func (st *Store) Has(key []byte) (exists bool) {
defer telemetry.MeasureSince("store", "iavl", "has")
defer telemetry.MeasureSince(time.Now().UTC(), "store", "iavl", "has")
return st.tree.Has(key)
}
// Implements types.KVStore.
func (st *Store) Delete(key []byte) {
defer telemetry.MeasureSince("store", "iavl", "delete")
defer telemetry.MeasureSince(time.Now().UTC(), "store", "iavl", "delete")
st.tree.Remove(key)
}
@ -226,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("store", "iavl", "query")
defer telemetry.MeasureSince(time.Now().UTC(), "store", "iavl", "query")
if len(req.Data) == 0 {
return sdkerrors.QueryResult(sdkerrors.Wrap(sdkerrors.ErrTxDecode, "query cannot be zero length"))

View File

@ -20,10 +20,10 @@ func NewLabel(name, value string) metrics.Label {
// ModuleMeasureSince provides a short hand method for emitting a time measure
// metric for a module with a given set of keys. If any global labels are defined,
// they will be added to the module label.
func ModuleMeasureSince(module string, keys ...string) {
func ModuleMeasureSince(module string, start time.Time, keys ...string) {
metrics.MeasureSinceWithLabels(
keys,
time.Now().UTC(),
start,
append([]metrics.Label{NewLabel(MetricLabelNameModule, module)}, globalLabels...),
)
}
@ -65,6 +65,6 @@ 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(keys ...string) {
metrics.MeasureSinceWithLabels(keys, time.Now().UTC(), globalLabels)
func MeasureSince(start time.Time, keys ...string) {
metrics.MeasureSinceWithLabels(keys, start, globalLabels)
}

View File

@ -1,6 +1,8 @@
package crisis
import (
"time"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/crisis/keeper"
@ -9,7 +11,7 @@ import (
// check all registered invariants
func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.MetricKeyEndBlocker)
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyEndBlocker)
if k.InvCheckPeriod() == 0 || ctx.BlockHeight()%int64(k.InvCheckPeriod()) != 0 {
// skip running the invariant check

View File

@ -1,6 +1,8 @@
package distribution
import (
"time"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/telemetry"
@ -12,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, telemetry.MetricKeyBeginBlocker)
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyBeginBlocker)
// determine the total power signing the block
var previousTotalPower, sumPreviousPrecommitPower int64

View File

@ -2,6 +2,7 @@ package evidence
import (
"fmt"
"time"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -16,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, telemetry.MetricKeyBeginBlocker)
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyBeginBlocker)
for _, tmEvidence := range req.ByzantineValidators {
switch tmEvidence.Type {

View File

@ -2,6 +2,7 @@ package gov
import (
"fmt"
"time"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -11,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, telemetry.MetricKeyEndBlocker)
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyEndBlocker)
logger := keeper.Logger(ctx)

View File

@ -1,6 +1,8 @@
package mint
import (
"time"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/mint/keeper"
@ -9,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, telemetry.MetricKeyBeginBlocker)
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyBeginBlocker)
// fetch stored minter & params
minter := k.GetMinter(ctx)

View File

@ -1,6 +1,8 @@
package slashing
import (
"time"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/telemetry"
@ -12,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, telemetry.MetricKeyBeginBlocker)
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), 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

View File

@ -1,6 +1,8 @@
package staking
import (
"time"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/telemetry"
@ -12,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, telemetry.MetricKeyBeginBlocker)
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), 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, telemetry.MetricKeyEndBlocker)
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyEndBlocker)
return k.BlockValidatorUpdates(ctx)
}

View File

@ -2,6 +2,7 @@ package upgrade
import (
"fmt"
"time"
abci "github.com/tendermint/tendermint/abci/types"
@ -20,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, telemetry.MetricKeyBeginBlocker)
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now().UTC(), telemetry.MetricKeyBeginBlocker)
plan, found := k.GetUpgradePlan(ctx)
if !found {