Skip to content

Commit

Permalink
Fail fast on empty wasmvm cache metric setup (backport #1576) (#1580)
Browse files Browse the repository at this point in the history
* Fail fast on wasmvm cache metric setup

(cherry picked from commit 4595e6d)

* Adjust to the branch

---------

Co-authored-by: Alex Peters <alpe@users.noreply.github.com>
  • Loading branch information
mergify[bot] and alpe authored Aug 31, 2023
1 parent 78e5977 commit 4643ce9
Show file tree
Hide file tree
Showing 2 changed files with 12 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
9 changes: 9 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,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)
Expand Down

0 comments on commit 4643ce9

Please sign in to comment.