Skip to content

Commit

Permalink
Only warn once when a flag is missing
Browse files Browse the repository at this point in the history
It's totally legitimate to reference a feature flag that doesn't exist,
yet, but before this change, doing so would spam our logs with warnings.
  • Loading branch information
erbridge committed Oct 18, 2024
1 parent 936d5d8 commit a52ef03
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion flags/flags.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package flags

import (
"fmt"
"sync"
"time"

"github.com/launchdarkly/go-sdk-common/v3/ldcontext"
Expand All @@ -14,6 +16,8 @@ var logger = logging.New("flags")

var overrides = make(map[string]bool)

var emittedWarnings = sync.Map{}

type BlueYellowResult string

const (
Expand Down Expand Up @@ -136,7 +140,11 @@ func lookupDefault(context *ldcontext.Context, name string, defaultVal bool) boo
// misconfigured the client).
result, err := currentClient.BoolVariation(name, *context, defaultVal)
if err != nil {
log.Warnf("Failed to fetch value for flag '%s' (returning default %v to caller): %v", name, defaultVal, err)
w := fmt.Sprintf("Failed to fetch value for flag '%s' (returning default %v to caller): %v", name, defaultVal, err)
// Emit the warning once per message.
if _, loaded := emittedWarnings.LoadOrStore(w, true); !loaded {
log.Warn(w)
}
}
return result
}

0 comments on commit a52ef03

Please sign in to comment.