Skip to content

Commit

Permalink
feat: add debug logging for merge behaviour (#456)
Browse files Browse the repository at this point in the history
<!-- Please use this template for your pull request. -->
<!-- Please use the sections that you need and delete other sections -->

## This PR
<!-- add the description of the PR here -->

- adds logging describing merge events, specifically when overwrites /
deletes do not take place

### Related Issues
<!-- add here the GitHub issue that this PR resolves if applicable -->

#453

### Notes
<!-- any additional notes for this PR -->

### Follow-up Tasks
<!-- anything that is related to this PR but not done here should be
noted under this section -->
<!-- if there is a need for a new issue, please link it here -->

### How to test
<!-- if applicable, add testing instructions under this section -->

---------

Signed-off-by: James Milligan <[email protected]>
  • Loading branch information
james-milligan authored Mar 2, 2023
1 parent f907f11 commit dc71e84
Showing 1 changed file with 49 additions and 7 deletions.
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
}

0 comments on commit dc71e84

Please sign in to comment.