From 50858572c07ddef43980131087ac117884d5c13d Mon Sep 17 00:00:00 2001 From: James Milligan Date: Thu, 2 Mar 2023 13:31:22 +0000 Subject: [PATCH 1/2] add debug logging Signed-off-by: James Milligan --- pkg/store/flags.go | 54 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/pkg/store/flags.go b/pkg/store/flags.go index 91b5b0898..f797c5d1f 100644 --- a/pkg/store/flags.go +++ b/pkg/store/flags.go @@ -87,6 +87,14 @@ func (f *Flags) Add(logger *logger.Logger, source string, flags map[string]model for k, newFlag := range flags { storedFlag, ok := f.Get(k) if ok && !f.hasPriority(storedFlag.Source, source) { + logger.Debug( + fmt.Sprintf( + "not overwriting: flag %s from source %s does not have priority over %s", + k, + source, + storedFlag.Source, + ), + ) continue } @@ -118,6 +126,14 @@ func (f *Flags) Update(logger *logger.Logger, source string, flags map[string]mo continue } if !f.hasPriority(storedFlag.Source, source) { + logger.Debug( + fmt.Sprintf( + "not updating: flag %s from source %s does not have priority over %s", + k, + source, + storedFlag.Source, + ), + ) continue } @@ -135,6 +151,12 @@ func (f *Flags) Update(logger *logger.Logger, source string, flags map[string]mo // DeleteFlags matching flags from source. func (f *Flags) DeleteFlags(logger *logger.Logger, source string, flags map[string]model.Flag) map[string]interface{} { + logger.Debug( + fmt.Sprintf( + "store resync triggered: delete event from source %s", + source, + ), + ) notifications := map[string]interface{}{} if len(flags) == 0 { allFlags := f.GetAll() @@ -154,6 +176,14 @@ func (f *Flags) DeleteFlags(logger *logger.Logger, source string, flags map[stri flag, ok := f.Get(k) if ok { if !f.hasPriority(flag.Source, source) { + logger.Debug( + fmt.Sprintf( + "not deleting: flag %s from source %s cannot be deleted by %s", + k, + flag.Source, + source, + ), + ) continue } notifications[k] = map[string]interface{}{ @@ -193,6 +223,13 @@ func (f *Flags) Merge( "source": source, } resyncRequired = true + logger.Debug( + fmt.Sprintf( + "store resync triggered: flag %s has been deleted from source %s", + k, + source, + ), + ) continue } } @@ -203,8 +240,21 @@ func (f *Flags) Merge( newFlag.Source = source storedFlag, ok := f.Get(k) - if ok && (!f.hasPriority(storedFlag.Source, source) || reflect.DeepEqual(storedFlag, newFlag)) { - continue + if ok { + if !f.hasPriority(storedFlag.Source, source) { + logger.Debug( + fmt.Sprintf( + "not merging: flag %s from source %s does not have priority over %s", + k, + source, + storedFlag.Source, + ), + ) + continue + } + if reflect.DeepEqual(storedFlag, newFlag) { + continue + } } if !ok { notifications[k] = map[string]interface{}{ From 6a9f11dd4c93525f685cb88282d8e6a2bcdfd5a5 Mon Sep 17 00:00:00 2001 From: James Milligan Date: Thu, 2 Mar 2023 13:42:39 +0000 Subject: [PATCH 2/2] removed whitespacing for linting to pass Signed-off-by: James Milligan --- pkg/store/flags.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pkg/store/flags.go b/pkg/store/flags.go index f797c5d1f..dc86dffc4 100644 --- a/pkg/store/flags.go +++ b/pkg/store/flags.go @@ -211,7 +211,6 @@ func (f *Flags) Merge( ) (map[string]interface{}, bool) { notifications := map[string]interface{}{} resyncRequired := false - f.mx.Lock() for k, v := range f.Flags { if v.Source == source { @@ -226,8 +225,7 @@ func (f *Flags) Merge( logger.Debug( fmt.Sprintf( "store resync triggered: flag %s has been deleted from source %s", - k, - source, + k, source, ), ) continue @@ -235,19 +233,15 @@ func (f *Flags) Merge( } } f.mx.Unlock() - for k, newFlag := range flags { newFlag.Source = source - storedFlag, ok := f.Get(k) if ok { if !f.hasPriority(storedFlag.Source, source) { logger.Debug( fmt.Sprintf( "not merging: flag %s from source %s does not have priority over %s", - k, - source, - storedFlag.Source, + k, source, storedFlag.Source, ), ) continue @@ -267,10 +261,8 @@ func (f *Flags) Merge( "source": source, } } - // Store the new version of the flag f.Set(k, newFlag) } - return notifications, resyncRequired }