Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 49 additions & 7 deletions pkg/store/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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()
Expand All @@ -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{}{
Expand Down Expand Up @@ -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 {
Expand All @@ -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{}{
Expand All @@ -217,10 +261,8 @@ func (f *Flags) Merge(
"source": source,
}
}

// Store the new version of the flag
f.Set(k, newFlag)
}

return notifications, resyncRequired
}