Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
feat: [default polling to 10 seconds from 5 minutes; add configurable…
Browse files Browse the repository at this point in the history
… value] (FF-2686) (#60)

* feat: [default polling to 10 seconds from 5 minutes; add configurable value] (FF-2686)

* leave default at 5 min; add comment for breaking change in future

* add config for jitter

* tox
  • Loading branch information
leoromanovsky authored Jul 15, 2024
1 parent c015c4f commit d1b4fa7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ The `init` function accepts the following optional configuration arguments.
| ------ | ----- | ----- | ----- |
| **`assignment_logger`** | [AssignmentLogger](https://github.com/Eppo-exp/python-sdk/blob/ebc1a0b781769fe9d2e2be6fc81779eb8685a6c7/eppo_client/assignment_logger.py#L6-L10) | A callback that sends each assignment to your data warehouse. Required only for experiment analysis. See [example](#assignment-logger) below. | `None` |
| **`is_graceful_mode`** | bool | When true, gracefully handles all exceptions within the assignment function and returns the default value. | `True` |

| **`poll_interval_seconds`** | int | The interval in seconds at which the SDK polls for configuration updates. | `300` |
| **`poll_jitter_seconds`** | int | The jitter in seconds to add to the poll interval. | `30` |

## Assignment logger

Expand Down
2 changes: 2 additions & 0 deletions eppo_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def init(config: Config) -> EppoClient:
__client = EppoClient(
config_requestor=config_requestor,
assignment_logger=assignment_logger,
poll_interval_seconds=config.poll_interval_seconds,
poll_jitter_seconds=config.poll_jitter_seconds,
is_graceful_mode=is_graceful_mode,
)
return __client
Expand Down
11 changes: 8 additions & 3 deletions eppo_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
from eppo_client.configuration_requestor import (
ExperimentConfigurationRequestor,
)
from eppo_client.constants import POLL_INTERVAL_MILLIS, POLL_JITTER_MILLIS
from eppo_client.models import VariationType
from eppo_client.poller import Poller
from eppo_client.sharders import MD5Sharder
from eppo_client.types import Attributes, ValueType
from eppo_client.validation import validate_not_blank
from eppo_client.eval import FlagEvaluation, Evaluator, none_result
from eppo_client.version import __version__
from eppo_client.constants import (
POLL_INTERVAL_SECONDS_DEFAULT,
POLL_JITTER_SECONDS_DEFAULT,
)


logger = logging.getLogger(__name__)
Expand All @@ -33,13 +36,15 @@ def __init__(
config_requestor: ExperimentConfigurationRequestor,
assignment_logger: AssignmentLogger,
is_graceful_mode: bool = True,
poll_interval_seconds: int = POLL_INTERVAL_SECONDS_DEFAULT,
poll_jitter_seconds: int = POLL_JITTER_SECONDS_DEFAULT,
):
self.__config_requestor = config_requestor
self.__assignment_logger = assignment_logger
self.__is_graceful_mode = is_graceful_mode
self.__poller = Poller(
interval_millis=POLL_INTERVAL_MILLIS,
jitter_millis=POLL_JITTER_MILLIS,
interval_millis=poll_interval_seconds * 1000,
jitter_millis=poll_jitter_seconds * 1000,
callback=config_requestor.fetch_and_store_configurations,
)
self.__poller.start()
Expand Down
7 changes: 6 additions & 1 deletion eppo_client/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from eppo_client.assignment_logger import AssignmentLogger
from eppo_client.base_model import SdkBaseModel

from eppo_client.validation import validate_not_blank
from eppo_client.constants import (
POLL_INTERVAL_SECONDS_DEFAULT,
POLL_JITTER_SECONDS_DEFAULT,
)


class Config(SdkBaseModel):
api_key: str
base_url: str = "https://fscdn.eppo.cloud/api"
assignment_logger: AssignmentLogger
is_graceful_mode: bool = True
poll_interval_seconds: int = POLL_INTERVAL_SECONDS_DEFAULT
poll_jitter_seconds: int = POLL_JITTER_SECONDS_DEFAULT

def _validate(self):
validate_not_blank("api_key", self.api_key)
9 changes: 5 additions & 4 deletions eppo_client/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# poller
SECOND_MILLIS = 1000
MINUTE_MILLIS = 60 * SECOND_MILLIS
POLL_JITTER_MILLIS = 30 * SECOND_MILLIS
POLL_INTERVAL_MILLIS = 5 * MINUTE_MILLIS
# We accidently shipped Python with a 5 minute poll interval.
# Customers can set the poll interval to 30 seconds to match the behavior of the other server SDKs.
# Please change this to 30 seconds when ready to bump to 4.0.
POLL_JITTER_SECONDS_DEFAULT = 30 # 30 seconds
POLL_INTERVAL_SECONDS_DEFAULT = 5 * 60 # 5 minutes
5 changes: 4 additions & 1 deletion eppo_client/version.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
__version__ = "3.4.0"
# Note to developers: When ready to bump to 4.0, please change
# the `POLL_INTERVAL_SECONDS` constant in `eppo_client/constants.py`
# to 30 seconds to match the behavior of the other server SDKs.
__version__ = "3.5.0"

0 comments on commit d1b4fa7

Please sign in to comment.