From 7a838ad64be9a3af6200eaa34a8dfcacff7cf85f Mon Sep 17 00:00:00 2001 From: Tanveer Gill Date: Thu, 4 Jan 2024 14:52:10 -0800 Subject: [PATCH 1/2] Fix unregisters --- pkg/otelcollector/metricsprocessor/processor.go | 2 +- .../concurrency-limiter/concurrency-limiter.go | 10 +++++----- .../concurrency-scheduler/concurrency-scheduler.go | 2 +- .../flowcontrol/actuators/rate-limiter/rate-limiter.go | 8 ++++---- pkg/policies/flowcontrol/actuators/sampler/sampler.go | 8 ++++---- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/otelcollector/metricsprocessor/processor.go b/pkg/otelcollector/metricsprocessor/processor.go index 9d876dd53c..f8b275c9b6 100644 --- a/pkg/otelcollector/metricsprocessor/processor.go +++ b/pkg/otelcollector/metricsprocessor/processor.go @@ -245,7 +245,7 @@ func (p *metricsProcessor) updateMetricsForWorkload(limiterID iface.LimiterID, l Str(metrics.PolicyNameLabel, limiterID.PolicyName). Str(metrics.PolicyHashLabel, limiterID.PolicyHash). Str(metrics.ComponentIDLabel, limiterID.ComponentID). - Msg("LoadScheduler not found") + Msg("Scheduler not found") return } // Observe latency only if the request was allowed by Aperture and response was received from the server (I.E. latency is found) diff --git a/pkg/policies/flowcontrol/actuators/concurrency-limiter/concurrency-limiter.go b/pkg/policies/flowcontrol/actuators/concurrency-limiter/concurrency-limiter.go index d8807930a6..743a55b9b9 100644 --- a/pkg/policies/flowcontrol/actuators/concurrency-limiter/concurrency-limiter.go +++ b/pkg/policies/flowcontrol/actuators/concurrency-limiter/concurrency-limiter.go @@ -256,12 +256,8 @@ func (cl *concurrencyLimiter) setup(lifecycle fx.Lifecycle) error { }, OnStop: func(context.Context) error { var merr, err error - deleted := cl.clFactory.counterVector.DeletePartialMatch(metricLabels) - if deleted == 0 { - logger.Warn().Msg("Could not delete concurrency limiter counter from its metric vector. No traffic to generate metrics?") - } // remove from data engine - err = cl.clFactory.engineAPI.UnregisterRateLimiter(cl) + err = cl.clFactory.engineAPI.UnregisterConcurrencyLimiter(cl) if err != nil { logger.Error().Err(err).Msg("Failed to unregister concurrency limiter") merr = multierr.Append(merr, err) @@ -273,6 +269,10 @@ func (cl *concurrencyLimiter) setup(lifecycle fx.Lifecycle) error { merr = multierr.Append(merr, err) } cl.limiter.Close() + deleted := cl.clFactory.counterVector.DeletePartialMatch(metricLabels) + if deleted == 0 { + logger.Warn().Msg("Could not delete concurrency limiter counter from its metric vector. No traffic to generate metrics?") + } cl.registry.SetStatus(status.NewStatus(nil, merr)) return merr diff --git a/pkg/policies/flowcontrol/actuators/concurrency-scheduler/concurrency-scheduler.go b/pkg/policies/flowcontrol/actuators/concurrency-scheduler/concurrency-scheduler.go index f2d48197dd..000e24f0f2 100644 --- a/pkg/policies/flowcontrol/actuators/concurrency-scheduler/concurrency-scheduler.go +++ b/pkg/policies/flowcontrol/actuators/concurrency-scheduler/concurrency-scheduler.go @@ -286,7 +286,7 @@ func (cs *concurrencyScheduler) setup(lifecycle fx.Lifecycle) error { var merr, err error // remove from data engine - err = cs.csFactory.engineAPI.UnregisterScheduler(cs) + err = cs.csFactory.engineAPI.UnregisterConcurrencyScheduler(cs) if err != nil { logger.Error().Err(err).Msg("Failed to unregister rate limiter") merr = multierr.Append(merr, err) diff --git a/pkg/policies/flowcontrol/actuators/rate-limiter/rate-limiter.go b/pkg/policies/flowcontrol/actuators/rate-limiter/rate-limiter.go index 8b85a4685b..144a0d07f4 100644 --- a/pkg/policies/flowcontrol/actuators/rate-limiter/rate-limiter.go +++ b/pkg/policies/flowcontrol/actuators/rate-limiter/rate-limiter.go @@ -290,10 +290,6 @@ func (rl *rateLimiter) setup(lifecycle fx.Lifecycle) error { }, OnStop: func(context.Context) error { var merr, err error - deleted := rl.rlFactory.counterVector.DeletePartialMatch(metricLabels) - if deleted == 0 { - logger.Warn().Msg("Could not delete rate limiter counter from its metric vector. No traffic to generate metrics?") - } // remove from data engine err = rl.rlFactory.engineAPI.UnregisterRateLimiter(rl) if err != nil { @@ -307,6 +303,10 @@ func (rl *rateLimiter) setup(lifecycle fx.Lifecycle) error { merr = multierr.Append(merr, err) } rl.limiter.Close() + deleted := rl.rlFactory.counterVector.DeletePartialMatch(metricLabels) + if deleted == 0 { + logger.Warn().Msg("Could not delete rate limiter counter from its metric vector. No traffic to generate metrics?") + } rl.registry.SetStatus(status.NewStatus(nil, merr)) return merr diff --git a/pkg/policies/flowcontrol/actuators/sampler/sampler.go b/pkg/policies/flowcontrol/actuators/sampler/sampler.go index 7a276a29b2..e48c55e078 100644 --- a/pkg/policies/flowcontrol/actuators/sampler/sampler.go +++ b/pkg/policies/flowcontrol/actuators/sampler/sampler.go @@ -253,10 +253,6 @@ func (fr *sampler) setup(lifecycle fx.Lifecycle) error { }, OnStop: func(context.Context) error { var merr, err error - deleted := counterVec.DeletePartialMatch(metricLabels) - if deleted == 0 { - logger.Warn().Msg("Could not delete sampler counter from its metric vector. No traffic to generate metrics?") - } // remove from data engine err = fr.factory.engineAPI.UnregisterSampler(fr) if err != nil { @@ -269,6 +265,10 @@ func (fr *sampler) setup(lifecycle fx.Lifecycle) error { logger.Error().Err(err).Msg("Failed to remove decision notifier") merr = multierr.Append(merr, err) } + deleted := counterVec.DeletePartialMatch(metricLabels) + if deleted == 0 { + logger.Warn().Msg("Could not delete sampler counter from its metric vector. No traffic to generate metrics?") + } fr.registry.SetStatus(status.NewStatus(nil, merr)) return merr From 5f1135ee258a7fc2f05d92a808edf3e509ee39ee Mon Sep 17 00:00:00 2001 From: Tanveer Gill Date: Thu, 4 Jan 2024 15:31:21 -0800 Subject: [PATCH 2/2] Fix log --- pkg/policies/flowcontrol/actuators/sampler/sampler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/policies/flowcontrol/actuators/sampler/sampler.go b/pkg/policies/flowcontrol/actuators/sampler/sampler.go index e48c55e078..8a390fe1cc 100644 --- a/pkg/policies/flowcontrol/actuators/sampler/sampler.go +++ b/pkg/policies/flowcontrol/actuators/sampler/sampler.go @@ -256,7 +256,7 @@ func (fr *sampler) setup(lifecycle fx.Lifecycle) error { // remove from data engine err = fr.factory.engineAPI.UnregisterSampler(fr) if err != nil { - logger.Error().Err(err).Msg("Failed to unregister rate limiter") + logger.Error().Err(err).Msg("Failed to unregister sampler") merr = multierr.Append(merr, err) } // remove decisions notifier