From 727f2597e921d97d0a52507876b9d64f2a6710cc Mon Sep 17 00:00:00 2001 From: Robert Pirtle Date: Fri, 25 Aug 2023 15:14:35 -0700 Subject: [PATCH] feat(metrics): add timing metrics to abci methods (#1669) * feat(metrics): add timing metrics to abci methods * update changelog (cherry picked from commit 8b6bbd36f49c2f2995b23044e178de968be4f632) # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 62 +++++++++++++++++++++++++++++++++++++++++++++ x/auction/abci.go | 4 +++ x/bep3/abci.go | 6 +++++ x/cdp/abci.go | 5 ++++ x/committee/abci.go | 6 +++++ x/hard/abci.go | 6 +++++ x/incentive/abci.go | 5 ++++ x/issuance/abci.go | 6 +++++ x/kavadist/abci.go | 6 +++++ x/pricefeed/abci.go | 4 +++ 10 files changed, 110 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69d325bb8b..a2bcee48e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] - (metrics) [#1668] Adds non-state breaking x/metrics module for custom telemetry. +- (metrics) [#1669] Add performance timing metrics to all Begin/EndBlockers ## [v0.21.1](https://github.com/Kava-Labs/kava/releases/tag/v0.21.1) @@ -210,5 +211,66 @@ Bump tendermint version to 0.32.10 to address [cosmos security advisory Lavender [#1668]: https://github.com/Kava-Labs/kava/pull/1668 +<<<<<<< HEAD [#1503]: https://github.com/Kava-Labs/kava/pull/1503 [#1384]: https://github.com/Kava-Labs/kava/pull/1384 +======= +[#1669]: https://github.com/Kava-Labs/kava/pull/1669 +[#1655]: https://github.com/Kava-Labs/kava/pull/1655 +[#1624]: https://github.com/Kava-Labs/kava/pull/1624 +[#1631]: https://github.com/Kava-Labs/kava/pull/1631 +[#1622]: https://github.com/Kava-Labs/kava/pull/1622 +[#1614]: https://github.com/Kava-Labs/kava/pull/1614 +[#1610]: https://github.com/Kava-Labs/kava/pull/1610 +[#1609]: https://github.com/Kava-Labs/kava/pull/1609 +[#1605]: https://github.com/Kava-Labs/kava/pull/1605 +[#1604]: https://github.com/Kava-Labs/kava/pull/1604 +[#1603]: https://github.com/Kava-Labs/kava/pull/1603 +[#1598]: https://github.com/Kava-Labs/kava/pull/1598 +[#1596]: https://github.com/Kava-Labs/kava/pull/1596 +[#1591]: https://github.com/Kava-Labs/kava/pull/1591 +[#1590]: https://github.com/Kava-Labs/kava/pull/1590 +[#1568]: https://github.com/Kava-Labs/kava/pull/1568 +[#1567]: https://github.com/Kava-Labs/kava/pull/1567 +[#1566]: https://github.com/Kava-Labs/kava/pull/1566 +[#1565]: https://github.com/Kava-Labs/kava/pull/1565 +[#1563]: https://github.com/Kava-Labs/kava/pull/1563 +[#1562]: https://github.com/Kava-Labs/kava/pull/1562 +[#1550]: https://github.com/Kava-Labs/kava/pull/1550 +[#1544]: https://github.com/Kava-Labs/kava/pull/1544 +[#1477]: https://github.com/Kava-Labs/kava/pull/1477 +[#1512]: https://github.com/Kava-Labs/kava/pull/1512 +[#1519]: https://github.com/Kava-Labs/kava/pull/1519 +[#1106]: https://github.com/Kava-Labs/kava/pull/1106 +[#1152]: https://github.com/Kava-Labs/kava/pull/1152 +[#1542]: https://github.com/Kava-Labs/kava/pull/1542 +[#253]: https://github.com/Kava-Labs/kava/pull/253 +[#260]: https://github.com/Kava-Labs/kava/pull/260 +[#266]: https://github.com/Kava-Labs/kava/pull/266 +[#364]: https://github.com/Kava-Labs/kava/pull/364 +[#590]: https://github.com/Kava-Labs/kava/pull/590 +[#591]: https://github.com/Kava-Labs/kava/pull/591 +[#596]: https://github.com/Kava-Labs/kava/pull/596 +[#598]: https://github.com/Kava-Labs/kava/pull/598 +[#625]: https://github.com/Kava-Labs/kava/pull/625 +[#701]: https://github.com/Kava-Labs/kava/pull/701 +[#750]: https://github.com/Kava-Labs/kava/pull/750 +[#751]: https://github.com/Kava-Labs/kava/pull/751 +[#780]: https://github.com/Kava-Labs/kava/pull/780 +[unreleased]: https://github.com/Kava-Labs/kava/compare/v0.24.0...HEAD +[v0.24.0]: https://github.com/Kava-Labs/kava/compare/v0.24.0...v0.23.2 +[v0.23.2]: https://github.com/Kava-Labs/kava/compare/v0.23.1...v0.23.2 +[v0.23.1]: https://github.com/Kava-Labs/kava/compare/v0.23.0...v0.23.1 +[v0.23.0]: https://github.com/Kava-Labs/kava/compare/v0.21.1...v0.23.0 +[v0.16.1]: https://github.com/Kava-Labs/kava/compare/v0.16.0...v0.16.1 +[v0.16.0]: https://github.com/Kava-Labs/kava/compare/v0.15.2...v0.16.0 +[v0.13.0]: https://github.com/Kava-Labs/kava/compare/v0.12.4...v0.13.0 +[v0.12.0]: https://github.com/Kava-Labs/kava/compare/v0.11.1...v0.12.0 +[v0.11.0]: https://github.com/Kava-Labs/kava/compare/v0.10.0...v0.11.0 +[v0.8.1]: https://github.com/Kava-Labs/kava/compare/v0.8.0...v0.8.1 +[v0.8.0]: https://github.com/Kava-Labs/kava/compare/v0.7.0...v0.8.0 +[v0.3.5]: https://github.com/Kava-Labs/kava/compare/v0.3.4...v0.3.5 +[v0.3.2]: https://github.com/Kava-Labs/kava/compare/v0.3.1...v0.3.2 +[v0.3.1]: https://github.com/Kava-Labs/kava/compare/v0.3.0...v0.3.1 +[v0.3.0]: https://github.com/Kava-Labs/kava/compare/v0.2.0...v0.3.0 +>>>>>>> 8b6bbd36 (feat(metrics): add timing metrics to abci methods (#1669)) diff --git a/x/auction/abci.go b/x/auction/abci.go index 5b868c687a..6203f6d1ca 100644 --- a/x/auction/abci.go +++ b/x/auction/abci.go @@ -2,7 +2,9 @@ package auction import ( "errors" + "time" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/kava-labs/kava/x/auction/keeper" @@ -12,6 +14,8 @@ import ( // BeginBlocker closes all expired auctions at the end of each block. It panics if // there's an error other than ErrAuctionNotFound. func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + err := k.CloseExpiredAuctions(ctx) if err != nil && !errors.Is(err, types.ErrAuctionNotFound) { panic(err) diff --git a/x/bep3/abci.go b/x/bep3/abci.go index bf62c1df13..194ef1f2ee 100644 --- a/x/bep3/abci.go +++ b/x/bep3/abci.go @@ -1,13 +1,19 @@ package bep3 import ( + "time" + + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/kava-labs/kava/x/bep3/keeper" + "github.com/kava-labs/kava/x/bep3/types" ) // BeginBlocker on every block expires outdated atomic swaps and removes closed // swap from long term storage (default storage time of 1 week) func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + k.UpdateTimeBasedSupplyLimits(ctx) k.UpdateExpiredAtomicSwaps(ctx) k.DeleteClosedAtomicSwapsFromLongtermStorage(ctx) diff --git a/x/cdp/abci.go b/x/cdp/abci.go index 7601c64d37..6a66a48200 100644 --- a/x/cdp/abci.go +++ b/x/cdp/abci.go @@ -2,17 +2,22 @@ package cdp import ( "errors" + "time" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/x/cdp/keeper" + "github.com/kava-labs/kava/x/cdp/types" pricefeedtypes "github.com/kava-labs/kava/x/pricefeed/types" ) // BeginBlocker compounds the debt in outstanding cdps and liquidates cdps that are below the required collateralization ratio func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + params := k.GetParams(ctx) for _, cp := range params.CollateralParams { diff --git a/x/committee/abci.go b/x/committee/abci.go index 8cab4a6454..3e4a745990 100644 --- a/x/committee/abci.go +++ b/x/committee/abci.go @@ -1,14 +1,20 @@ package committee import ( + "time" + + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/tendermint/tendermint/abci/types" "github.com/kava-labs/kava/x/committee/keeper" + "github.com/kava-labs/kava/x/committee/types" ) // BeginBlocker runs at the start of every block. func BeginBlocker(ctx sdk.Context, _ abci.RequestBeginBlock, k keeper.Keeper) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + k.ProcessProposals(ctx) } diff --git a/x/hard/abci.go b/x/hard/abci.go index 17e6cb7e7a..8041011e93 100644 --- a/x/hard/abci.go +++ b/x/hard/abci.go @@ -1,11 +1,17 @@ package hard import ( + "time" + + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/kava-labs/kava/x/hard/keeper" + "github.com/kava-labs/kava/x/hard/types" ) // BeginBlocker updates interest rates func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + k.ApplyInterestRateUpdates(ctx) } diff --git a/x/incentive/abci.go b/x/incentive/abci.go index feac0e6cc5..02d8b67c66 100644 --- a/x/incentive/abci.go +++ b/x/incentive/abci.go @@ -2,14 +2,19 @@ package incentive import ( "fmt" + "time" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/kava-labs/kava/x/incentive/keeper" + "github.com/kava-labs/kava/x/incentive/types" ) // BeginBlocker runs at the start of every block func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + params := k.GetParams(ctx) for _, rp := range params.USDXMintingRewardPeriods { diff --git a/x/issuance/abci.go b/x/issuance/abci.go index 126c02c023..cb6ddca7ba 100644 --- a/x/issuance/abci.go +++ b/x/issuance/abci.go @@ -1,12 +1,18 @@ package issuance import ( + "time" + + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/kava-labs/kava/x/issuance/keeper" + "github.com/kava-labs/kava/x/issuance/types" ) // BeginBlocker iterates over each asset and seizes coins from blocked addresses by returning them to the asset owner func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + err := k.SeizeCoinsForBlockableAssets(ctx) if err != nil { panic(err) diff --git a/x/kavadist/abci.go b/x/kavadist/abci.go index e852714e7a..dbe53d419c 100644 --- a/x/kavadist/abci.go +++ b/x/kavadist/abci.go @@ -1,12 +1,18 @@ package kavadist import ( + "time" + + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/kava-labs/kava/x/kavadist/keeper" + "github.com/kava-labs/kava/x/kavadist/types" ) func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + err := k.MintPeriodInflation(ctx) if err != nil { panic(err) diff --git a/x/pricefeed/abci.go b/x/pricefeed/abci.go index 98754c06d5..8f32c6290f 100644 --- a/x/pricefeed/abci.go +++ b/x/pricefeed/abci.go @@ -2,7 +2,9 @@ package pricefeed import ( "errors" + "time" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/kava-labs/kava/x/pricefeed/keeper" "github.com/kava-labs/kava/x/pricefeed/types" @@ -10,6 +12,8 @@ import ( // EndBlocker updates the current pricefeed func EndBlocker(ctx sdk.Context, k keeper.Keeper) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) + // Update the current price of each asset. for _, market := range k.GetMarkets(ctx) { if !market.Active {