From 7fa6bf54376e873ea5acae51234a983d19d63191 Mon Sep 17 00:00:00 2001 From: Aryan Goyal <137564277+ary82@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:54:54 +0530 Subject: [PATCH 1/2] [extension/jaegerremotesampling] fix: wait for autoUpdateStrategies in Close function Signed-off-by: Aryan Goyal <137564277+ary82@users.noreply.github.com> --- .../internal/source/filesource/filesource.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/extension/jaegerremotesampling/internal/source/filesource/filesource.go b/extension/jaegerremotesampling/internal/source/filesource/filesource.go index f0334c3cbe1d..a55a12ef2cad 100644 --- a/extension/jaegerremotesampling/internal/source/filesource/filesource.go +++ b/extension/jaegerremotesampling/internal/source/filesource/filesource.go @@ -13,6 +13,7 @@ import ( "net/url" "os" "path/filepath" + "sync" "sync/atomic" "time" @@ -34,6 +35,8 @@ type samplingProvider struct { cancelFunc context.CancelFunc options Options + + wg sync.WaitGroup } type storedStrategies struct { @@ -96,6 +99,7 @@ func (h *samplingProvider) GetSamplingStrategy(_ context.Context, serviceName st // Close stops updating the strategies func (h *samplingProvider) Close() error { h.cancelFunc() + h.wg.Wait() return nil } @@ -156,6 +160,9 @@ func (h *samplingProvider) samplingStrategyLoader(strategiesFile string) strateg } func (h *samplingProvider) autoUpdateStrategies(ctx context.Context, interval time.Duration, loader strategyLoader) { + h.wg.Add(1) + defer h.wg.Done() + lastValue := string(nullJSON) ticker := time.NewTicker(interval) defer ticker.Stop() From c48dc0aa0630ecc73e96fa19aa506afdea64dc78 Mon Sep 17 00:00:00 2001 From: Aryan Goyal <137564277+ary82@users.noreply.github.com> Date: Fri, 17 Jan 2025 23:10:21 +0530 Subject: [PATCH 2/2] fix Signed-off-by: Aryan Goyal <137564277+ary82@users.noreply.github.com> --- .../internal/source/filesource/filesource.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extension/jaegerremotesampling/internal/source/filesource/filesource.go b/extension/jaegerremotesampling/internal/source/filesource/filesource.go index a55a12ef2cad..e50d8b711c44 100644 --- a/extension/jaegerremotesampling/internal/source/filesource/filesource.go +++ b/extension/jaegerremotesampling/internal/source/filesource/filesource.go @@ -80,6 +80,7 @@ func NewFileSource(options Options, logger *zap.Logger) (source.Source, error) { } if options.ReloadInterval > 0 { + h.wg.Add(1) go h.autoUpdateStrategies(ctx, options.ReloadInterval, loadFn) } return h, nil @@ -160,9 +161,7 @@ func (h *samplingProvider) samplingStrategyLoader(strategiesFile string) strateg } func (h *samplingProvider) autoUpdateStrategies(ctx context.Context, interval time.Duration, loader strategyLoader) { - h.wg.Add(1) defer h.wg.Done() - lastValue := string(nullJSON) ticker := time.NewTicker(interval) defer ticker.Stop()