-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[low-code]: Evaluate backoff strategies at runtime #18053
Conversation
@@ -19,7 +21,14 @@ class ConstantBackoffStrategy(BackoffStrategy, JsonSchemaMixin): | |||
backoff_time_in_seconds (float): time to backoff before retrying a retryable request. | |||
""" | |||
|
|||
backoff_time_in_seconds: float | |||
backoff_time_in_seconds: Union[float, InterpolatedString, str] | |||
options: InitVar[Mapping[str, Any]] |
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.
add options and config parameters
|
||
def __post_init__(self, options: Mapping[str, Any]): | ||
if not isinstance(self.backoff_time_in_seconds, InterpolatedString): | ||
self.backoff_time_in_seconds = str(self.backoff_time_in_seconds) |
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.
convert to string if needed
|
||
def backoff(self, response: requests.Response, attempt_count: int) -> Optional[float]: | ||
return self.backoff_time_in_seconds | ||
return self.backoff_time_in_seconds.eval(self.config) |
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.
eval at runtime
@@ -229,14 +229,17 @@ def _create_subcomponent(self, key, definition, kwargs, config, parent_class, in | |||
options = kwargs.get(OPTIONS_STR, {}) | |||
try: | |||
# enums can't accept options | |||
if issubclass(expected_type, enum.Enum): | |||
if issubclass(expected_type, enum.Enum) or self.isBuiltinTypes(definition): |
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.
we can't pass the options parameter if the expected_type is an int, float, or bool
request_options_provider: | ||
request_parameters: | ||
a_parameter: "something_here" | ||
request_headers: | ||
header: header_value | ||
{error_handler} |
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.
make sure we can instantiate all types of backoff strategies
return expected_type(definition) | ||
else: | ||
return expected_type(definition, options=options) | ||
except Exception as e: | ||
raise Exception(f"failed to instantiate type {expected_type}. {e}") | ||
return definition | ||
|
||
def isBuiltinTypes(self, obj): |
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.
snake case instead?
("test_exponential_backoff", 1, BACKOFF_TIME), | ||
("test_exponential_backoff", 2, BACKOFF_TIME), | ||
("test_constant_backoff_first_attempt", 1, BACKOFF_TIME, BACKOFF_TIME), | ||
("test_constant_backoff_second_attempt", 2, BACKOFF_TIME, BACKOFF_TIME), |
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.
Can we also add a test for a float? Right now eval()
would end up casting these to ints
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.
@brianjlai are you referring to the backoff time or the attempt count? I added tests for both.
- backoff time is a float -> backoff time is evaluated as a float
- attempt count is a float -> the value is actually never used. Python auto casts it to int. Do you think we should be stricter and fail if we pass a float instead of an int?
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.
i just meant for backoff time, we were using the constants for BACKOFF_TIME
which were ints, so just adding a true float. I was messing around with things and using the constants eval would come back as int, figured we should just test a float returned too just in case. But I see you added it already so all good!
What
How
options
parameter if the field is a primitiveRecommended reading order
airbyte-cdk/python/airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/constant_backoff_strategy.py
airbyte-cdk/python/airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/exponential_backoff_strategy.py
airbyte-cdk/python/airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/wait_time_from_header_backoff_strategy.py
airbyte-cdk/python/airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/wait_until_time_from_header_backoff_strategy.py
airbyte-cdk/python/airbyte_cdk/sources/declarative/requesters/error_handlers/default_error_handler.py
airbyte-cdk/python/airbyte_cdk/sources/declarative/requesters/http_requester.py
airbyte-cdk/python/airbyte_cdk/sources/declarative/parsers/factory.py
🚨 User Impact 🚨
Are there any breaking changes? What is the end result perceived by the user? If yes, please merge this PR with the 🚨🚨 emoji so changelog authors can further highlight this if needed.
Pre-merge Checklist
Expand the relevant checklist and delete the others.
New Connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
bootstrap.md
. See description and examplesdocs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampledocs/integrations/README.md
airbyte-integrations/builds.md
Airbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing/publish
command described hereUpdating a connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
bootstrap.md
. See description and examplesdocs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampleAirbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing/publish
command described hereConnector Generator
-scaffold
in their name) have been updated with the latest scaffold by running./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates
then checking in your changesTests
Unit
Put your unit tests output here.
Integration
Put your integration tests output here.
Acceptance
Put your acceptance tests output here.