Skip to content

Commit

Permalink
feat(x/metrics): add module for emiting custom chain metrics (#1668)
Browse files Browse the repository at this point in the history
* initialize x/metrics with metrics collection

* include global labels in x/metrics metrics

* add x/metrics spec

* add x/metrics test coverage

* update changelog

(cherry picked from commit 9a0aed7)

# Conflicts:
#	CHANGELOG.md
#	app/app.go
#	go.mod
  • Loading branch information
pirtleshell authored and mergify[bot] committed Aug 25, 2023
1 parent c4f0504 commit f94c9a2
Show file tree
Hide file tree
Showing 11 changed files with 539 additions and 0 deletions.
72 changes: 72 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

<<<<<<< HEAD
### State Machine Breaking
[\#1158](https://github.com/Kava-Labs/kava/pull/1158) Split existing auction `bid_duration` parameter into `forward_bid_duration` and `reverse_bid_duration`
=======
### Features
- (metrics) [#1668] Adds non-state breaking x/metrics module for custom telemetry.

### Bug Fixes
- (evmutil) [#1655] Initialize x/evmutil module account in InitGenesis
>>>>>>> 9a0aed76 (feat(x/metrics): add module for emiting custom chain metrics (#1668))
## [v0.16.1](https://github.com/Kava-Labs/kava/releases/tag/v0.16.1)

Expand Down Expand Up @@ -153,4 +161,68 @@ Bump tendermint version to 0.32.10 to address [cosmos security advisory Lavender

### Improvements

<<<<<<< HEAD
[\#257](https://github.com/Kava-Labs/kava/pulls/257) Include scripts to run large-scale simulations remotely using aws-batch
=======
- [#257](https://github.com/Kava-Labs/kava/pulls/257) Include scripts to run
large-scale simulations remotely using aws-batch

[#1668]: https://github.com/Kava-Labs/kava/pull/1668
[#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
>>>>>>> 9a0aed76 (feat(x/metrics): add module for emiting custom chain metrics (#1668))
44 changes: 44 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ import (
kavadistclient "github.com/kava-labs/kava/x/kavadist/client"
kavadistkeeper "github.com/kava-labs/kava/x/kavadist/keeper"
kavadisttypes "github.com/kava-labs/kava/x/kavadist/types"
<<<<<<< HEAD
=======
"github.com/kava-labs/kava/x/liquid"
liquidkeeper "github.com/kava-labs/kava/x/liquid/keeper"
liquidtypes "github.com/kava-labs/kava/x/liquid/types"
metrics "github.com/kava-labs/kava/x/metrics"
metricstypes "github.com/kava-labs/kava/x/metrics/types"
>>>>>>> 9a0aed76 (feat(x/metrics): add module for emiting custom chain metrics (#1668))
pricefeed "github.com/kava-labs/kava/x/pricefeed"
pricefeedkeeper "github.com/kava-labs/kava/x/pricefeed/keeper"
pricefeedtypes "github.com/kava-labs/kava/x/pricefeed/types"
Expand Down Expand Up @@ -197,7 +205,16 @@ var (
savings.AppModuleBasic{},
validatorvesting.AppModuleBasic{},
evmutil.AppModuleBasic{},
<<<<<<< HEAD
bridge.AppModuleBasic{},
=======
liquid.AppModuleBasic{},
earn.AppModuleBasic{},
router.AppModuleBasic{},
mint.AppModuleBasic{},
community.AppModuleBasic{},
metrics.AppModuleBasic{},
>>>>>>> 9a0aed76 (feat(x/metrics): add module for emiting custom chain metrics (#1668))
)

// module account permissions
Expand Down Expand Up @@ -240,6 +257,7 @@ type Options struct {
MempoolAuthAddresses []sdk.AccAddress
EVMTrace string
EVMMaxGasWanted uint64
TelemetryOptions metricstypes.TelemetryOptions
}

// DefaultOptions is a sensible default Options value.
Expand Down Expand Up @@ -700,11 +718,22 @@ func NewApp(
incentive.NewAppModule(app.incentiveKeeper, app.accountKeeper, app.bankKeeper, app.cdpKeeper),
evmutil.NewAppModule(app.evmutilKeeper, app.bankKeeper),
savings.NewAppModule(app.savingsKeeper, app.accountKeeper, app.bankKeeper),
<<<<<<< HEAD
bridge.NewAppModule(app.bridgeKeeper, app.accountKeeper),
=======
liquid.NewAppModule(app.liquidKeeper),
earn.NewAppModule(app.earnKeeper, app.accountKeeper, app.bankKeeper),
router.NewAppModule(app.routerKeeper),
// nil InflationCalculationFn, use SDK's default inflation function
mint.NewAppModule(appCodec, app.mintKeeper, app.accountKeeper, nil),
community.NewAppModule(app.communityKeeper, app.accountKeeper),
metrics.NewAppModule(options.TelemetryOptions),
>>>>>>> 9a0aed76 (feat(x/metrics): add module for emiting custom chain metrics (#1668))
)

// Warning: Some begin blockers must run before others. Ensure the dependencies are understood before modifying this list.
app.mm.SetOrderBeginBlockers(
metricstypes.ModuleName,
// Upgrade begin blocker runs migrations on the first block after an upgrade. It should run before any other module.
upgradetypes.ModuleName,
// Capability begin blocker runs non state changing initialization.
Expand Down Expand Up @@ -786,7 +815,16 @@ func NewApp(
authz.ModuleName,
evmutiltypes.ModuleName,
savingstypes.ModuleName,
<<<<<<< HEAD
bridgetypes.ModuleName,
=======
liquidtypes.ModuleName,
earntypes.ModuleName,
routertypes.ModuleName,
minttypes.ModuleName,
communitytypes.ModuleName,
metricstypes.ModuleName,
>>>>>>> 9a0aed76 (feat(x/metrics): add module for emiting custom chain metrics (#1668))
)

// Warning: Some init genesis methods must run before others. Ensure the dependencies are understood before modifying this list
Expand Down Expand Up @@ -825,6 +863,12 @@ func NewApp(
paramstypes.ModuleName,
upgradetypes.ModuleName,
validatorvestingtypes.ModuleName,
<<<<<<< HEAD
=======
liquidtypes.ModuleName,
routertypes.ModuleName,
metricstypes.ModuleName,
>>>>>>> 9a0aed76 (feat(x/metrics): add module for emiting custom chain metrics (#1668))
)

app.mm.RegisterInvariants(&app.crisisKeeper)
Expand Down
2 changes: 2 additions & 0 deletions cmd/kava/cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/app/params"
metricstypes "github.com/kava-labs/kava/x/metrics/types"
)

const (
Expand Down Expand Up @@ -88,6 +89,7 @@ func (ac appCreator) newApp(
MempoolAuthAddresses: mempoolAuthAddresses,
EVMTrace: cast.ToString(appOpts.Get(ethermintflags.EVMTracer)),
EVMMaxGasWanted: cast.ToUint64(appOpts.Get(ethermintflags.EVMMaxTxGasWanted)),
TelemetryOptions: metricstypes.TelemetryOptionsFromAppOpts(appOpts),
},
baseapp.SetPruning(pruningOpts),
baseapp.SetMinGasPrices(strings.Replace(cast.ToString(appOpts.Get(server.FlagMinGasPrices)), ";", ",", -1)),
Expand Down
36 changes: 36 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,45 @@ module github.com/kava-labs/kava
go 1.17

require (
<<<<<<< HEAD
github.com/cosmos/cosmos-proto v1.0.0-alpha6
github.com/cosmos/cosmos-sdk v0.45.4
github.com/cosmos/ibc-go/v3 v3.0.0
github.com/ethereum/go-ethereum v1.10.16
=======
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4
github.com/cenkalti/backoff/v4 v4.1.3
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.46.11
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-go/v6 v6.1.1
github.com/ethereum/go-ethereum v1.10.26
github.com/evmos/ethermint v0.21.0
github.com/go-kit/kit v0.12.0
>>>>>>> 9a0aed76 (feat(x/metrics): add module for emiting custom chain metrics (#1668))
github.com/gogo/protobuf v1.3.3
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
<<<<<<< HEAD
github.com/kava-labs/kava-bridge v0.2.0
github.com/spf13/cast v1.4.1
github.com/spf13/cobra v1.4.0
github.com/stretchr/testify v1.7.1
github.com/tendermint/tendermint v0.34.19
=======
github.com/linxGnu/grocksdb v1.8.0
github.com/pelletier/go-toml/v2 v2.0.6
github.com/prometheus/client_golang v1.14.0
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.3
github.com/subosito/gotenv v1.4.2
github.com/tendermint/tendermint v0.34.27
>>>>>>> 9a0aed76 (feat(x/metrics): add module for emiting custom chain metrics (#1668))
github.com/tendermint/tm-db v0.6.7
github.com/tharsis/ethermint v0.14.0
google.golang.org/genproto v0.0.0-20220414192740-2d67ff6cf2b4
Expand Down Expand Up @@ -60,8 +85,13 @@ require (
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
<<<<<<< HEAD
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.0 // indirect
=======
github.com/gin-gonic/gin v1.8.1 // indirect
github.com/go-kit/log v0.2.1 // indirect
>>>>>>> 9a0aed76 (feat(x/metrics): add module for emiting custom chain metrics (#1668))
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/go-stack/stack v1.8.0 // indirect
Expand Down Expand Up @@ -110,10 +140,16 @@ require (
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
<<<<<<< HEAD
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
=======
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.40.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
>>>>>>> 9a0aed76 (feat(x/metrics): add module for emiting custom chain metrics (#1668))
github.com/prometheus/tsdb v0.7.1 // indirect
github.com/rakyll/statik v0.1.7 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
Expand Down
12 changes: 12 additions & 0 deletions x/metrics/abci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package metrics

import (
"github.com/kava-labs/kava/x/metrics/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)

// BeginBlocker publishes metrics at the start of each block.
func BeginBlocker(ctx sdk.Context, metrics *types.Metrics) {
metrics.LatestBlockHeight.Set(float64(ctx.BlockHeight()))
}
45 changes: 45 additions & 0 deletions x/metrics/abci_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package metrics_test

import (
"testing"

kitmetrics "github.com/go-kit/kit/metrics"
"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/x/metrics"
"github.com/kava-labs/kava/x/metrics/types"
)

type MockGauge struct {
value float64
}

func (mg *MockGauge) With(labelValues ...string) kitmetrics.Gauge { return mg }
func (mg *MockGauge) Set(value float64) { mg.value = value }
func (*MockGauge) Add(_ float64) {}

func ctxWithHeight(height int64) sdk.Context {
tApp := app.NewTestApp()
tApp.InitializeFromGenesisStates()
return tApp.NewContext(false, tmproto.Header{Height: height})
}

func TestBeginBlockEmitsLatestHeight(t *testing.T) {
gauge := MockGauge{}
myMetrics := &types.Metrics{
LatestBlockHeight: &gauge,
}

metrics.BeginBlocker(ctxWithHeight(1), myMetrics)
require.EqualValues(t, 1, gauge.value)

metrics.BeginBlocker(ctxWithHeight(100), myMetrics)
require.EqualValues(t, 100, gauge.value)

metrics.BeginBlocker(ctxWithHeight(17e6), myMetrics)
require.EqualValues(t, 17e6, gauge.value)
}
Loading

0 comments on commit f94c9a2

Please sign in to comment.