-
Notifications
You must be signed in to change notification settings - Fork 45
chore: Initial structure and implementation of FDv2 datasystem #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import time | ||
| from typing import Callable, Optional | ||
|
|
||
| from ldclient.impl.listeners import Listeners | ||
| from ldclient.impl.rwlock import ReadWriteLock | ||
| from ldclient.interfaces import ( | ||
| DataSourceErrorInfo, | ||
| DataSourceState, | ||
| DataSourceStatus, | ||
| DataSourceStatusProvider | ||
| ) | ||
|
|
||
|
|
||
| class DataSourceStatusProviderImpl(DataSourceStatusProvider): | ||
| def __init__(self, listeners: Listeners): | ||
| self.__listeners = listeners | ||
| self.__status = DataSourceStatus(DataSourceState.INITIALIZING, 0, None) | ||
| self.__lock = ReadWriteLock() | ||
|
|
||
| @property | ||
| def status(self) -> DataSourceStatus: | ||
| self.__lock.rlock() | ||
| status = self.__status | ||
| self.__lock.runlock() | ||
|
|
||
| return status | ||
|
|
||
| def update_status(self, new_state: DataSourceState, new_error: Optional[DataSourceErrorInfo]): | ||
| status_to_broadcast = None | ||
|
|
||
| try: | ||
| self.__lock.lock() | ||
| old_status = self.__status | ||
|
|
||
| if new_state == DataSourceState.INTERRUPTED and old_status.state == DataSourceState.INITIALIZING: | ||
| new_state = DataSourceState.INITIALIZING | ||
|
|
||
| if new_state == old_status.state and new_error is None: | ||
| return | ||
|
|
||
| new_since = self.__status.since if new_state == self.__status.state else time.time() | ||
| new_error = self.__status.error if new_error is None else new_error | ||
|
|
||
| self.__status = DataSourceStatus(new_state, new_since, new_error) | ||
|
|
||
| status_to_broadcast = self.__status | ||
| finally: | ||
| self.__lock.unlock() | ||
|
|
||
| if status_to_broadcast is not None: | ||
| self.__listeners.notify(status_to_broadcast) | ||
|
|
||
| def add_listener(self, listener: Callable[[DataSourceStatus], None]): | ||
| self.__listeners.add(listener) | ||
|
|
||
| def remove_listener(self, listener: Callable[[DataSourceStatus], None]): | ||
| self.__listeners.remove(listener) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,10 +2,10 @@ | |
| Configuration for LaunchDarkly's data acquisition strategy. | ||
| """ | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Callable, List, Optional, TypeVar | ||
|
|
||
| from ldclient.config import Config as LDConfig | ||
| from ldclient.config import DataSystemConfig | ||
| from ldclient.impl.datasourcev2.polling import ( | ||
| PollingDataSource, | ||
| PollingDataSourceBuilder, | ||
|
|
@@ -22,22 +22,6 @@ | |
| Builder = Callable[[], T] | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was moved. |
||
| class Config: | ||
| """ | ||
| Configuration for LaunchDarkly's data acquisition strategy. | ||
| """ | ||
|
|
||
| initializers: Optional[List[Builder[Initializer]]] | ||
| """The initializers for the data system.""" | ||
|
|
||
| primary_synchronizer: Builder[Synchronizer] | ||
| """The primary synchronizer for the data system.""" | ||
|
|
||
| secondary_synchronizer: Optional[Builder[Synchronizer]] | ||
| """The secondary synchronizers for the data system.""" | ||
|
|
||
|
|
||
| class ConfigBuilder: # pylint: disable=too-few-public-methods | ||
| """ | ||
| Builder for the data system configuration. | ||
|
|
@@ -47,7 +31,7 @@ class ConfigBuilder: # pylint: disable=too-few-public-methods | |
| _primary_synchronizer: Optional[Builder[Synchronizer]] = None | ||
| _secondary_synchronizer: Optional[Builder[Synchronizer]] = None | ||
|
|
||
| def initializers(self, initializers: List[Builder[Initializer]]) -> "ConfigBuilder": | ||
| def initializers(self, initializers: Optional[List[Builder[Initializer]]]) -> "ConfigBuilder": | ||
| """ | ||
| Sets the initializers for the data system. | ||
| """ | ||
|
|
@@ -66,14 +50,14 @@ def synchronizers( | |
| self._secondary_synchronizer = secondary | ||
| return self | ||
|
|
||
| def build(self) -> Config: | ||
| def build(self) -> DataSystemConfig: | ||
| """ | ||
| Builds the data system configuration. | ||
| """ | ||
| if self._primary_synchronizer is None: | ||
| raise ValueError("Primary synchronizer must be set") | ||
|
|
||
| return Config( | ||
| return DataSystemConfig( | ||
| initializers=self._initializers, | ||
| primary_synchronizer=self._primary_synchronizer, | ||
| secondary_synchronizer=self._secondary_synchronizer, | ||
|
|
@@ -144,7 +128,7 @@ def polling(config: LDConfig) -> ConfigBuilder: | |
| streaming, but may be necessary in some network environments. | ||
| """ | ||
|
|
||
| polling_builder = __polling_ds_builder(config) | ||
| polling_builder: Builder[Synchronizer] = __polling_ds_builder(config) | ||
|
|
||
| builder = ConfigBuilder() | ||
| builder.synchronizers(polling_builder) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These ignores are because the data system protocol doesn't expose these methods, but both fdv1 and fdv2 implementations do. So we have to tell the linter to trust us in a few places.