Documentation ¶
Index ¶
- Constants
- func ClearOverrides()
- func Close() error
- func Flag(context *ldcontext.Context, name string) bool
- func FlagContextFromContext(ctx context.Context) ldcontext.Context
- func FlagSystem(name string) bool
- func GetUser(id int, r *http.Request) ldcontext.Context
- func GetVersion(id string) ldcontext.Context
- func Init(key string)
- func KillSwitch(context *ldcontext.Context, name string) bool
- func KillSwitchSystem(name string) bool
- func Override(f func(map[string]bool))
- func SpanAttributes(user *ldcontext.Context) (attrs []attribute.KeyValue)
- func WithFlagContext(ctx context.Context, c ldcontext.Context) context.Context
- type BlueYellowResult
Constants ¶
const VersionKind = ldcontext.Kind("version")
Variables ¶
This section is empty.
Functions ¶
func ClearOverrides ¶
func ClearOverrides()
func FlagContextFromContext ¶
FlagContextFromContext returns any LaunchDarkly context stored on the passed Go context, or the "unknown" user context if none is found.
func FlagSystem ¶
func GetVersion ¶
func KillSwitchSystem ¶
func Override ¶
Override allows setting flag overrides. This is usually only used in the context of testing.
func SpanAttributes ¶
SpanAttributes returns a slice of span attributes containing the values of all feature flags (under the "flags." namespace).
Types ¶
type BlueYellowResult ¶
type BlueYellowResult string
const ( ResultBlue BlueYellowResult = "blue" ResultYellow BlueYellowResult = "yellow" )
func FlagBlueYellow ¶
func FlagBlueYellow(context *ldcontext.Context, name string, defaultVal BlueYellowResult) BlueYellowResult
FlagBlueYellow is a wrapper around a boolean flag that serves to conventionalise a blue/green (or in this case blue/yellow) rollout pattern.
You would use it in code that needs to roll out a behavior in both directions -- from yellow to blue and from blue to yellow -- but with a safe fallback value (the provided default) once a rollout is complete. This guards against the possibility of a LaunchDarkly outage accidentally reverting a rollout.
While the naming is idiosyncratic, it serves to emphasise that this is not a "normal" blue-green flag, and care is required when setting up the flag in LaunchDarkly.
You should label the LaunchDarkly variations clearly. The true variation should be "Blue", and the false variation "Yellow". The names should match the default colors assigned to boolean flag variations in LaunchDarkly.
Code that uses this should look something like the following:
rolloutDefault := flags.ResultBlue if flags.FlagBlueYellow(&flagContext, "my-rollout-flag", rolloutDefault) == flags.ResultBlue { // behavior when blue... } else { // behavior when yellow... }
Depending on the situation, you would change the default in code (here, `rolloutDefault`) either when starting a new rollout, or when one has completed. Note: the default value will *only* be used if either
- LaunchDarkly cannot be contacted - the flag is not defined in LaunchDarkly
A LaunchDarkly flag used for blue-yellow rollouts should be clearly annotated, and usually left with targeting switched on at all times.