Skip to content

ingest retry strategy refactor#1708

Merged
rbiseck3 merged 9 commits into
mainfrom
roman/retry-source-connectors
Oct 17, 2023
Merged

ingest retry strategy refactor#1708
rbiseck3 merged 9 commits into
mainfrom
roman/retry-source-connectors

Conversation

@rbiseck3
Copy link
Copy Markdown
Contributor

@rbiseck3 rbiseck3 commented Oct 11, 2023

Description

Pivot from using the retry logic as a decorator as this posed too many limitations on what can be passed in as a parameter at runtime. Moved this to be a class approach and now that can be instantiated with appropriate loggers leveraging the --verbose flag to set the log level. This also mitigates how much new code is being forked from the backoff library. The existing notion client that was using the previous decorator has been refactored to use the new class approach and the airtable connector was updated to support retry logic as well. Default log handlers were introduced which applies to all instances of the retry handler when it starts, backs off, and gives up.

A generic approach was added to configuring the retry parameters in the CLI and was added to the running number of common configs across all CLI commands.

Omitted CHANGELOG entry as this is mostly just a refactor of the retry code. All other connectors will be updated to support retry in another PR but this helps limit the number of changes to review in this one.

Extra fixes

  • Updated local and salesforce source connector to set ingest_doc_cls in a __post_init__ method since this variable can't be serialized.

Testing

Both the airtable and notion ingest tests can be run locally. While they might not pass due to text changes (to be expected when running locally), the process can be viewed in the logs to validate.

Associated issue: #1488

@rbiseck3 rbiseck3 force-pushed the roman/retry-source-connectors branch from 1a4eec7 to 3a6962a Compare October 11, 2023 14:13
@ryannikolaidis
Copy link
Copy Markdown
Contributor

so where we were headed with wrapping / raising those custom errors was that one could catch connection errors and re-run outside of the call to the ingest doc. then the code in the ingest doc itself could be somewhat agnostic to retry logic. obviously notion was a bit of a special case since it has tons of nested internal calls...also maybe not all connection errors necessarily make sense to retry? wondering if a: this still makes sense to consider and b: we need to specify some kind of retry-worthy error.

@rbiseck3
Copy link
Copy Markdown
Contributor Author

rbiseck3 commented Oct 11, 2023

so where we were headed with wrapping / raising those custom errors was that one could catch connection errors and re-run outside of the call to the ingest doc. then the code in the ingest doc itself could be somewhat agnostic to retry logic. obviously notion was a bit of a special case since it has tons of nested internal calls...also maybe not all connection errors necessarily make sense to retry? wondering if a: this still makes sense to consider and b: we need to specify some kind of retry-worthy error.

Some concerns about this, if we move it out of the ingest doc class, then the code that we would be retrying would be the entire get_file method rather than the particular network call that may have failed, adding additional logic that otherwise wouldn't need to be reproduced.

If we're fine with that additional overhead, I can isolate the network calls and wrap that in a specific custom error to indicate it's something that should be retried.

@ryannikolaidis
Copy link
Copy Markdown
Contributor

so where we were headed with wrapping / raising those custom errors was that one could catch connection errors and re-run outside of the call to the ingest doc. then the code in the ingest doc itself could be somewhat agnostic to retry logic. obviously notion was a bit of a special case since it has tons of nested internal calls...also maybe not all connection errors necessarily make sense to retry? wondering if a: this still makes sense to consider and b: we need to specify some kind of retry-worthy error.

Some concerns about this, if we move it out of the ingest doc class, then the code that we would be retrying would be the entire get_file method rather than the particular network call that may have failed, adding additional logic that otherwise wouldn't need to be reproduced.

If we're fine with that additional overhead, I can isolate the network calls and wrap that in a specific custom error to indicate it's something that should be retried.

yea, totally understood and agreed. I think in a majority of cases that extra logic is going to be nominal. for instance, with the airbyte connector you updated here afaict in get_file the only thing it is doing before the actual query is importing pd. That said, totally get that this isn't always the case...clearly for Notion, what you're doing makes a ton of sense. maybe some simple compromise, do exactly what you're doing, but assuming the user doesn't specify retry then we use the call instead to just raise some custom error for "retry-able" issues? then the caller would have the flexibility to either use what's built in or wrap their own logic?

Comment thread unstructured/ingest/connector/airtable.py Outdated
@rbiseck3 rbiseck3 force-pushed the roman/retry-source-connectors branch from 5b2df86 to 38c7809 Compare October 11, 2023 23:17
@rbiseck3 rbiseck3 force-pushed the roman/retry-source-connectors branch from 38c7809 to 3c32da2 Compare October 13, 2023 14:44
Comment thread unstructured/ingest/cli/interfaces.py Outdated
def add_cli_options(cmd: click.Command) -> None:
options = [
click.Option(
["--max-tries"],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we can call this max-retries as you had it before? I think this makes it clear it's tied to retry logic

Comment thread unstructured/ingest/cli/interfaces.py Outdated
"back off strategy if http calls fail",
),
click.Option(
["--max-time"],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

max-retry-time? (so it's clear this is specifically about retry

pass


class CliRetryStrategyConfig(RetryStrategyConfig, CliMixin):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

depending on sequencing of PRs, just want to make sure this is also captured in documentation at some point.

Copy link
Copy Markdown
Contributor

@ryannikolaidis ryannikolaidis left a comment

Choose a reason for hiding this comment

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

nit on naming otherwise lgtm

@rbiseck3 rbiseck3 force-pushed the roman/retry-source-connectors branch 3 times, most recently from 6414034 to 1713bf6 Compare October 17, 2023 12:12
@rbiseck3 rbiseck3 changed the title Roman/retry strategy refactor ingest retry strategy refactor Oct 17, 2023
@rbiseck3 rbiseck3 enabled auto-merge October 17, 2023 12:16
@rbiseck3 rbiseck3 force-pushed the roman/retry-source-connectors branch from 1713bf6 to 9fe74f4 Compare October 17, 2023 15:44
@rbiseck3 rbiseck3 added this pull request to the merge queue Oct 17, 2023
Merged via the queue into main with commit 775bfb7 Oct 17, 2023
@rbiseck3 rbiseck3 deleted the roman/retry-source-connectors branch October 17, 2023 16:44
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.

2 participants