Skip to content

Commit

Permalink
Fail fast on wasmvm cache metric setup
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Aug 28, 2023
1 parent 7c6069d commit 4595e6d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions x/wasm/keeper/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type WasmVMMetricsCollector struct {

// NewWasmVMMetricsCollector constructor
func NewWasmVMMetricsCollector(s metricSource) *WasmVMMetricsCollector {
if s == nil {
panic("wasmvm instance must not be nil")
}
return &WasmVMMetricsCollector{
source: s,
CacheHitsDescr: prometheus.NewDesc("wasmvm_cache_hits_total", "Total number of cache hits", []string{"type"}, nil),
Expand Down
10 changes: 10 additions & 0 deletions x/wasm/keeper/options_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"github.com/prometheus/client_golang/prometheus"
"reflect"
"testing"

Expand Down Expand Up @@ -31,6 +32,15 @@ func TestConstructorOptions(t *testing.T) {
assert.IsType(t, &wasmtesting.MockWasmer{}, k.wasmVM)
},
},
"vm cache metrics": {
srcOpt: WithVMCacheMetrics(prometheus.DefaultRegisterer),
verify: func(t *testing.T, k Keeper) {
t.Helper()
registered := prometheus.DefaultRegisterer.Unregister(NewWasmVMMetricsCollector(k.wasmVM))
assert.True(t, registered)
},
isPostOpt: true,
},
"decorate wasmvm": {
srcOpt: WithWasmEngineDecorator(func(old types.WasmerEngine) types.WasmerEngine {
require.IsType(t, &wasmvm.VM{}, old)
Expand Down

0 comments on commit 4595e6d

Please sign in to comment.