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
10 changes: 5 additions & 5 deletions UnleashClient/_async_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from yggdrasil_engine.engine import UnleashEngine

from UnleashClient._async_scheduler import _AsyncJob, _AsyncScheduler
from UnleashClient._async_transport import _AsyncTransport
from UnleashClient._async_unleash_api_client import _AsyncUnleashApiClient
from UnleashClient._payloads import _build_metrics_payload
from UnleashClient.config import UnleashConfig
from UnleashClient.impact_metrics import ImpactMetrics
Expand All @@ -23,7 +23,7 @@ class _AsyncMetricsReporter:

reporter = _AsyncMetricsReporter(
config=config,
transport=transport,
api_client=api_client,
scheduler=scheduler,
engine=engine,
impact_metrics=impact_metrics,
Expand All @@ -38,13 +38,13 @@ class _AsyncMetricsReporter:
def __init__(
self,
config: UnleashConfig,
transport: _AsyncTransport,
api_client: _AsyncUnleashApiClient,
scheduler: _AsyncScheduler,
engine: UnleashEngine,
impact_metrics: ImpactMetrics,
) -> None:
self._config: UnleashConfig = config
self._transport: _AsyncTransport = transport
self._api: _AsyncUnleashApiClient = api_client
self._scheduler: _AsyncScheduler = scheduler
self._engine: UnleashEngine = engine
self._impact_metrics: ImpactMetrics = impact_metrics
Expand Down Expand Up @@ -75,7 +75,7 @@ async def flush(self) -> None:
payload = _build_metrics_payload(self._config, bucket, impact_metrics)
sent = False
try:
sent = await self._transport.send_metrics(payload)
sent = await self._api.send_metrics(payload)
finally:
if not sent and impact_metrics:
self._impact_metrics.restore(impact_metrics)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Asynchronous HTTP transport, for the async Unleash client."""
"""Unleash API client over aiohttp, for the async Unleash client."""

import asyncio
import json
Expand All @@ -7,7 +7,7 @@

from UnleashClient._event_dispatcher import _EventDispatcher
from UnleashClient._headers import _HeaderFactory
from UnleashClient._transport import (
from UnleashClient._unleash_api_client import (
FetchResult,
_emit_fetch_completed,
_failure_status,
Expand Down Expand Up @@ -42,8 +42,8 @@ async def _log_resp_info(resp: "aiohttp.ClientResponse") -> None:
LOGGER.debug("HTTP content: %s", await resp.text())


class _AsyncTransport:
"""The asyncio twin of :class:`UnleashClient._transport._Transport`."""
class _AsyncUnleashApiClient:
"""The asyncio twin of :class:`UnleashClient._unleash_api_client._UnleashApiClient`."""

def __init__(
self,
Expand Down Expand Up @@ -82,10 +82,10 @@ def _timeout(self) -> "aiohttp.ClientTimeout":

async def aclose(self) -> None:
"""
Close the pooled session and put the transport out of service.
Close the pooled session and put the API client out of service.

Every later request raises :class:`AlreadyClosedError`. Closing a
transport that is already closed does nothing.
Every later request raises :class:`AlreadyClosedError`. Closing an already
closed API client does nothing.
"""
with self._close_lock:
if self._is_closed:
Expand All @@ -112,7 +112,7 @@ async def fetch_features(

:param etag: the cached etag, or "" to fetch unconditionally.
:param options: the polling settings
:raises AlreadyClosedError: if the transport has been closed.
:raises AlreadyClosedError: if the API client has been closed.
"""
self._raise_if_closed()

Expand Down Expand Up @@ -202,7 +202,7 @@ async def register(self, payload: Dict[str, Any]) -> bool:

:param payload: as built by
:func:`UnleashClient._payloads._build_register_payload`.
:raises AlreadyClosedError: if the transport has been closed.
:raises AlreadyClosedError: if the API client has been closed.
"""
self._raise_if_closed()

Expand Down Expand Up @@ -249,7 +249,7 @@ async def send_metrics(self, payload: Dict[str, Any]) -> bool:
timeout all return False.

:param payload: the metrics request body.
:raises AlreadyClosedError: if the transport has been closed.
:raises AlreadyClosedError: if the API client has been closed.
:raises asyncio.CancelledError: if the send is cancelled.
"""
self._raise_if_closed()
Expand Down
2 changes: 1 addition & 1 deletion UnleashClient/_feature_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class _FeatureStore:
store = _FeatureStore(engine=UnleashEngine(), cache=cache, events=dispatcher)
store.load_from_cache()

result = transport.fetch_features(etag=store.cached_etag, options=polling)
result = api_client.fetch_features(etag=store.cached_etag, options=polling)
store.apply_fetched(raw_state=result.raw_state, etag=result.etag)
"""

Expand Down
10 changes: 5 additions & 5 deletions UnleashClient/_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from UnleashClient._payloads import _build_metrics_payload
from UnleashClient._scheduler import _ScheduledJob, _Scheduler
from UnleashClient._transport import _Transport
from UnleashClient._unleash_api_client import _UnleashApiClient
from UnleashClient.config import UnleashConfig
from UnleashClient.impact_metrics import ImpactMetrics
from UnleashClient.utils import LOGGER
Expand All @@ -19,7 +19,7 @@ class _MetricsReporter:

reporter = _MetricsReporter(
config=config,
transport=transport,
api_client=api_client,
scheduler=scheduler,
engine=engine,
impact_metrics=impact_metrics,
Expand All @@ -34,13 +34,13 @@ class _MetricsReporter:
def __init__(
self,
config: UnleashConfig,
transport: _Transport,
api_client: _UnleashApiClient,
scheduler: _Scheduler,
engine: UnleashEngine,
impact_metrics: ImpactMetrics,
) -> None:
self._config: UnleashConfig = config
self._transport: _Transport = transport
self._api: _UnleashApiClient = api_client
self._scheduler: _Scheduler = scheduler
self._engine: UnleashEngine = engine
self._impact_metrics: ImpactMetrics = impact_metrics
Expand Down Expand Up @@ -78,7 +78,7 @@ def flush(self) -> None:
return

payload = _build_metrics_payload(self._config, bucket, impact_metrics)
if not self._transport.send_metrics(payload) and impact_metrics:
if not self._api.send_metrics(payload) and impact_metrics:
self._impact_metrics.restore(impact_metrics)

def stop(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _log_resp_info(resp: Response) -> None:
LOGGER.debug("HTTP content: %s", resp.text)


class _Transport:
class _UnleashApiClient:
"""
Sends the SDK's requests to the Unleash server: feature fetches, client
registration and metrics submission.
Expand Down
12 changes: 6 additions & 6 deletions UnleashClient/clients/async_unleash_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from UnleashClient._async_metrics import _AsyncMetricsReporter
from UnleashClient._async_scheduler import _AsyncScheduler
from UnleashClient._async_transport import _AsyncTransport
from UnleashClient._async_unleash_api_client import _AsyncUnleashApiClient
from UnleashClient._context import _ContextEnricher
from UnleashClient._evaluator import _Evaluator
from UnleashClient._event_dispatcher import _EventDispatcher
Expand Down Expand Up @@ -142,13 +142,13 @@ def __init__(
config=self._config,
events=self._event_dispatcher,
)
self._transport: _AsyncTransport = _AsyncTransport(
self._api: _AsyncUnleashApiClient = _AsyncUnleashApiClient(
self._config, self._headers, self._event_dispatcher
)
self._metrics_scheduler: _AsyncScheduler = _AsyncScheduler()
self._metrics: _AsyncMetricsReporter = _AsyncMetricsReporter(
config=self._config,
transport=self._transport,
api_client=self._api,
scheduler=self._metrics_scheduler,
engine=self._engine,
impact_metrics=self.impact_metrics,
Expand Down Expand Up @@ -330,7 +330,7 @@ async def initialize_client(self, fetch_toggles: bool = True) -> None:
self._engine.register_custom_strategies(self._custom_strategies)

if not self._config.metrics.disable_registration:
await self._transport.register(
await self._api.register(
_build_register_payload(self._config, self._custom_strategies)
)

Expand All @@ -339,7 +339,7 @@ async def initialize_client(self, fetch_toggles: bool = True) -> None:

self._connector = _AsyncPollingConnector(
store=self._store,
transport=self._transport,
api_client=self._api,
options=cast(PollingOptions, self._config.mode),
)
await self._connector.start()
Expand Down Expand Up @@ -384,7 +384,7 @@ async def destroy(self) -> None:
except Exception as exc:
LOGGER.warning("Exception during scheduler teardown: %s", exc)

await self._transport.aclose()
await self._api.aclose()

if not isinstance(self._cache, FileCache):
try:
Expand Down
10 changes: 5 additions & 5 deletions UnleashClient/clients/unleash_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from UnleashClient._metrics import _MetricsReporter
from UnleashClient._payloads import _build_register_payload
from UnleashClient._scheduler import _ScheduledJob, _Scheduler
from UnleashClient._transport import _Transport
from UnleashClient._unleash_api_client import _UnleashApiClient
from UnleashClient.cache import BaseCache, FileCache
from UnleashClient.config import (
HttpOptions,
Expand Down Expand Up @@ -199,13 +199,13 @@ def __init__(
events=self.__events,
)

self._transport = _Transport(self._config, self._headers, self.__events)
self._api = _UnleashApiClient(self._config, self._headers, self.__events)

self._scheduler = _Scheduler(scheduler, scheduler_executor)

self._metrics = _MetricsReporter(
config=self._config,
transport=self._transport,
api_client=self._api,
scheduler=self._scheduler,
engine=self._engine,
impact_metrics=self.impact_metrics,
Expand Down Expand Up @@ -297,7 +297,7 @@ def initialize_client(self, fetch_toggles: bool = True) -> None:

# Register app
if not self._config.metrics.disable_registration:
self._transport.register(
self._api.register(
_build_register_payload(self._config, self._custom_strategies)
)
mode = self._config.mode
Expand All @@ -315,7 +315,7 @@ def initialize_client(self, fetch_toggles: bool = True) -> None:
self.connector = PollingConnector(
store=self._store,
scheduler=self._scheduler,
transport=self._transport,
api_client=self._api,
options=mode,
)
else:
Expand Down
12 changes: 6 additions & 6 deletions UnleashClient/connectors/_async_connector.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod

from UnleashClient._async_scheduler import _AsyncScheduler
from UnleashClient._async_transport import _AsyncTransport
from UnleashClient._async_unleash_api_client import _AsyncUnleashApiClient
from UnleashClient._feature_store import _FeatureStore
from UnleashClient.config import PollingOptions

Expand Down Expand Up @@ -32,7 +32,7 @@ class _AsyncPollingConnector(_AsyncBaseConnector):

connector = _AsyncPollingConnector(
store=store,
transport=transport,
api_client=api_client,
options=PollingOptions(interval=15),
)
await connector.start()
Expand All @@ -43,21 +43,21 @@ class _AsyncPollingConnector(_AsyncBaseConnector):
def __init__(
self,
store: _FeatureStore,
transport: _AsyncTransport,
api_client: _AsyncUnleashApiClient,
options: PollingOptions,
) -> None:
"""
:param store: Applies feature state to the engine and the cache.
:param transport: Performs the fetch against the Unleash server.
:param api_client: Performs the fetch against the Unleash server.
:param options: How often to fetch, and which project to fetch.
"""
super().__init__(store)
self._transport: _AsyncTransport = transport
self._api: _AsyncUnleashApiClient = api_client
self._options: PollingOptions = options
self._scheduler: _AsyncScheduler = _AsyncScheduler()

async def _fetch_and_load(self) -> None:
result = await self._transport.fetch_features(
result = await self._api.fetch_features(
etag=self._store.cached_etag, options=self._options
)

Expand Down
10 changes: 5 additions & 5 deletions UnleashClient/connectors/polling_connector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from UnleashClient._feature_store import _FeatureStore
from UnleashClient._scheduler import _ScheduledJob, _Scheduler
from UnleashClient._transport import _Transport
from UnleashClient._unleash_api_client import _UnleashApiClient
from UnleashClient.config import PollingOptions

from .base_connector import BaseConnector
Expand All @@ -13,21 +13,21 @@ def __init__(
self,
store: _FeatureStore,
scheduler: _Scheduler,
transport: _Transport,
api_client: _UnleashApiClient,
options: PollingOptions,
):
"""
:param transport: Performs the fetch against the Unleash server.
:param api_client: Performs the fetch against the Unleash server.
:param options: How often to fetch, and which project to fetch.
"""
super().__init__(store)
self.scheduler: _Scheduler = scheduler
self.transport: _Transport = transport
self.api_client: _UnleashApiClient = api_client
self.options: PollingOptions = options
self.job: _ScheduledJob = None

def _fetch_and_load(self) -> None:
result = self.transport.fetch_features(
result = self.api_client.fetch_features(
self._store.cached_etag, options=self.options
)

Expand Down
6 changes: 3 additions & 3 deletions UnleashClient/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class TransportError(UnleashClientError):
Example::

try:
result = await transport.fetch_features(options=polling)
result = await api_client.fetch_features(options=polling)
except TransportError as error:
LOGGER.error("Could not reach the Unleash server: %s", error)
"""
Expand All @@ -108,10 +108,10 @@ class AlreadyClosedError(TransportError):

Example::

await transport.aclose()
await api_client.aclose()

try:
await transport.fetch_features(options=polling)
await api_client.fetch_features(options=polling)
except AlreadyClosedError:
... # build a new client instead of reusing the closed one
"""
Expand Down
Loading
Loading