Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,7 @@ jobs:
- name: start contract test service
run: make start-contract-test-service-bg

- name: Run contract tests v2
uses: launchdarkly/gh-actions/actions/contract-tests@contract-tests-v1
with:
test_service_port: 9000
token: ${{ secrets.GITHUB_TOKEN }}
stop_service: "false"
enable_persistence_tests: "true"

- name: Run contract tests v3
- name: Run contract tests
uses: launchdarkly/gh-actions/actions/contract-tests@contract-tests-v1
with:
test_service_port: 9000
Expand All @@ -77,15 +69,7 @@ jobs:
- name: start async contract test service
run: make start-async-contract-test-service-bg

- name: Run async contract tests v2
uses: launchdarkly/gh-actions/actions/contract-tests@contract-tests-v1
with:
test_service_port: 9001
token: ${{ secrets.GITHUB_TOKEN }}
stop_service: "false"
enable_persistence_tests: "true"

- name: Run async contract tests v3
- name: Run async contract tests
uses: launchdarkly/gh-actions/actions/contract-tests@contract-tests-v1
with:
test_service_port: 9001
Expand Down Expand Up @@ -166,6 +150,7 @@ jobs:
test_service_port: 9000
enable_persistence_tests: "false"
token: ${{ secrets.GITHUB_TOKEN }}
version: v3

- name: Start the async contract test service from the sdist
working-directory: ${{ runner.temp }}/sdist
Expand All @@ -177,6 +162,7 @@ jobs:
test_service_port: 9001
enable_persistence_tests: "false"
token: ${{ secrets.GITHUB_TOKEN }}
version: v3

windows:
runs-on: windows-latest
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ start-async-contract-test-service-bg:

.PHONY: run-contract-tests
run-contract-tests:
@curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/v2/downloader/run.sh \
| VERSION=v2 PARAMS="-url http://localhost:$(PORT) -debug -stop-service-at-end" sh
@curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/v3/downloader/run.sh \
| VERSION=v3 PARAMS="-url http://localhost:$(PORT) -debug -stop-service-at-end" sh

.PHONY: contract-tests
contract-tests: #! Run the contract test harness
Expand Down
22 changes: 0 additions & 22 deletions contract-tests/async_client_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,6 @@ async def start(self):
datasystem_config = config_params.get('dataSystem')
if datasystem_config is not None:
opts["datasystem_config"] = _build_async_data_system(datasystem_config, opts)
elif config_params.get("streaming") is not None:
streaming = config_params["streaming"]
if streaming.get("baseUri") is not None:
opts["stream_uri"] = streaming["baseUri"]
if streaming.get("filter") is not None:
opts["payload_filter_key"] = streaming["filter"]
_set_optional_time_prop(streaming, "initialRetryDelayMs", opts, "initial_reconnect_delay")
elif config_params.get("polling") is not None:
opts['stream'] = False
polling = config_params["polling"]
if polling.get("baseUri") is not None:
opts["base_uri"] = polling["baseUri"]
if polling.get("filter") is not None:
opts["payload_filter_key"] = polling["filter"]
_set_optional_time_prop(polling, "pollIntervalMs", opts, "poll_interval")
elif not endpoints.get('streaming') and not endpoints.get('polling'):
# No data source config and no streaming or polling endpoint means daemon mode.
# A config that sets only an endpoint gets the default streaming data source.
opts['use_ldd'] = True

if config_params.get("events") is not None:
events = config_params["events"]
Expand Down Expand Up @@ -135,9 +116,6 @@ async def start(self):
_set_optional_time_prop(big_params, "staleAfterMs", big_config, "stale_after")
opts["big_segments"] = AsyncBigSegmentsConfig(**big_config)

if config_params.get("persistentDataStore") is not None:
opts["feature_store"] = _create_async_persistent_store(config_params["persistentDataStore"])

start_wait = config_params.get("startWaitTimeMs") or 5000
sdk_config = AsyncConfig(**opts)

Expand Down
3 changes: 0 additions & 3 deletions contract-tests/async_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ async def handle_status(request: aiohttp.web.Request) -> aiohttp.web.Response:
'all-flags-details-only-for-tracked-flags',
'big-segments',
'context-type',
'filtering',
'secure-mode-hash',
'tags',
'event-gzip',
Expand All @@ -69,8 +68,6 @@ async def handle_status(request: aiohttp.web.Request) -> aiohttp.web.Response:
'migrations',
'persistent-data-store-redis',
'fdv1-fallback',
'retry-conformance-fdv1-streaming',
'retry-conformance-fdv1-polling',
'service-endpoints',
'wrapper',
'http-proxy',
Expand Down
23 changes: 0 additions & 23 deletions contract-tests/client_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,26 +131,6 @@ def __init__(self, tag, config):

opts["datasystem_config"] = datasystem.build()

elif config.get("streaming") is not None:
streaming = config["streaming"]
if streaming.get("baseUri") is not None:
opts["stream_uri"] = streaming["baseUri"]
if streaming.get("filter") is not None:
opts["payload_filter_key"] = streaming["filter"]
_set_optional_time_prop(streaming, "initialRetryDelayMs", opts, "initial_reconnect_delay")
elif config.get("polling") is not None:
opts['stream'] = False
polling = config["polling"]
if polling.get("baseUri") is not None:
opts["base_uri"] = polling["baseUri"]
if polling.get("filter") is not None:
opts["payload_filter_key"] = polling["filter"]
_set_optional_time_prop(polling, "pollIntervalMs", opts, "poll_interval")
elif not endpoints.get('streaming') and not endpoints.get('polling'):
# No data source config and no streaming or polling endpoint means daemon mode.
# A config that sets only an endpoint gets the default streaming data source.
opts['use_ldd'] = True

if config.get("events") is not None:
events = config["events"]
opts["enable_event_compression"] = events.get("enableGzip", False)
Expand Down Expand Up @@ -179,9 +159,6 @@ def __init__(self, tag, config):
_set_optional_time_prop(big_params, "staleAfterMs", big_config, "stale_after")
opts["big_segments"] = BigSegmentsConfig(**big_config)

if config.get("persistentDataStore") is not None:
opts["feature_store"] = _create_persistent_store(config["persistentDataStore"])

start_wait = config.get("startWaitTimeMs") or 5000
config = Config(**opts)

Expand Down
3 changes: 0 additions & 3 deletions contract-tests/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def status():
'all-flags-details-only-for-tracked-flags',
'big-segments',
'context-type',
'filtering',
'secure-mode-hash',
'tags',
'migrations',
Expand All @@ -86,8 +85,6 @@ def status():
'flag-change-listeners',
'flag-value-change-listeners',
'fdv1-fallback',
'retry-conformance-fdv1-streaming',
'retry-conformance-fdv1-polling',
'service-endpoints',
'wrapper',
'http-proxy',
Expand Down
8 changes: 4 additions & 4 deletions docs/api-testing.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Test fixtures
=============

ldclient.integrations.test_data module
--------------------------------------
ldclient.integrations.test_datav2 module
----------------------------------------

The entry point for this feature is :class:`ldclient.integrations.test_data.TestData`.
The entry point for this feature is :class:`ldclient.integrations.test_datav2.TestDataV2`.

.. automodule:: ldclient.integrations.test_data
.. automodule:: ldclient.integrations.test_datav2
:members:
:special-members: __init__
:show-inheritance:
59 changes: 29 additions & 30 deletions ldclient/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from typing import Any, Callable, List, Optional, Tuple
from uuid import uuid4

