Skip to content

feat: fetch timeout made configurable #411

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 17 commits into from
Dec 20, 2022

Conversation

ozayr-zaviar
Copy link
Contributor

@ozayr-zaviar ozayr-zaviar commented Nov 23, 2022

Summary

  • Fetch segment and send opd event timeout made configurable through sdk_settings option

Test plan

  • All unit tests and FSC should pass.

Ticket

FSSDK-8693

@msohailhussain msohailhussain marked this pull request as ready for review December 2, 2022 06:26
@msohailhussain msohailhussain requested a review from a team as a code owner December 2, 2022 06:26
Copy link
Contributor

@andrewleap-optimizely andrewleap-optimizely left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! A couple minor suggestions.

Also can we add a test confirming the new settings get passed in appropriately?

api_key: str,
api_host: str,
events: list[OdpEvent],
odp_event_timeout: Optional[int] = None) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
odp_event_timeout: Optional[int] = None) -> bool:
timeout: Optional[int] = None) -> bool:

Seems like odp_event prefix is unnecessary in this context?

def fetch_qualified_segments(self, user_key: str, user_value: str, options: list[str]
) -> Optional[list[str]]:
def fetch_qualified_segments(self, user_key: str, user_value: str, options: list[str],
fetch_segments_timeout: Optional[int]) -> Optional[list[str]]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fetch_segments_timeout: Optional[int]) -> Optional[list[str]]:
timeout: Optional[int]) -> Optional[list[str]]:

fetch_segments is redundant in this context.

@@ -112,7 +112,8 @@ def __init__(self, logger: Optional[optimizely_logger.Logger] = None):
self.logger = logger or optimizely_logger.NoOpLogger()

def fetch_segments(self, api_key: str, api_host: str, user_key: str,
user_value: str, segments_to_check: list[str]) -> Optional[list[str]]:
user_value: str, segments_to_check: list[str],
fetch_segments_timeout: Optional[int] = None) -> Optional[list[str]]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fetch_segments_timeout: Optional[int] = None) -> Optional[list[str]]:
timeout: Optional[int] = None) -> Optional[list[str]]:

@@ -112,7 +112,8 @@ def __init__(self, logger: Optional[optimizely_logger.Logger] = None):
self.logger = logger or optimizely_logger.NoOpLogger()

def fetch_segments(self, api_key: str, api_host: str, user_key: str,
user_value: str, segments_to_check: list[str]) -> Optional[list[str]]:
user_value: str, segments_to_check: list[str],
fetch_segments_timeout: Optional[int] = None) -> Optional[list[str]]:
"""
Fetch segments from ODP GraphQL API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing doc string for the new arg

@@ -56,6 +59,7 @@ def __init__(
self.segment_manager = OdpSegmentManager(segments_cache, logger=self.logger)

self.event_manager = self.event_manager or OdpEventManager(self.logger)
self.event_manager.odp_event_timeout = odp_event_timeout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we pass this in on initialization of the OdpEventManager?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 Pass it down all the way to OdpEventApiManager and OdpSegmentApiManager?

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A suggestion to pass down timeout while initialization. Other than that, it looks good.

@@ -43,14 +43,19 @@ class OdpEventApiManager:
def __init__(self, logger: Optional[optimizely_logger.Logger] = None):
self.logger = logger or optimizely_logger.NoOpLogger()

def send_odp_events(self, api_key: str, api_host: str, events: list[OdpEvent]) -> bool:
def send_odp_events(self,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about passing the timeout value when initializing? We do not need to send timeout for every event. It's not expected we need event-by-event control. Also a custom OdpEventApiManager can have own timeout control.

@@ -112,7 +112,8 @@ def __init__(self, logger: Optional[optimizely_logger.Logger] = None):
self.logger = logger or optimizely_logger.NoOpLogger()

def fetch_segments(self, api_key: str, api_host: str, user_key: str,
user_value: str, segments_to_check: list[str]) -> Optional[list[str]]:
user_value: str, segments_to_check: list[str],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. we may keep the timeout constant locally instead of passing timeout for each api call.

@@ -56,6 +59,7 @@ def __init__(
self.segment_manager = OdpSegmentManager(segments_cache, logger=self.logger)

self.event_manager = self.event_manager or OdpEventManager(self.logger)
self.event_manager.odp_event_timeout = odp_event_timeout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 Pass it down all the way to OdpEventApiManager and OdpSegmentApiManager?

Copy link
Contributor

@andrewleap-optimizely andrewleap-optimizely left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple more small suggestions. Also can we add one more test for Optimizely initialization with OptimizelySdkSettings and the two new parameters?

self.logger = logger or optimizely_logger.NoOpLogger()
self.timeout = timeout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.timeout = timeout
self.timeout = timeout or OdpEventApiConfig.REQUEST_TIMEOUT

Might as well just do this once.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

self.logger = logger or optimizely_logger.NoOpLogger()
self.timeout = timeout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.timeout = timeout
self.timeout = timeout or OdpSegmentApiConfig.REQUEST_TIMEOUT

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

self.logger = logger or optimizely_logger.NoOpLogger()
self.timeout = timeout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor

@andrewleap-optimizely andrewleap-optimizely left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@msohailhussain msohailhussain merged commit f67a0cc into master Dec 20, 2022
@msohailhussain msohailhussain deleted the uzair/fetch-timeout-config branch December 20, 2022 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants