You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6e05c04
Browse filesBrowse the repository at this point in the historyBrowse files
feat: Add experimental support for flag overrides (#580)
<!-- TERMAG_PR_BODY_BEGIN -->
BEGIN_COMMIT_OVERRIDE
feat: Add experimental support for flag overrides, read from local JSON
or YAML files or supplied by a custom override source
feat: Mark evaluations that a flag override affected with
`overrideAffected` in the evaluation reason, and count them under
separate summary counters
fix: Stop the components that already started when the client fails to
start
END_COMMIT_OVERRIDE
Every change in this PR was already reviewed and merged through its own
PR against `feat/overrides`: #525, #526, #527, #528, #529, #530, #572,
#574, #576, #577. This PR merges the branch into `main`.
Flag overrides let an operator force flags and segments to known
definitions on a running client, whether or not the client can reach
LaunchDarkly, and remove the override when the incident is over. They
are an option of the FDv2 data system, on both `LDClient` and
`AsyncLDClient`, with a file-based source in
`ldclient.integrations.overrides.FileOverrideSourceBuilder`, and are
experimental.
The one change outside the feature: #527 stops the components that had
already started when the data system fails to start, so a failed client
construction no longer leaves threads behind.
`main` was merged into `feat/overrides` in 46e5f0e, so the branch has
every `main` commit. That merge resolved two conflicts and made one
follow-up change:
- The capability lists of both contract test services keep both sides:
`flag-overrides` from this branch, and the retry conformance, service
endpoints, wrapper, proxy and TLS capabilities from `main`.
- One async override test used `AsyncHook`, which #548 removed from
`main`. It now uses `Hook`, which the async client accepts.
Before the push:
- the unit test suite passed (2,357 tests, without the Redis, DynamoDB
and Consul store tests, which need servers);
- `mypy`, `isort` and `pycodestyle` were clean;
- the contract test harness's `flag overrides` suite passed against both
the sync and the async test service (88 tests each).
<!-- TERMAG_PR_BODY_END -->
<!-- termag: box=i-0575d1c54853058d7 project=python-server-sdk -->
<sub>Opened from termag</sub>
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Overview**
> Adds **experimental flag overrides** so operators can force known
flag/segment definitions at runtime (via local JSON/YAML files through
`FileOverrideSourceBuilder`, or a custom `OverrideSource`), integrated
into the FDv2 data system for sync and async clients through
`datasystem_config.override_source` / `ConfigBuilder.overrides()`.
>
> The data system now maintains an **override layer** merged over the
normal store, serves override-only flags when LaunchDarkly data is not
ready, and fans out **dependency-aware flag-change notifications** when
LD data affects overridden prerequisites/segments. Evaluations propagate
an **`overrideAffected`** reason marker; analytics treat those
evaluations differently (summary counters only, `all_flags_state`
disables per-flag tracking for them).
>
> Contract test services advertise **`flag-overrides`** and build
override sources from harness config; docs add
`ldclient.integrations.overrides`.
>
> Also **fixes client startup**: if the data system fails to start,
already-started components are stopped so failed construction does not
leak threads.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
46e5f0e. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
log.warning("Feature Flag evaluation attempted before client has initialized! Feature store unavailable - returning default: "+str(default) +" for feature key: "+key)
log.warning("Feature Flag evaluation attempted before client has initialized - using last known values from feature store for feature key: "+key+". This message is logged once.")
507
520
else:
508
-
log.warning("Feature Flag evaluation attempted before client has initialized! Feature store unavailable - returning default: "+str(default) +" for feature key: "+key)
log.warning("all_flags_state() called before client has finished initializing! Using last known values from feature store. This message is logged once.")
581
606
else:
582
-
log.warning("all_flags_state() called before client has finished initializing! Feature store unavailable - returning empty state")
583
-
returnFeatureFlagsState(False)
607
+
# No data from LaunchDarkly is available. When the override layer holds flags,
608
+
# the state contains only those, read from the layer itself: a store that is not
609
+
# initialized can still hold LaunchDarkly data, which the state must not include.
610
+
# Without override flags the state is unavailable, as it is without an override
log.error("Unable to read flags for all_flag_state: %s"%repr(e))
599
-
returnFeatureFlagsState(False)
600
-
626
+
ifoverride_flagsisnotNone:
627
+
ifnotself._all_flags_overrides_only_warned:
628
+
self._all_flags_overrides_only_warned=True
629
+
log.warning("all_flags_state() called before client has finished initializing! Returning only flags from the override layer. This message is logged once.")
0 commit comments