Repository navigation
feat: Add the file-based override source - #453
kinyoklion wants to merge 10 commits into
Conversation
89f544e to
be39b66
Compare
52a065f to
605d0ab
Compare
be39b66 to
6ff51f4
Compare
605d0ab to
5bda436
Compare
6ff51f4 to
e0dd518
Compare
5bda436 to
4287523
Compare
e0dd518 to
356fee9
Compare
4287523 to
703e368
Compare
|
bugbot review |
356fee9 to
de05ef4
Compare
703e368 to
18d4335
Compare
de05ef4 to
aae4984
Compare
18d4335 to
d4f7481
Compare
aae4984 to
db462f2
Compare
d4f7481 to
ddada85
Compare
|
bugbot review |
db462f2 to
21046ad
Compare
d0a8633 to
e0adc16
Compare
21046ad to
d5133ec
Compare
e0adc16 to
15125ab
Compare
|
bugbot review |
d5133ec to
0b2876b
Compare
15125ab to
647d385
Compare
0b2876b to
d02bf8a
Compare
647d385 to
357c6ae
Compare
|
bugbot review |
79e08c0 to
704e7bd
Compare
|
bugbot review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 704e7bd. Configure here.
11d2d5c to
bd01623
Compare
72fc4bc to
6791024
Compare
bd01623 to
178e890
Compare
6791024 to
fe7eef7
Compare
178e890 to
a9b7419
Compare
fe7eef7 to
cd1861c
Compare
a9b7419 to
1fb2959
Compare
| # | ||
| # @example | ||
| # overrides = LaunchDarkly::Integrations::FileData.override_source(paths: ["/etc/launchdarkly/overrides.json"]) | ||
| # config = LaunchDarkly::Config.new(data_system: LaunchDarkly::DataSystem.default.overrides(overrides)) |
There was a problem hiding this comment.
An operator who copies this example gets a client that ignores the override file, and nothing in the logs says so. Config reads data_system_config: and drops unknown keys, so data_system: leaves the client on FDv1 with no override source. With only the key fixed, the unbuilt ConfigBuilder makes LDClient.new raise ArgumentError: wrong number of arguments.
Can this be LaunchDarkly::Config.new(data_system_config: LaunchDarkly::DataSystem.default.overrides(overrides).build), as in the ConfigBuilder#overrides example? The PR description has the same snippet. The data_source_v2 examples above (lines 136, 143, 151) have the same key typo from before this series, if you want to fix them in the same pass.
There was a problem hiding this comment.
This reply was written by an AI agent (Claude Code) working on behalf of @kinyoklion.
Fixed in 1a9d9db. The override_source example now passes data_system_config: LaunchDarkly::DataSystem.default.overrides(overrides).build, and the PR description has the same snippet. In the same commit, the three data_source_v2 examples use data_system_config:, and the four examples in the DataSystem module documentation (lib/ldclient-rb/data_system.rb: default, streaming, polling, and the custom builder), which had the same key and also passed an unbuilt ConfigBuilder, now pass data_system_config: with .build. No example under lib/ uses data_system: any more. Each corrected example was run: every one produces a Config with a DataSystemConfig, and a client built from the override configuration serves the overridden value.
1fb2959 to
725a09b
Compare
cd1861c to
8209864
Compare
Adds `LaunchDarkly::Integrations::FileData.override_source`, the file-based override source that the OVERRIDE specification defines, for use with `LaunchDarkly::DataSystem::ConfigBuilder#overrides`. The source reads one or more JSON or YAML files in the file data source document format (`flags`, `flagValues`, `segments`) and supplies complete snapshots to the SDK's override store. Options: `paths` (required, in precedence order), `duplicate_keys_handling` (`:fail`, the default, or `:ignore`, which keeps the first file's entry), `change_detection` (`:polling`, the default, or `:watching` through the optional listen gem), and `poll_interval` (default 1 second, raised to the 1 second minimum with a warning). Invalid options, including an unknown option key, raise `ArgumentError` when the client is created. Behavior comes from the shared file data code: a configured file that does not exist contributes no overrides, so a file can be created later and deleting a file removes its overrides. A file that exists but cannot be read or parsed fails that reload and keeps the last good overrides, with a logged failure and a retry. A rewrite with identical content is not reapplied. The initial load completes before the client constructor returns. A `flagValues` entry expands into a flag that is off and serves the value, so the evaluation reports the OFF reason kind. Every applied change is logged at Info with the overrides in effect and what each file supplied. The reloader's log lines for this source carry a FileOverrideSource prefix. Flag overrides are currently experimental and subject to change.
…ntries as duplicate keys A path listed more than once would make every entry of that file a duplicate of itself: under the default fail handling the load failed, and under ignore the first listing won by accident. The builder now drops the repeats, keeps the first occurrence in its place in the order, and logs a warning once at build time. This is the behavior the Node SDK has.
… SDKs A flagValues entry becomes a flag without client-side availability, so all_flags_state with client_side_only leaves it out even when the flag it overrides is client-side. A full definition with clientSide is the way to override such a flag. A spec pins both.
The override source chooses each file's format by its name: a name that
ends in .yaml or .yml, in any case, is YAML, and any other file is JSON.
Files must be UTF-8. An override file can be rewritten in place: while the
source finds a file empty during a rewrite, it keeps the overrides in
effect until the new content is written. An empty JSON file is not a valid
document; to remove a file's overrides, delete it or write `{}`.
The override source tests rewrite their files in place, and end-to-end
tests check that the source never supplies a snapshot without the
override, and that a client never serves the LaunchDarkly value, while a
JSON or YAML file is rewritten in place with polling and watching change
detection; also for a YAML file that starts with a comment, for rewrites
about once a second with the default timing, and for files that are not
UTF-8.
Watching follows edits to the configured files and to the targets of configured links, including a ConfigMap update, but not a link further along the path or a configured directory that is pointed elsewhere or replaced. The change detection documentation now says so and points such deployments to polling.
…, in every example Config reads the data system configuration from the data_system_config option and ignores unknown keys, so the examples that passed it as data_system gave a client without that configuration, and without an override source in the override_source example. The DataSystem builders also need build. The override_source, data_source_v2, and DataSystem module examples now pass data_system_config with a built configuration.
725a09b to
e2e01d8
Compare
1a9d9db to
46b384f
Compare
Summary
This PR is stacked on #452 because it supplies the override store that the earlier PRs add, and its client-level spec relies on the marked reasons and events they produce.
This change adds
LaunchDarkly::Integrations::FileData.override_source, the file-based override source that the OVERRIDE specification defines. It is configured withLaunchDarkly::DataSystem::ConfigBuilder#overrides:The source reads one or more JSON or YAML files in the file data source document format (
flags,flagValues,segments) and supplies complete snapshots to the SDK's override store. Its options arepaths(required, non-empty strings in precedence order; a path listed more than once is logged and the repeats are ignored; on Windows, where file names ignore case, paths that differ only in case count as the same path),duplicate_keys_handling(:fail, the default, or:ignore, which keeps the first file's entry),change_detection(:polling, the default, or:watchingthrough the optionallistengem), andpoll_interval(default 1 second, raised to the 1 second minimum with a warning). Invalid options raiseArgumentErrorwhen the client is created, the same way other invalid component configuration is reported. Unlike the Go reference, an unrecognizedduplicate_keys_handlingvalue and an unknown option key are rejected rather than defaulted, because the specification treats invalid configuration as a construction error and an emergency mechanism should fail loudly.Behavior comes from the shared file data code added in #449:
.yamlor.yml, in any case, is YAML, and any other file, including one with no extension, is JSON. The existing file data sources read every file with the YAML parser, which also reads most JSON; the override source does not, so a YAML document in a.jsonfile, or JSON with a#comment or a trailing comma, does not load. Files must be UTF-8; a UTF-16 file, as Windows PowerShell 5.1 writes with>, fails to load with a clear message and keeps the overrides in effect.{}.---), it holds the file back and keeps the overrides in effect until the new content is written: until the file has stayed so, unwritten, for one retry delay (1 second), and for at most five retry delays while it keeps being rewritten. Changes to the other files wait with it, since a reload applies all files or none. The mechanism is described in feat: Add file loading code for flag overrides #449; the public docs say only what an application needs.A
flagValuesentry expands into a flag that is on and serves the value by fallthrough, so the evaluation reports the FALLTHROUGH reason kind. Every applied change is logged at Info with the overrides in effect and what each file supplied, and the reloader's log lines for this source, including the hold's debug lines, carry aFileOverrideSourceprefix.The
override_sourcedocs say how the format is chosen, that files must be UTF-8, that comments and repeated keys in JSON depend on the application'sjsongem, that files can be rewritten in place, how to remove a file's overrides, that an empty JSON file is not a valid document, and that replacing a YAML file in one operation avoids briefly applying a partly written file.Testing
listenrequirement, poll interval clamping), the initial load (merge, fallthrough-form expansion, YAML, missing file, all files missing, malformed file, duplicate keys under both handlings), the Info log format, polling change detection (change, appearance, deletion, malformed edit with recovery, identical rewrite, stop, stop before start), watching change detection (change, appearance, deletion), and a client-level check of serving and reloading overrides throughLDClient.flag overridessuite of sdk-test-harness (3.2.0-alpha.13, built from #515, whose override files are rewritten in place and have no extension) passes against the test service of feat: Add flag overrides to the contract test service #454: 79 tests ran, all passed.can be automatically loaded by Bundler.require, which needs write access to the system gem directory on the test machine. Each new spec was checked against a deliberate defect in the code it covers.The existing FDv1 and FDv2 file data sources keep their current behavior. This series does not change them; the override feature is additive.
SDK-3249
Opened from termag
Note
Overview
Adds
LaunchDarkly::Integrations::FileData.override_sourceso operators can load flag and segment overrides from local JSON/YAML files that take precedence over LaunchDarkly at evaluation time, wired throughDataSystem::ConfigBuilder#overrides. The newFileOverrideSourcereuses the sharedFileData::Reloader(withskip_missing_paths,skip_unchanged, polling or optionallistenwatching) and logs applied overrides with aFileOverrideSource:prefix.Reloadergains a configurablelog_prefix(default[LDClient]) and logs unexpected errors directly instead ofUtil.log_exception.Documentation examples for custom data systems now use
data_system_config:and.buildonDataSystembuilders instead of the olddata_system:shape.Reviewed by Cursor Bugbot for commit 46b384f. Bugbot is set up for automated code reviews on this repo. Configure here.