Skip to content
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

Modify add_license_url DAG for more specific null check #4124

Merged
merged 10 commits into from
Apr 24, 2024

Conversation

krysal
Copy link
Member

@krysal krysal commented Apr 16, 2024

Fixes

Fixes #3885 by @krysal

Description

This PR modifies the existing DAG submitted by @obulat to correct all the rows without a license_url in their meta_data field. Yesterday, I queried upstream DB and the distribution of rows to fix was the following:

openledger> SELECT license, license_version, count(identifier)
 FROM image WHERE meta_data->>'license_url' IS NULL
 GROUP BY license, license_version;
+----------+-----------------+----------+
| license  | license_version | count    |
|----------+-----------------+----------|
| by       | 2.0             | 18013988 |
| by       | 3.0             | 109      |
| by       | 4.0             | 20280    |
| by-nc    | 2.0             | 12378526 |
| by-nc    | 3.0             | 84       |
| by-nc    | 4.0             | 34596    |
| by-nc-nd | 2.0             | 23425098 |
| by-nc-nd | 3.0             | 292      |
| by-nc-nd | 4.0             | 15547    |
| by-nc-sa | 2.0             | 26487161 |
| by-nc-sa | 3.0             | 9229     |
| by-nc-sa | 4.0             | 9575     |
| by-nd    | 2.0             | 5184389  |
| by-nd    | 3.0             | 112      |
| by-nd    | 4.0             | 175      |
| by-sa    | 2.0             | 9843818  |
| by-sa    | 3.0             | 137      |
| by-sa    | 4.0             | 15819    |
| cc0      | 1.0             | 884224   |
| pdm      | 1.0             | 1452034  |
| pdm      | 4.0             | 43       |
+----------+-----------------+----------+
SELECT 21
Time: 2181.062s (36 minutes 21 seconds), executed in: 2181.030s (36 minutes 21 seconds)

This version does not interact with AWS S3; given the low number of license-version combinations, it's not necessary. Instead, if some failed pairs are found, it's notified at the end.

Testing Instructions

Spin up the catalog stack, just catalog/up, and remove the targeted field from some rows. You could try the next update statement on the sample data.

UPDATE image SET meta_data = '{"foo": "bar"}'::jsonb WHERE identifier IN (
	'd74da171-0347-435c-a32a-74a4526d3950',
	'bc4120e9-1ed3-4499-9a10-69d5bebb03e4',
	'22c54bc1-df4e-4bd7-ab19-9e649aacada1',
	'093344ca-9aa7-4f96-b40a-1fd493c41a15'
);

Then, run the dag and observe the original meta_data is preserved with the addition of the corresponding license_url.

SELECT identifier, updated_on, license, license_version, meta_data
FROM image WHERE identifier IN (
	'd74da171-0347-435c-a32a-74a4526d3950',
	'bc4120e9-1ed3-4499-9a10-69d5bebb03e4',
	'22c54bc1-df4e-4bd7-ab19-9e649aacada1',
	'093344ca-9aa7-4f96-b40a-1fd493c41a15'
)

To observe the failed pairs alert task being run, you can simply modify the license_version of one of the rows to a non-existing one with a high number. The individual mapped task for it will be skipped.

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate 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.

@krysal krysal added 🟨 priority: medium Not blocking but should be addressed soon 🧰 goal: internal improvement Improvement that benefits maintainers, not users 🧱 stack: catalog Related to the catalog and Airflow DAGs 🗄️ aspect: data Concerns the data in our catalog and/or databases labels Apr 16, 2024
@krysal krysal force-pushed the fix/license_url_null branch 4 times, most recently from a30e6e9 to 5e32387 Compare April 16, 2024 21:17
@krysal krysal marked this pull request as ready for review April 16, 2024 23:55
@krysal krysal requested review from a team as code owners April 16, 2024 23:55
Copy link

Full-stack documentation: https://docs.openverse.org/_preview/4124

Please note that GitHub pages takes a little time to deploy newly pushed code, if the links above don't work or you see old versions, wait 5 minutes and try again.

You can check the GitHub pages deployment action list to see the current status of the deployments.

Changed files 🔄:

@krysal krysal removed the request for review from fcoveram April 16, 2024 23:57
@obulat
Copy link
Contributor

obulat commented Apr 17, 2024

I am going to test this PR locally now, but wanted to leave a couple of notes about the licenses in the catalog.

I think we still have some items with null in metadata. At least, that's what I wrote in this comment: WordPress/openverse-catalog#1045 (comment). The reason for it is that the license pairs were invalid.

There's also an invalid pair here: PDM does not have a 4.0 version, only 1.0.

Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

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

The DAG runs well locally. I was surprised that the SELECT query in prod was so quick!

I would love to see more detailed reporting of the results: the list of license pairs and updated item count for each, and the same for the invalid license pair. But I don't want to block on this.

catalog/dags/maintenance/add_license_url.py Outdated Show resolved Hide resolved
select_query = dedent("""
SELECT license, license_version, count(identifier)
FROM image WHERE meta_data->>'license_url' IS NULL
GROUP BY license, license_version
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice use of GROUP BY SQL power :)

@krysal
Copy link
Member Author

krysal commented Apr 18, 2024

I think we still have some items with null in metadata.

I queried before and this is not the case anymore!

openledger> SELECT count(*) FROM image WHERE meta_data IS NULL;
+-------+
| count |
|-------|
| 0     |
+-------+
SELECT 1
Time: 2154.197s (35 minutes 54 seconds), executed in: 2154.180s (35 minutes 54 seconds)

There's also an invalid pair here: PDM does not have a 4.0 version, only 1.0.

Interesting. Currently, that pair will be skipped, but certainly, we should look to fix it 🤔 I'll create an issue for that.

I was surprised that the SELECT query in prod was so quick!

Same! That was very useful to get more information on the problem.

I would love to see more detailed reporting of the results: the list of license pairs and updated item count for each, and the same for the invalid license pair.

Admittedly, I was lazy on the final report, given that the distribution to change is specified at the beginning of the DAG, and was expecting it to return 0 as the pending after finishing 😆 Let me see if it's easy to add.

@openverse-bot
Copy link
Collaborator

Based on the medium urgency of this PR, the following reviewers are being gently reminded to review this PR:

@dhruvkb
@stacimc
This reminder is being automatically generated due to the urgency configuration.

Excluding weekend1 days, this PR was ready for review 4 day(s) ago. PRs labelled with medium urgency are expected to be reviewed within 4 weekday(s)2.

@krysal, if this PR is not ready for a review, please draft it to prevent reviewers from getting further unnecessary pings.

Footnotes

  1. Specifically, Saturday and Sunday.

  2. For the purpose of these reminders we treat Monday - Friday as weekdays. Please note that the operation that generates these reminders runs at midnight UTC on Monday - Friday. This means that depending on your timezone, you may be pinged outside of the expected range.

Copy link
Contributor

@stacimc stacimc left a comment

Choose a reason for hiding this comment

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

Worked locally for me!

@krysal krysal merged commit feb8e00 into main Apr 24, 2024
39 checks passed
@krysal krysal deleted the fix/license_url_null branch April 24, 2024 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄️ aspect: data Concerns the data in our catalog and/or databases 🧰 goal: internal improvement Improvement that benefits maintainers, not users 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: catalog Related to the catalog and Airflow DAGs
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Backfill license_url field for images where it's null in the meta_data
4 participants