From aca11d7474d0341b37a17e08a1a719bb3bd158fc Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 11 Oct 2023 15:13:28 +0300 Subject: [PATCH] [#735] policer: Allow to provide metrics from the outside Signed-off-by: Evgenii Stratonikov --- pkg/services/policer/metrics.go | 4 ++++ pkg/services/policer/option.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/services/policer/metrics.go b/pkg/services/policer/metrics.go index 0b83f298c..c2ad2b0b5 100644 --- a/pkg/services/policer/metrics.go +++ b/pkg/services/policer/metrics.go @@ -3,3 +3,7 @@ package policer type MetricsRegister interface { IncProcessedObjects() } + +type noopMetrics struct{} + +func (noopMetrics) IncProcessedObjects() {} diff --git a/pkg/services/policer/option.go b/pkg/services/policer/option.go index 3a2fdc507..fe47555c4 100644 --- a/pkg/services/policer/option.go +++ b/pkg/services/policer/option.go @@ -81,6 +81,7 @@ func defaultCfg() *cfg { rebalanceFreq: 1 * time.Second, sleepDuration: 1 * time.Second, evictDuration: 30 * time.Second, + metrics: noopMetrics{}, } } @@ -172,3 +173,10 @@ func WithPool(p *ants.Pool) Option { c.taskPool = p } } + +// WithMetrics returns option to set metrics. +func WithMetrics(m MetricsRegister) Option { + return func(c *cfg) { + c.metrics = m + } +} -- 2.45.2