Skip to content

Add Retry Logic to Airbyte API calls. #19693

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 9 commits into from
Nov 28, 2022
Merged

Conversation

davinchia
Copy link
Contributor

@davinchia davinchia commented Nov 22, 2022

What

Today we often see HTTP/1.1 header parser received no bytes' during syncs, especially in the Data Plane.

This PR attempts to fix this by adding naive retries.

If this works, we will explore using a more fully featured HTTP Client. I will not merge this in.

It turns out this is the best way for what we are trying to do. More details in How section.

How

Add a basic retry wrapper with the unique ability to retry for a much longer period on the last retry. This is particularly useful for us as most of our jobs are long running workflows, and the benefit of not having to restart the entire job outweighs the added wait time.

Alternative solutions I explored:

  • Switching the underlying HTTP client to a more fully featured HTTP client. E.g. Apache or OkHttp. Issues with this:
    • These clients do not support the ability to configure the retry policy we want.
    • These clients do not support the ability to inject application aware logging.
    • Most importantly, because this changes the interface, the resulting change set is big and affects many unrelated classes. I do think we eventually want to switch the underlying libraries out. However I don't think we should do this as part of OC work.
  • Exploring pairing retry libraries such as https://resilience4j.readme.io/docs with the native http clients. The main issue here is the lack of ability to configure the last retry period.

Since the hand-rolled wrapper is simple + gets the job done, my thoughts are to run with this for the time being and revisit this if additional requirements around the clients come up.

Recommended reading order

  1. AirbyteApiClient.java for implementation and AirbyteApiClientTest.java for tests.
  2. All others are usage changes.

🚨 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

  • Community member? Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
    • docs/integrations/README.md
    • airbyte-integrations/builds.md
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • If new credentials are required for use in CI, add them to GSM. Instructions.
  • /test connector=connectors/<name> command is passing
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the connector is published, connector added to connector index as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as described here
Updating a connector

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • If new credentials are required for use in CI, add them to GSM. Instructions.
  • /test connector=connectors/<name> command is passing
  • New Connector version released on Dockerhub and connector version bumped by running the /publish command described here
Connector Generator
  • Issue acceptance criteria met
  • PR name follows PR naming conventions
  • If adding a new generator, add it to the list of scaffold modules being tested
  • The generator test modules (all connectors with -scaffold in their name) have been updated with the latest scaffold by running ./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates then checking in your changes
  • Documentation which references the generator is updated as needed

Tests

Unit

Put your unit tests output here.

Integration

Put your integration tests output here.

Acceptance

Put your acceptance tests output here.

@octavia-squidington-iv octavia-squidington-iv added area/platform issues related to the platform area/worker Related to worker labels Nov 22, 2022
@davinchia davinchia temporarily deployed to more-secrets November 22, 2022 21:20 Inactive
@davinchia davinchia temporarily deployed to more-secrets November 22, 2022 21:20 Inactive
@davinchia davinchia temporarily deployed to more-secrets November 22, 2022 23:31 Inactive
@davinchia davinchia temporarily deployed to more-secrets November 22, 2022 23:31 Inactive
@davinchia
Copy link
Contributor Author

I have confirmed this fix works. See https://github.com/airbytehq/oncall/issues/1079#issuecomment-1324451000 for more info.

Going to leave this open when I explore a cleaner fix.

@davinchia davinchia changed the title Test application logic retry calls. DNM: Test application logic retry calls. Nov 24, 2022
@octavia-squidington-iv octavia-squidington-iv added the area/api Related to the api label Nov 24, 2022
@davinchia davinchia temporarily deployed to more-secrets November 24, 2022 17:18 Inactive
@davinchia davinchia temporarily deployed to more-secrets November 24, 2022 17:18 Inactive
@davinchia davinchia changed the title DNM: Test application logic retry calls. Add Retry Logic to Airbyte API calls. Nov 24, 2022
@davinchia davinchia temporarily deployed to more-secrets November 24, 2022 17:51 Inactive
@davinchia davinchia temporarily deployed to more-secrets November 24, 2022 17:51 Inactive
@davinchia davinchia temporarily deployed to more-secrets November 24, 2022 18:11 Inactive
@davinchia davinchia temporarily deployed to more-secrets November 24, 2022 18:11 Inactive
@davinchia davinchia temporarily deployed to more-secrets November 24, 2022 18:20 Inactive
@davinchia davinchia temporarily deployed to more-secrets November 24, 2022 18:20 Inactive
@davinchia davinchia marked this pull request as ready for review November 24, 2022 18:20
final JobIdRequestBody id = new JobIdRequestBody();
id.setId(Long.valueOf(jobRunConfig.getJobId()));
final var jobScope = airbyteApiClient.getJobsApi().getJobInfo(id).getJob().getConfigId();
final var jobScope = AirbyteApiClient.retryWithJitter(
() -> airbyteApiClient.getJobsApi().getJobInfo(id).getJob().getConfigId(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pmossman I feel like we can switch this to getJobInfoLight?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If so, will do in a follow up PR.

final var jobScope = airbyteApiClient.getJobsApi().getJobInfo(id).getJob().getConfigId();

final var jobScope = AirbyteApiClient.retryWithJitter(
() -> airbyteApiClient.getJobsApi().getJobInfo(id).getJob().getConfigId(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here too

@davinchia
Copy link
Contributor Author

PTAL @pmossman @xiaohansong ended up going with the hand-rolled solution for the reasons in the PR description.

Copy link
Contributor

@xiaohansong xiaohansong left a comment

Choose a reason for hiding this comment

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

Some minor comments, otherwise LGTM

saveWorkflowIdForCancellation(airbyteApiClient);
AirbyteApiClient.retryWithJitter(() -> {
saveWorkflowIdForCancellation(airbyteApiClient);
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove this return null?

Copy link
Contributor Author

@davinchia davinchia Nov 25, 2022

Choose a reason for hiding this comment

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

I looked into this and I think the alternatives are messier.

We can turn the interface into a Runnable, which doesn't expect an return value. However Runnables do not support checked exceptions, which means we would have to catch and recast the exception thrown by saveWorkflowIdForCancellation into a RTE.

Given that, I think it's simpler to keep this as is!

If you have a suggestion, I'm happy to edit this!

@davinchia davinchia temporarily deployed to more-secrets November 25, 2022 00:04 Inactive
@davinchia davinchia temporarily deployed to more-secrets November 25, 2022 00:04 Inactive
@davinchia davinchia temporarily deployed to more-secrets November 25, 2022 05:41 Inactive
@davinchia davinchia temporarily deployed to more-secrets November 25, 2022 05:41 Inactive
@davinchia davinchia temporarily deployed to more-secrets November 26, 2022 17:29 Inactive
@davinchia davinchia temporarily deployed to more-secrets November 26, 2022 17:29 Inactive
@davinchia davinchia merged commit a695b41 into master Nov 28, 2022
@davinchia davinchia deleted the davinchia/retry-client branch November 28, 2022 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api Related to the api area/platform issues related to the platform area/worker Related to worker
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants