-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…1675) * 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 # go.mod Co-authored-by: Robert Pirtle <[email protected]>
- Loading branch information
1 parent
c90fe07
commit e99a1bd
Showing
11 changed files
with
496 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.