Feature Flags
The feature flag package is included out of the box but is not consumed by any application code.
The feature flag package is a thin wrapper around the split
sdk to make use of feature flags streamlined.
Further reading on feature flags usage and best practices can be found at backstage
here
Implementation
In order to utilize the feature flag package you will have to create a new singleton client
import(
"replay/pkg/featureflag"
"replay/pkg/logger"
)
...
featureflagClient, err := featureflag.NewFeatureFlagClient()
if err != nil {
logger.Error(err, "failed to create split client, falling back to `control` treatment feature flag behavior")
featureflagClient = featureflag.NewFallback()
}
defer featureflagClient.Close()
The above snippet handles sets up a client and handles the case that the service can not connect to split.io.
To use the client to grab the value of a feature flag for a given key (usually a sub name)
treatment := featureflagClient.GetTreatment("quinnmurray", "default_my-awesome-feature")
if treatment == "on" {
logger.Info("Feature flag is on for quinnmurray and all I got was this log")
} else if treatment == "off" {
logger.Info("Feature flag is off for quinnmurray so you will never know what it does")
} else {
logger.Info("Received control from client, here is the serving the default behavior")
}
The above example also exists as a godoc test example located in the featureflagger_test.go
file that can be ran and
tested locally.
Local development
To test your split client locally, you will need to fetch the dev split api key and set SPLIT_API_KEY
export SPLIT_API_KEY=$(gcloud secrets versions access latest --secret split-server-key)