Skip to content

Commit

Permalink
Merge PR cosmos#6761: telemetry: use UTC() in wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
boz authored and chengwenxi committed Jul 22, 2020
1 parent c6f6517 commit fc4ae6c
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 33 deletions.
12 changes: 6 additions & 6 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/adr-013-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
// ...
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/core/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

// ...
}
Expand Down
8 changes: 4 additions & 4 deletions store/cachekv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions store/gaskv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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"))
Expand Down
4 changes: 2 additions & 2 deletions telemetry/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...),
)
}
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion x/crisis/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/evidence/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion x/gov/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion x/mint/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions x/staking/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion x/upgrade/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fc4ae6c

Please sign in to comment.