flags

package
v0.0.0-...-de7ece4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const VersionKind = ldcontext.Kind("version")

Variables

This section is empty.

Functions

func ClearOverrides

func ClearOverrides()

func Close

func Close() error

func Flag

func Flag(context *ldcontext.Context, name string) bool

func FlagContextFromContext

func FlagContextFromContext(ctx context.Context) ldcontext.Context

FlagContextFromContext returns any LaunchDarkly context stored on the passed Go context, or the "unknown" user context if none is found.

func FlagSystem

func FlagSystem(name string) bool

func GetUser

func GetUser(id int, r *http.Request) ldcontext.Context

func GetVersion

func GetVersion(id string) ldcontext.Context

func Init

func Init(key string)

func KillSwitch

func KillSwitch(context *ldcontext.Context, name string) bool

func KillSwitchSystem

func KillSwitchSystem(name string) bool

func Override

func Override(f func(map[string]bool))

Override allows setting flag overrides. This is usually only used in the context of testing.

func SpanAttributes

func SpanAttributes(user *ldcontext.Context) (attrs []attribute.KeyValue)

SpanAttributes returns a slice of span attributes containing the values of all feature flags (under the "flags." namespace).

func WithFlagContext

func WithFlagContext(ctx context.Context, c ldcontext.Context) context.Context

WithFlagContext returns a child context that has had the provided LaunchDarkly context stored on it.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL