diff --git a/pkg/store/flags.go b/pkg/store/flags.go index 91b5b0898..dc86dffc4 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{}{ @@ -181,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 { @@ -193,18 +222,33 @@ 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 } } } f.mx.Unlock() - for k, newFlag := range flags { 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{}{ @@ -217,10 +261,8 @@ func (f *Flags) Merge( "source": source, } } - // Store the new version of the flag f.Set(k, newFlag) } - return notifications, resyncRequired }