Skip to content

Commit

Permalink
Fetcher: Refer retry configuration inside __init__ to make it configu…
Browse files Browse the repository at this point in the history
…rable when imported

If it's refered from class definition - setting `opal_client_config.DATA_UPDATER_CONN_RETRY` from an importing code would have no effect.
  • Loading branch information
roekatz committed Mar 19, 2024
1 parent 11211d5 commit 4cceee8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
18 changes: 6 additions & 12 deletions packages/opal-client/opal_client/data/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@
class DataFetcher:
"""fetches policy data from backend."""

# Use as default config the configuration provider by opal_client_config.DATA_UPDATER_CONN_RETRY
# Add reraise as true (an option not available for control from the higher-level config)
DEFAULT_RETRY_CONFIG = opal_client_config.DATA_UPDATER_CONN_RETRY.toTenacityConfig()
DEFAULT_RETRY_CONFIG["reraise"] = True

def __init__(
self, default_data_url: str = None, token: str = None, retry_config=None
):
def __init__(self, default_data_url: str = None, token: str = None):
"""
Args:
Expand All @@ -31,15 +24,16 @@ def __init__(
# defaults
default_data_url: str = default_data_url or opal_client_config.DEFAULT_DATA_URL
token: str = token or opal_client_config.CLIENT_TOKEN
self._retry_config = (
retry_config if retry_config is not None else self.DEFAULT_RETRY_CONFIG
)

retry_config = opal_client_config.DATA_UPDATER_CONN_RETRY.toTenacityConfig()
retry_config["reraise"] = True # This is currently not configurable

# The underlying fetching engine
self._engine = FetchingEngine(
worker_count=opal_common_config.FETCHING_WORKER_COUNT,
callback_timeout=opal_common_config.FETCHING_CALLBACK_TIMEOUT,
enqueue_timeout=opal_common_config.FETCHING_ENQUEUE_TIMEOUT,
retry_config=self._retry_config,
retry_config=retry_config,
)
self._data_url = default_data_url
self._token = token
Expand Down
13 changes: 4 additions & 9 deletions packages/opal-client/opal_client/policy/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@ def force_valid_bundle(bundle) -> PolicyBundle:
class PolicyFetcher:
"""fetches policy from backend."""

# Use as default config the configuration provider by opal_client_config.POLICY_UPDATER_CONN_RETRY
# Add reraise as true (an option not available for control from the higher-level config)
DEFAULT_RETRY_CONFIG = (
opal_client_config.POLICY_UPDATER_CONN_RETRY.toTenacityConfig()
)
DEFAULT_RETRY_CONFIG["reraise"] = True

def __init__(self, backend_url=None, token=None, retry_config=None):
def __init__(self, backend_url=None, token=None):
"""
Args:
backend_url (str): Defaults to opal_client_config.SERVER_URL.
Expand All @@ -44,9 +37,11 @@ def __init__(self, backend_url=None, token=None, retry_config=None):
self._token = token or opal_client_config.CLIENT_TOKEN
self._backend_url = backend_url or opal_client_config.SERVER_URL
self._auth_headers = tuple_to_dict(get_authorization_header(self._token))

self._retry_config = (
retry_config if retry_config is not None else self.DEFAULT_RETRY_CONFIG
opal_client_config.POLICY_UPDATER_CONN_RETRY.toTenacityConfig()
)
self._retry_config["reraise"] = True # This is currently not configurable

scope_id = opal_client_config.SCOPE_ID

Expand Down

0 comments on commit 4cceee8

Please sign in to comment.