diff --git a/Dockerfile b/Dockerfile index 4bbcd30dc6..8e0494d2e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,10 +17,10 @@ RUN apk add git WORKDIR /code COPY . /code/ # See https://github.com/CosmWasm/wasmvm/releases -ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.1.0-rc.1/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a -ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.1.0-rc.1/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a -RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep 293a7b1d8468374fc5d079f7082e83e2866729d2d80f8a2d4b0a69e06113c2c7 -RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep 1f0d477ea71e2d0062e1091ef08ea791908fc4c73d0ef95b56326c96df07db8f +ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.1.0-rc.2/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a +ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.1.0-rc.2/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a +RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep c22273727e2a1b7af1968162e30087c948dbaf4f53a2dbdece1de089cba3872d +RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep 3ef25e229658ca3e44c0dd55426006f590d88cebb6e566c52f35cf9b4a203345 # force it to use static lib (from above) not standard libgo_cosmwasm.so file RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make build diff --git a/go.mod b/go.mod index 9abe39f993..55b7dc6672 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/CosmWasm/wasmd go 1.21 require ( - github.com/CosmWasm/wasmvm/v2 v2.1.0-rc.1 + github.com/CosmWasm/wasmvm/v2 v2.1.0-rc.2 github.com/cosmos/cosmos-proto v1.0.0-beta.5 github.com/cosmos/cosmos-sdk v0.50.7 github.com/cosmos/gogogateway v1.2.0 // indirect diff --git a/go.sum b/go.sum index b75d001130..03f5de0cee 100644 --- a/go.sum +++ b/go.sum @@ -225,8 +225,8 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25 github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/CosmWasm/wasmvm/v2 v2.1.0-rc.1 h1:YLJtI6N0STdf4/UAnTzsEuHtHK3ux/vMKbSA7VHn3e8= -github.com/CosmWasm/wasmvm/v2 v2.1.0-rc.1/go.mod h1:bMhLQL4Yp9CzJi9A83aR7VO9wockOsSlZbT4ztOl6bg= +github.com/CosmWasm/wasmvm/v2 v2.1.0-rc.2 h1:gT7UDdmOcHRuQyyUiM5pxTU4wQUSVSaNfaV+01fsl48= +github.com/CosmWasm/wasmvm/v2 v2.1.0-rc.2/go.mod h1:bMhLQL4Yp9CzJi9A83aR7VO9wockOsSlZbT4ztOl6bg= github.com/DataDog/datadog-go v3.2.0+incompatible h1:qSG2N4FghB1He/r2mFrWKCaL7dXCilEuNEeAn20fdD4= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ= diff --git a/x/wasm/keeper/metrics.go b/x/wasm/keeper/metrics.go index 37d7cd4300..a2b26a1f7d 100644 --- a/x/wasm/keeper/metrics.go +++ b/x/wasm/keeper/metrics.go @@ -14,6 +14,7 @@ const ( // metricSource source of wasmvm metrics type metricSource interface { GetMetrics() (*wasmvmtypes.Metrics, error) + GetPinnedMetrics() (*wasmvmtypes.PinnedMetrics, error) } var _ prometheus.Collector = (*WasmVMMetricsCollector)(nil) @@ -25,6 +26,8 @@ type WasmVMMetricsCollector struct { CacheMissesDescr *prometheus.Desc CacheElementsDescr *prometheus.Desc CacheSizeDescr *prometheus.Desc + PinnedHitsDescr *prometheus.Desc + PinnedSizeDescr *prometheus.Desc } // NewWasmVMMetricsCollector constructor @@ -38,6 +41,8 @@ func NewWasmVMMetricsCollector(s metricSource) *WasmVMMetricsCollector { CacheMissesDescr: prometheus.NewDesc("wasmvm_cache_misses_total", "Total number of cache misses", nil, nil), CacheElementsDescr: prometheus.NewDesc("wasmvm_cache_elements_total", "Total number of elements in the cache", []string{"type"}, nil), CacheSizeDescr: prometheus.NewDesc("wasmvm_cache_size_bytes", "Total number of elements in the cache", []string{"type"}, nil), + PinnedHitsDescr: prometheus.NewDesc("wasmvm_pinned_contract_hits", "Number of hits of a pinned contract", []string{"checksum"}, nil), + PinnedSizeDescr: prometheus.NewDesc("wasmvm_pinned_contract_size", "Size of a pinned contract", []string{"checksum"}, nil), } } @@ -57,17 +62,25 @@ func (p *WasmVMMetricsCollector) Describe(descs chan<- *prometheus.Desc) { // Collect is called by the Prometheus registry when collecting metrics. func (p *WasmVMMetricsCollector) Collect(c chan<- prometheus.Metric) { m, err := p.source.GetMetrics() - if err != nil { - return + if err == nil { + c <- prometheus.MustNewConstMetric(p.CacheHitsDescr, prometheus.CounterValue, float64(m.HitsPinnedMemoryCache), labelPinned) + c <- prometheus.MustNewConstMetric(p.CacheHitsDescr, prometheus.CounterValue, float64(m.HitsMemoryCache), labelMemory) + c <- prometheus.MustNewConstMetric(p.CacheHitsDescr, prometheus.CounterValue, float64(m.HitsFsCache), labelFs) + c <- prometheus.MustNewConstMetric(p.CacheMissesDescr, prometheus.CounterValue, float64(m.Misses)) + c <- prometheus.MustNewConstMetric(p.CacheElementsDescr, prometheus.GaugeValue, float64(m.ElementsPinnedMemoryCache), labelPinned) + c <- prometheus.MustNewConstMetric(p.CacheElementsDescr, prometheus.GaugeValue, float64(m.ElementsMemoryCache), labelMemory) + c <- prometheus.MustNewConstMetric(p.CacheSizeDescr, prometheus.GaugeValue, float64(m.SizeMemoryCache), labelMemory) + c <- prometheus.MustNewConstMetric(p.CacheSizeDescr, prometheus.GaugeValue, float64(m.SizePinnedMemoryCache), labelPinned) } - c <- prometheus.MustNewConstMetric(p.CacheHitsDescr, prometheus.CounterValue, float64(m.HitsPinnedMemoryCache), labelPinned) - c <- prometheus.MustNewConstMetric(p.CacheHitsDescr, prometheus.CounterValue, float64(m.HitsMemoryCache), labelMemory) - c <- prometheus.MustNewConstMetric(p.CacheHitsDescr, prometheus.CounterValue, float64(m.HitsFsCache), labelFs) - c <- prometheus.MustNewConstMetric(p.CacheMissesDescr, prometheus.CounterValue, float64(m.Misses)) - c <- prometheus.MustNewConstMetric(p.CacheElementsDescr, prometheus.GaugeValue, float64(m.ElementsPinnedMemoryCache), labelPinned) - c <- prometheus.MustNewConstMetric(p.CacheElementsDescr, prometheus.GaugeValue, float64(m.ElementsMemoryCache), labelMemory) - c <- prometheus.MustNewConstMetric(p.CacheSizeDescr, prometheus.GaugeValue, float64(m.SizeMemoryCache), labelMemory) - c <- prometheus.MustNewConstMetric(p.CacheSizeDescr, prometheus.GaugeValue, float64(m.SizePinnedMemoryCache), labelPinned) + + pm, err := p.source.GetPinnedMetrics() + if err == nil { + for _, mod := range pm.PerModule { + c <- prometheus.MustNewConstMetric(p.PinnedHitsDescr, prometheus.CounterValue, float64(mod.Metrics.Hits), mod.Checksum.String()) + c <- prometheus.MustNewConstMetric(p.PinnedSizeDescr, prometheus.GaugeValue, float64(mod.Metrics.Size), mod.Checksum.String()) + } + } + // Node about fs metrics: // The number of elements and the size of elements in the file system cache cannot easily be obtained. // We had to either scan the whole directory of potentially thousands of files or track the values when files are added or removed. diff --git a/x/wasm/keeper/wasmtesting/mock_engine.go b/x/wasm/keeper/wasmtesting/mock_engine.go index 9ef1c583a2..f35386d7fd 100644 --- a/x/wasm/keeper/wasmtesting/mock_engine.go +++ b/x/wasm/keeper/wasmtesting/mock_engine.go @@ -42,6 +42,7 @@ type MockWasmEngine struct { PinFn func(checksum wasmvm.Checksum) error UnpinFn func(checksum wasmvm.Checksum) error GetMetricsFn func() (*wasmvmtypes.Metrics, error) + GetPinMetricsFn func() (*wasmvmtypes.PinnedMetrics, error) } func (m *MockWasmEngine) IBCChannelOpen(codeID wasmvm.Checksum, env wasmvmtypes.Env, msg wasmvmtypes.IBCChannelOpenMsg, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.IBCChannelOpenResult, uint64, error) { @@ -184,6 +185,13 @@ func (m *MockWasmEngine) GetMetrics() (*wasmvmtypes.Metrics, error) { return m.GetMetricsFn() } +func (m *MockWasmEngine) GetPinnedMetrics() (*wasmvmtypes.PinnedMetrics, error) { + if m.GetPinMetricsFn == nil { + panic("not expected to be called") + } + return m.GetPinMetricsFn() +} + var AlwaysPanicMockWasmEngine = &MockWasmEngine{} // SelfCallingInstMockWasmEngine prepares a WasmEngine mock that calls itself on instantiation. diff --git a/x/wasm/types/wasmer_engine.go b/x/wasm/types/wasmer_engine.go index f3829e9146..fb53494353 100644 --- a/x/wasm/types/wasmer_engine.go +++ b/x/wasm/types/wasmer_engine.go @@ -246,6 +246,9 @@ type WasmEngine interface { // GetMetrics some internal metrics for monitoring purposes. GetMetrics() (*wasmvmtypes.Metrics, error) + + // GetPinnedMetrics some internal metrics about pinned contracts for monitoring purposes. + GetPinnedMetrics() (*wasmvmtypes.PinnedMetrics, error) } var _ wasmvm.KVStore = &StoreAdapter{}