From 764def2ecb091e90c3bb99abbea2c0cdfafd45df Mon Sep 17 00:00:00 2001 From: Karen Stepanyan Date: Mon, 6 Apr 2026 17:10:04 +0400 Subject: [PATCH] change UserMetricsLimiter to gate limitter --- pkg/workflows/wasm/host/execution.go | 2 +- pkg/workflows/wasm/host/module.go | 6 +++++- pkg/workflows/wasm/host/wasm_nodag_test.go | 12 ++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/workflows/wasm/host/execution.go b/pkg/workflows/wasm/host/execution.go index 393b669a92..ec9fd1bbfd 100644 --- a/pkg/workflows/wasm/host/execution.go +++ b/pkg/workflows/wasm/host/execution.go @@ -186,7 +186,7 @@ func (e *execution[T]) log(caller *wasmtime.Caller, ptr int32, ptrlen int32) { } func (e *execution[T]) emitMetric(caller *wasmtime.Caller, ptr int32, ptrlen int32) int32 { - if !e.module.cfg.EnableUserMetrics { + if err := e.module.cfg.EnableUserMetricsLimiter.AllowErr(e.ctx); err != nil { return -1 } diff --git a/pkg/workflows/wasm/host/module.go b/pkg/workflows/wasm/host/module.go index e5d1b3211e..36d64ee4c6 100644 --- a/pkg/workflows/wasm/host/module.go +++ b/pkg/workflows/wasm/host/module.go @@ -82,7 +82,7 @@ type ModuleConfig struct { MaxLogCountDONMode uint32 MaxLogCountNodeMode uint32 - EnableUserMetrics bool + EnableUserMetricsLimiter limits.GateLimiter MaxUserMetricPayloadBytes uint32 MaxUserMetricPayloadLimiter limits.BoundLimiter[config.Size] // supersedes MaxUserMetricPayloadBytes if set MaxUserMetricNameLength uint32 @@ -248,6 +248,10 @@ func NewModule(ctx context.Context, modCfg *ModuleConfig, binary []byte, opts .. lf := limits.Factory{Logger: modCfg.Logger} + if modCfg.EnableUserMetricsLimiter == nil { + modCfg.EnableUserMetricsLimiter = limits.NewGateLimiter(false) + } + if modCfg.MaxUserMetricPayloadLimiter == nil { limit := settings.Size(config.Size(modCfg.MaxUserMetricPayloadBytes)) var err error diff --git a/pkg/workflows/wasm/host/wasm_nodag_test.go b/pkg/workflows/wasm/host/wasm_nodag_test.go index 0e8bf2a0d9..9f77ba1ebb 100644 --- a/pkg/workflows/wasm/host/wasm_nodag_test.go +++ b/pkg/workflows/wasm/host/wasm_nodag_test.go @@ -11,6 +11,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/capabilities/v2/protoc/pkg/test_capabilities/basictrigger" "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/settings/limits" "github.com/smartcontractkit/chainlink-protos/cre/go/sdk" wfpb "github.com/smartcontractkit/chainlink-protos/workflows/go/v2" @@ -158,9 +159,9 @@ func Test_NoDAG_EmitMetricWithLimits(t *testing.T) { trigger := &basictrigger.Outputs{CoolOutput: anyTestTriggerValue} executeRequest := triggerExecuteRequest(t, 0, trigger) cfg := &ModuleConfig{ - Logger: logger.Test(t), - IsUncompressed: true, - EnableUserMetrics: true, + Logger: logger.Test(t), + IsUncompressed: true, + EnableUserMetricsLimiter: limits.NewGateLimiter(true), MaxUserMetricPayloadBytes: 4096, MaxUserMetricNameLength: 15, MaxUserMetricLabelsPerMetric: 10, @@ -198,9 +199,8 @@ func Test_NoDAG_EmitMetricDisabled(t *testing.T) { trigger := &basictrigger.Outputs{CoolOutput: anyTestTriggerValue} executeRequest := triggerExecuteRequest(t, 0, trigger) cfg := &ModuleConfig{ - Logger: logger.Test(t), - IsUncompressed: true, - EnableUserMetrics: false, + Logger: logger.Test(t), + IsUncompressed: true, } binary := createTestBinary(metricLimitsBinaryCmd, metricLimitsBinaryLocation, true, t)