Flag overrides are experimentalFlag overrides are available in the SDKs listed below. This feature is experimental and subject to change.Flag overrides use data saving mode, which is only available to members of the LaunchDarkly Early Access Program (EAP).
About flag overrides
Flag overrides are for incidents. Use an override when you need to change a flag in a running application and you cannot make the change through LaunchDarkly. For example, the SDK might not be able to reach LaunchDarkly and is serving flag data that is out of date, or you might not be able to edit the flag in LaunchDarkly. An override applies only to the flags and segments it defines. The SDK continues to use LaunchDarkly data for every other flag. This is the difference from reading flags from a file, which replaces the connection to LaunchDarkly for all flags. Overrides behave as follows:- An override takes precedence over LaunchDarkly data for its key. This includes evaluations that use the flag as a prerequisite and evaluations that use the segment in a rule.
- The SDK serves overrides before it receives any data from LaunchDarkly. An override works even if the SDK never connects.
- Overrides that are in the files when your application starts are in effect after the SDK client finishes starting.
- The SDK does not serve overrides in offline mode.
- An override stays in effect even after LaunchDarkly becomes available again. While a flag has an override, changes that you make to the flag in LaunchDarkly do not affect its evaluations.
Prerequisites
To use flag overrides, you need:- An SDK version that supports flag overrides. Each SDK section below lists the required version.
- An SDK configured for data saving mode. The override source is part of the data system configuration. If your application already configures the data system, add the override source to that configuration. If it does not, set up data saving mode first, and configure any persistent store or Relay Proxy settings through the data system configuration.
Create an override file
Override files use the same format as flag data files. Each file is a JSON or YAML document with up to three properties:flagValues: Flag keys mapped to values. The SDK serves the value to every context. It evaluates the entry as a flag that is on and serves the value as its fallthrough. The evaluation reason kind isFALLTHROUGH.flags: Full flag definitions, keyed by flag key. These can target contexts and use rules, prerequisites, and segments.segments: Segment definitions, keyed by segment key.
my-boolean-flag-key serves false and my-string-flag-key serves "value-1" to every context. my-targeted-flag-key serves true to the user context with the key context-key-123abc and false to every other context.
To override a flag and keep its targeting, start from the flag’s current definition. Download your flag data from the /sdk/latest-all endpoint, as described in Create a flag data file, and copy the flag’s entry from flags. Do not use the /sdk/poll endpoint: its output is not in the file format.
A flagValues entry is not available to client-side SDKs. If you bootstrap a client-side SDK from the server-side SDK’s all flags output, override the flag in flags with a definition copied from LaunchDarkly. That preserves the flag’s client-side availability settings. If you write the definition yourself, set both "clientSide": true and "clientSideAvailability": { "usingEnvironmentId": true }, because SDKs read different properties.
Use multiple files
You can configure more than one override file. The SDK combines the entries from all the files, in the order you list them. If the same flag key or segment key appears in more than one file, the SDK rejects the change by default and keeps the overrides it loaded last. You can configure the SDK to use the entry from the first file that defines the key instead. A configured file that does not exist contributes no overrides. You can create the file when you need it. Deleting the file removes its overrides.Change and remove overrides
The SDK reads every configured file again when any of them changes. Removing an entry from a file removes that override. If a file exists but the SDK cannot read or parse it, the SDK keeps the overrides it loaded last, logs an error, and tries again. The SDK detects changes in one of two ways:- Polling: The SDK checks the files for changes every second. This is the default. Polling works on every file system, including network file systems and directories whose contents are replaced through symbolic links, such as a Kubernetes ConfigMap mounted as a volume. You can make the polling interval longer. The minimum is one second.
- Watching: The SDK reloads the files when the file system reports a change. This is faster than polling, but some file systems do not report changes reliably.
How overrides affect evaluations and events
An evaluation is affected by an override when it reads a definition from an override file. This includes evaluations of a flag with a prerequisite at any depth that has an override. It also includes evaluations of a flag with a rule that uses a segment that has an override. An evaluation that is affected by an override works like this:- The evaluation reason has the
overrideAffectedproperty set totrue. The reason kind is the kind that the definition produces. If the evaluation fails, for example because of a type mismatch, the reason is an error reason that still hasoverrideAffectedset totrue. - The SDK does not send feature events or debug events for the evaluation, even if the flag configuration requests them. LaunchDarkly features that rely on feature events, such as Experimentation, do not receive data from these evaluations.
- The SDK counts the evaluation in the summary events it sends to LaunchDarkly, separately from evaluations that are not affected by an override.
- In the all flags output, an overridden flag is evaluated from its override, and every flag that is affected by an override has event tracking turned off. A flag that exists only in an override file is included. Overrides do not remove any other flag from the output.
Server-side SDKs
This feature is available in the following server-side SDKs:Go
Expand Go code sample
Expand Go code sample
To use flag overrides, configure the data system with a file-based override source.This example reads overrides from The Go SDK reads both JSON and YAML files. To check whether an override affected an evaluation:To learn more, read
Supported versionsFlag overrides are available in the Go SDK version 7.18 and later. In versions 7.18 and 7.19, a
flagValues entry evaluates with the OFF reason kind instead of FALLTHROUGH./etc/launchdarkly/overrides.json:ldoverrides.FileSource() has the following options:FilePaths: The files to read, in precedence order. At least one path is required.DuplicateKeysHandling: What to do when the same key appears in more than one file.ldoverrides.DuplicateKeysFail, the default, rejects the change.ldoverrides.DuplicateKeysKeepFirstuses the entry from the first file that defines the key.ChangeDetection: How the SDK detects file changes. Useldoverrides.Polling, the default, orldoverrides.Watching.PollInterval: The interval between checks in polling mode. The default and the minimum are one second.
ldoverrides.Node.js (server-side)
Expand Node.js (server-side) code sample
Expand Node.js (server-side) code sample
To use flag overrides, configure the data system with a file-based override source.This example reads overrides from The SDK reads the override files when the client starts, without blocking The Node.js (server-side) SDK reads JSON files. It does not include a YAML parser. To read files with a To check whether an override affected an evaluation:To learn more, read
Supported versionsFlag overrides are available in the Node.js (server-side) SDK version 9.15 and later.
/etc/launchdarkly/overrides.json:init. Overrides that are in the files at startup are in effect after the promise that waitForInitialization returns settles, whether it resolves or rejects. An evaluation before then does not see those overrides.The overrides option has the following properties:type: Always'file'.paths: The files to read, in precedence order. At least one path is required.duplicateKeysHandling: What to do when the same key appears in more than one file.'fail', the default, rejects the change.'ignore'uses the entry from the first file that defines the key.changeDetection: How the SDK detects file changes. Use'polling', the default, or'watching'.pollInterval: The interval between checks in polling mode, in seconds. The default and the minimum are one second.yamlParser: A function that parses YAML files.
.yaml or .yml extension, supply a parser in yamlParser that returns the same structure as JSON.parse. If a configured file has a YAML extension and you do not supply a parser, creating the client fails.This example uses the parse function of the yaml package:FileOverrideSourceOptions.