From 4643ce970c7719d402f1a8009e389f2e09da3d5d Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 31 Aug 2023 09:01:11 +0200 Subject: [PATCH] Fail fast on empty wasmvm cache metric setup (backport #1576) (#1580) * Fail fast on wasmvm cache metric setup (cherry picked from commit 4595e6d8f692c0f6bcb8ebd0448ad8819575fbcf) * Adjust to the branch --------- Co-authored-by: Alex Peters --- x/wasm/keeper/metrics.go | 3 +++ x/wasm/keeper/options_test.go | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/x/wasm/keeper/metrics.go b/x/wasm/keeper/metrics.go index 4c4b959f50..93f88581ca 100644 --- a/x/wasm/keeper/metrics.go +++ b/x/wasm/keeper/metrics.go @@ -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), diff --git a/x/wasm/keeper/options_test.go b/x/wasm/keeper/options_test.go index d15b3bf58a..2d65584142 100644 --- a/x/wasm/keeper/options_test.go +++ b/x/wasm/keeper/options_test.go @@ -1,6 +1,7 @@ package keeper import ( + "github.com/prometheus/client_golang/prometheus" "reflect" "testing" @@ -31,6 +32,14 @@ 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) + }, + }, "decorate wasmvm": { srcOpt: WithWasmEngineDecorator(func(old types.WasmerEngine) types.WasmerEngine { require.IsType(t, &wasmvm.VM{}, old)