Skip to content

Commit 6cb66b1

Browse files
docs: configuration merge docs (#455)
## This PR - adds documentation for merge events + resyncs Signed-off-by: James Milligan <james@omnant.co.uk> Co-authored-by: Skye Gill <gill.skye95@gmail.com>
1 parent 4c03bfc commit 6cb66b1

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Flagd is configured via CLI arguments on startup, these configuration options ca
1818
- [Flag configuration](./configuration/flag_configuration.md)
1919
- [Fractional evaluation](./configuration/fractional_evaluation.md)
2020
- [Reusable targeting rules](./configuration/reusable_targeting_rules.md)
21+
- [Flag configuration merging](./configuration/flag_configuration_merging.md)
2122

2223
## Help
2324

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Flag Configuration Merging
2+
3+
Flagd can be configured to read from multiple sources at once, when this is the case flagd will merge all flag configurations into a single
4+
merged state. For example:
5+
6+
```mermaid
7+
flowchart LR
8+
source-A -->|config-A| store -->|merge|source-A-config-A\nsource-B-config-B
9+
source-B -->|config-B| store
10+
```
11+
12+
In this example, `source-A` and `source-B` provide a single flag configuration, `config-A` and `config-B` respectively. The merge logic for this configuration is simple, both flag configurations are added to the `store`.
13+
In most scenarios, these flag sources will be supplying `n` number of configurations, using a unique flag key for each configuration. However, as multiple sources are being used, there is the opportunity for keys to be duplicated, intentionally or not, between flag sources. In these situations `flagd` uses a merge priority order to ensure that its behavior is consistent.
14+
15+
Merge order is dictated by the order that `sync-providers` and `uris` are defined, with the latest defined source taking precedence over those defined before it, as an example:
16+
17+
```sh
18+
./flagd start --uri file:source-A.json --uri file:source-B.json --uri file:source-C.json
19+
```
20+
21+
When `flagd` is started with the command defined above, `source-B` takes priority over `source-A`, whilst `source-C` takes priority over both `source-B` and `source-A`. Using the above example, if a flag key is duplicated across all 3 sources, then the configuration from `source-C` would be the only one stored in the merged state.
22+
23+
```mermaid
24+
flowchart LR
25+
source-A -->|config-A| store -->source-C-config-A
26+
source-B -->|config-A| store
27+
source-C -->|config-A| store
28+
```
29+
30+
## State Resync Events
31+
32+
Given the above example, the `source-A` and `source-B` 'versions' of flag configuration `config-A` have been discarded, so if a delete event in `source-C` results in the removal of `config-A`, there will no longer be any reference of` config-A` in flagd's store. As a result of this flagd will return `FLAG_NOT_FOUND` errors, and the OpenFeature SDK will always return the default value.
33+
34+
To prevent flagd falling out of sync with its flag sources during delete events, resync events are used. When a delete event results in a flag configuration being removed from the merged state, the full set of configurations is requested from all flag sources, and the merged state is rebuilt. As a result, the value of `config-A` from `source-B` will be stored in the merged state, preventing flagd from returning `FLAG_NOT_FOUND` errors.
35+
36+
```mermaid
37+
flowchart LR
38+
source-A -->|config-A| store -->source-C-config-A
39+
source-B -->|config-A| store
40+
source-C -->|config-A| store
41+
source-C -->|delete config-A|source-C-config-A
42+
source-C-config-A --> resync-event
43+
```
44+
In the example above, a delete event results in a resync event being fired, as `source-C` has deleted its 'version' of `config-A`, this results in a new merge state being formed from the remaining configurations.
45+
46+
```mermaid
47+
flowchart LR
48+
source-A -->|config-A| store -->source-B-config-A
49+
source-B -->|config-A| store
50+
source-C -->store
51+
52+
```
53+
54+
Resync events may lead to further resync events if the returned flag configurations result in further delete events, however the state will eventually be resolved correctly.

0 commit comments

Comments
 (0)