-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(kit/feature): add feature flag package #17851
Conversation
63f384b
to
239dfd0
Compare
0bd63ca
to
8a1c3df
Compare
6fdd666
to
aae18b4
Compare
4832296
to
f1586a2
Compare
f1586a2
to
56a1949
Compare
Hey there @gavincabbage, i see you're into force pushing. Since you've requested reviews, please refrain from force-pushing until at least all the reviews are complete as it makes it difficult to track your recent work and wastes more time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just a couple nits/comments. Overall really clean.
d = o.Default.(map[string]string) | ||
} | ||
if hasShort { | ||
flagset.StringToStringVarP(destP, o.Flag, string(o.Short), d, o.Desc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will d
being nil cause a panic here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested with this flag both set and not and didn't run into any panics. It's just used as a default, and in launcher.go
we don't use this map if its nil or empty anyway.
Thanks for taking a look @desa! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
af90346
to
663d0cf
Compare
663d0cf
to
9fa3d11
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful work here, @gavincabbage.
This PR adds basic feature flag capabilities to InfluxDB. It allows users to create, consume and manipulate feature flags to exercise experimental feature before they become default behavior. The majority of code in this PR has been deployed internally for the past month and is merely open sourced by this change.
The best description of the functionality provided by this PR is in the included
doc.go
file:Package feature provides feature flagging capabilities for InfluxDB servers. This document describes this package and how it is used to control experimental features in
influxd
.Flags are configured in
flags.yml
at the top of this repository. Runningmake flags
generates Go code based on this configuration to programmatically test flag values in a given request context. Boolean flags are the most common case, but integers, floats and strings are supported for more complicated experiments.The
Flagger
interface is the crux of this package.It computes a map of feature flag values for a given request context. The default implementation always returns the flag default configured in
flags.yml
. The override implementation allows an operator to override feature flag defaults at startup. Changing these overrides requires a restart.In
influxd
, aFlagger
instance is provided to aHandler
middlewareconfigured to intercept all API requests and annotate their request context with a map of feature flags.
A flag can opt in to be exposed externally in
flags.yml
. If exposed, this flag will be included in the response from the new/api/v2/flags
endpoint. This allows the UI and other API clients to control their behavior according to the flag in addition to the server itself.A concrete example to illustrate the above:
I have a feature called "My Feature" that will involve turning on new code in both the UI and the server.
First, I add an entry to
flags.yml
.My flag type is inferred to be boolean by my defaulf of
false
when I runmake flags
and thefeature
package now includesfunc MyFeature() BoolFlag
.I use this to control my backend code with
and the
/api/v2/flags
response provides the same information to the frontend.While
false
by default, I can turn on my experimental feature by starting my server with a flag override.