from ldclient.async_config import AsyncConfig
from ldclient.async_feature_store import AsyncInMemoryFeatureStore
from ldclient import async_datasystem
from ldclient.async_config import AsyncConfig, AsyncDataSystemConfig
from ldclient.context import Context
from ldclient.evaluation import EvaluationDetail, FeatureFlagsState
from ldclient.hook import (
Expand Down Expand Up @@ -52,6 +52,18 @@
from ldclient.versioned_data_kind import FEATURES, SEGMENTS


def _is_daemon_mode(datasystem_config: AsyncDataSystemConfig) -> bool:
"""
Return true if the data system has a persistent store and no data sources. The SDK then reads
flags only from the store, which another process such as the Relay Proxy keeps up to date.
"""
return _has_no_data_sources(datasystem_config) and datasystem_config.data_store is not None


def _has_no_data_sources(datasystem_config: AsyncDataSystemConfig) -> bool:
return not datasystem_config.initializers and not datasystem_config.synchronizers


class AsyncLDClient:
"""Async LaunchDarkly SDK client.

Expand All @@ -76,6 +88,7 @@ def __init__(self, config: AsyncConfig):

self._config = config
self._config._instance_id = str(uuid4())
self._datasystem_config = config.datasystem_config or async_datasystem.default().build()
self._lifecycle_lock = asyncio.Lock()

self._started = False
Expand Down Expand Up @@ -202,17 +215,17 @@ async def __start_up(self, start_wait: float):
# Start the big-segment status poll now that a loop is running.
self.__big_segment_store_manager.start()

# FDv2 builds its data sources from builders; wire the shared session into
# them before starting (FDv1 pulls the session itself via its provider).
datasystem_config = self._config.datasystem_config
if datasystem_config is not None and not self._config.offline:
self._wire_data_source_sessions(datasystem_config)
# The data system builds its data sources from builders. Give the shared
# session to the builders before the data system starts.
if not self._config.offline:
self._wire_data_source_sessions(self._datasystem_config)

if self._config.offline:
log.info("Started LaunchDarkly Client in offline mode")

if self._config.use_ldd:
log.info("Started LaunchDarkly Client in LDD mode")
elif _is_daemon_mode(self._datasystem_config):
log.info("Started LaunchDarkly Client in daemon mode")
elif _has_no_data_sources(self._datasystem_config):
log.warning("The data system has no data sources and no persistent store. All evaluations will return default values.")

diagnostic_accumulator = self._set_event_processor(self._config)

Expand All @@ -224,7 +237,7 @@ async def __start_up(self, start_wait: float):
update_processor_ready = AsyncEvent()
self._data_system.start(update_processor_ready)

if not self._config.offline and not self._config.use_ldd:
if not self._config.offline and not _is_daemon_mode(self._datasystem_config):
if start_wait > 60:
log.warning(f"Client was configured to block for up to {start_wait} seconds when initializing. We recommend blocking no longer than 60.")

Expand All @@ -239,7 +252,7 @@ async def __start_up(self, start_wait: float):

def _get_session(self):
"""Return the shared aiohttp session, creating it on first use inside the
event loop. Nothing creates it in offline/LDD mode, because no network
event loop. Nothing creates it in offline or daemon mode, because no network
component asks for it. Uses the same factory as the async transport so
SSL/cert setup and proxy handling stay consistent (proxies are resolved
per request, so the session itself has trust_env=False)."""
Expand All @@ -248,23 +261,9 @@ def _get_session(self):
return self._session

def _make_data_system(self) -> AsyncDataSystem:
datasystem_config = self._config.datasystem_config
if datasystem_config is None:
from ldclient.impl.datasystem.async_fdv1 import AsyncFDv1

return AsyncFDv1(self._config, self._select_feature_store(), self._get_session)

from ldclient.impl.datasystem.async_fdv2 import AsyncFDv2

return AsyncFDv2(self._config, datasystem_config)

def _select_feature_store(self) -> AsyncFeatureStore:
"""Choose the async feature store for the v1 data system based on the
configured store."""
feature_store = self._config.feature_store
if feature_store is None:
return AsyncInMemoryFeatureStore()
return feature_store
return AsyncFDv2(self._config, self._datasystem_config)

def _wire_data_source_sessions(self, data_system_config) -> None:
"""Provide the client's aiohttp session to any async data source
Expand Down Expand Up @@ -394,7 +393,7 @@ async def is_initialized(self) -> bool:

This is a coroutine because determining readiness may query a persistent store.
"""
if self.is_offline() or self._config.use_ldd:
if self.is_offline():
return True

return (await self._data_system.data_availability()).at_least(DataAvailability.CACHED)
Expand Down Expand Up @@ -499,7 +498,7 @@ async def _evaluate_internal(self, key: str, context: Context, default: Any, eve
return EvaluationDetail(default, None, error_reason('CLIENT_NOT_READY')), None

availability = await self._data_system.data_availability()
if availability != DataAvailability.REFRESHED:
if not availability.at_least(self._data_system.target_availability):
if availability == DataAvailability.CACHED:
if not self._eval_cached_data_warned:
self._eval_cached_data_warned = True
Expand Down Expand Up @@ -573,7 +572,7 @@ async def all_flags_state(self, context: Context, **kwargs) -> FeatureFlagsState
return FeatureFlagsState(False)

availability = await self._data_system.data_availability()
if availability != DataAvailability.REFRESHED:
if not availability.at_least(self._data_system.target_availability):
if availability == DataAvailability.CACHED:
if not self._all_flags_cached_data_warned:
self._all_flags_cached_data_warned = True
Expand Down
Loading
Loading