Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Discard audio file when preview 404s fetching filesize #973

Merged
merged 2 commits into from
Feb 6, 2023

Conversation

stacimc
Copy link
Contributor

@stacimc stacimc commented Jan 25, 2023

Fixes

Fixes WordPress/openverse#1321 by @AetherUnbound
Fixes WordPress/openverse#1578 by @AetherUnbound

Description

  • Updates Freesound to use the new DelayedRequester::head call
  • Adds handling for an edge case when we get a 404 on a preview URL, which we use for getting filesize information. Since getting a 404 on the preview means the record is not playable on our frontend, we return None early and skip ingestion for these records.

Testing Instructions

Check out the new unit tests.

Run the Freesound DAG locally and verify that it still works.

One way to force a 404 for testing is to update the _get_audio_file_size method to append some nonsense to the end of the URL before making the request:

@retry(flaky_exceptions, tries=3, delay=1, backoff=2)
    def _get_audio_file_size(self, url):
        # Force a 404 by breaking the url 
        url = url + 'foo'

        response = self.delayed_requester.head(url)
        ...

Then re-run the DAG. You should see a lot of logs that look like this:

{requester.py:78} WARNING - Unable to request URL: https://cdn.freesound.org/previews/664/664719_14565529-hq.mp3foo  Status code: 404

Manually Mark Success the pull_data step once you have verified these logs, or else it will try and fail for all records. Then verify in report_load_completion that no records were actually ingested.

Checklist

  • My pull request has a descriptive title (not a vague title like
    Update index.md).
  • My pull request targets the default branch of the repository (main) or
    a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible
    errors.
  • I ran the DAG documentation generator (if 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.

@stacimc stacimc added bug Something isn't working 🟧 priority: high Stalls work on the project or its dependents 🛠 goal: fix Bug fix 💻 aspect: code Concerns the software code in the repository labels Jan 25, 2023
@stacimc stacimc requested a review from a team as a code owner January 25, 2023 23:55
@stacimc stacimc self-assigned this Jan 25, 2023
@stacimc stacimc requested review from krysal and obulat January 25, 2023 23:55
Comment on lines 179 to 182
TODO(obulat): move filesize detection to the polite crawler
"""
return int(requests.head(url).headers["content-length"])
Copy link
Member

Choose a reason for hiding this comment

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

It seems like the TODO task is done 😄 and we can remove the comment 👏
Aside from that, LGTM!

Copy link
Contributor

Choose a reason for hiding this comment

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

Well not quite 😅 Since we don't have the polite crawler running at all. But I agree, we can remove the comment 🙂

Copy link
Contributor

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

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

This looks good! One important thing this changes - we stop processing if we're unable to find the filesize, regardless of whether or not its because the preview 404'd or if it was a different reason that prevented us from doing so. I think that's fine, but I wanted to make it explicit that this is our new approach for this DAG since we're not differentiating on a 404 specifically (and I think it'd be particularly difficult to do with the delayed requester 😅).

Comment on lines 179 to 182
TODO(obulat): move filesize detection to the polite crawler
"""
return int(requests.head(url).headers["content-length"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Well not quite 😅 Since we don't have the polite crawler running at all. But I agree, we can remove the comment 🙂

@krysal
Copy link
Member

krysal commented Feb 6, 2023

@AetherUnbound Oh, so I see the other cases you mentioned in code comments:

Freesound can be finicky, so we want to retry it a few times on
these conditions:
* SSLError - 'EOF occurred in violation of protocol (_ssl.c:1129)'
* ConnectionError - '[Errno 113] No route to host'

But what kind of handling was you expecting here to happen? I think we already do the retry with the use of the delayed requester (that I confused with the crawler thing, my bad!) and don't see what else can be done in the different situations, other than discarding the track.

@stacimc stacimc merged commit 6c35cab into main Feb 6, 2023
@stacimc stacimc deleted the fix/freesound-handle-preview-404s branch February 6, 2023 22:51
@AetherUnbound
Copy link
Contributor

That's a good point of clarification @krysal, there's quite a few things happening with this particular request! In the cases you point out, the SSLError and ConnectionError, those are transient errors that occurred when making the request to Freesound (added in #330 & #413 respectively). We do have retries on the requester, but those are only for cases where the connection was able to be made successfully (albeit returning a non 200 response or an error in the response JSON). Since the errors we were seeing with Freesound were raising exceptions even within that block, we added the outer @retry wrappers to retry those exceptions. Freesound is the only provider this happens with, though if we begin to see it happening consistently with other providers, perhaps it would make sense to retry all errors initially within the requester rather than only successful connection requests.

The point with my comment was merely that it'd be possible for Freesound to return a 500 (or some other non-200 error code) consistently for all retries, but still potentially reference a valid record. In this case we'd discard the track entirely since the preview was not available (at the time). Previously this would raise an exception and potentially allow us to retry, now in that case the ingester will just move on. I think it's a very small edge case that we're not likely to encounter, but I wanted to point it out nonetheless 🙂

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository bug Something isn't working 🛠 goal: fix Bug fix 🟧 priority: high Stalls work on the project or its dependents
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use HEAD request in Freesound ingester for file size request Freesound preview for valid file could 404
3 participants