openverse icon indicating copy to clipboard operation
openverse copied to clipboard

Replace retry with backoff, add backoff to all Freesound requests

Open AetherUnbound opened this issue 6 months ago • 1 comments

Fixes

Fixes #4594 by @stacimc

Description

[!WARNING] This should not be merged until a deployment can be made immediately after, since it introduces new dependencies.

This PR makes two major changes:

  • Replaces the retry with backoff
  • Adds an exponential backoff to all requests made to Freesound during ingestion

The latter change is relatively straightforward: we encounter tons of exceptions during the Freesound ingestion process that seem to be transient and ultimately get resolved when checked later. However this causes significant disruptions in the execution of the DAG itself, since it often requires that maintainers restart the DAG with SKIP_INGESTION_ERRORS enabled for it. This change allows requests to be retried with an exponential backoff up to a max time (2 minutes for now) if they match the HTTP codes 400 or 503. On all other codes, the exception is raised and retries (outside of the normal ones for the DelayedRequester) are not attempted.

The former change is motivated by the above. retry is a Python library that hasn't been updated since 2016, and only supports fairly basic retry conditions. backoff on the other hand has been updated as recently as 2022 and supports much more complexity in retry conditions. With the above case, we only wanted to retry on HTTPErrors with a specific return code; that was not possible with retry but is now possible with backoff. This should give us some additional flexibility moving forward too!

Testing Instructions

I added new tests specifically for the conditions mentioned above. You can also run the freesound_workflow DAG locally to ensure everything behaves normally (and maybe encounter one of the above cases if you're lucky!).

Checklist

  • [x] My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • [x] My pull request targets the default branch of the repository (main) or a parent feature branch.
  • [x] My commit messages follow best practices.
  • [x] My code follows the established code style of the repository.
  • [x] I added or updated tests for the changes I made (if applicable).
  • [x] I added or updated documentation (if applicable).
  • [x] I tried running the project locally and verified that there are no visible errors.
  • [ ] I ran the DAG documentation generator (ov just catalog/generate-docs for catalog PRs) or the media properties generator (ov just catalog/generate-docs media-props for the catalog or ov just api/generate-docs for the API) where applicable.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

AetherUnbound avatar Jul 26 '24 20:07 AetherUnbound