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

Add catalog indexer worker #4330

Merged
merged 13 commits into from
Jun 20, 2024
Merged

Add catalog indexer worker #4330

merged 13 commits into from
Jun 20, 2024

Conversation

stacimc
Copy link
Collaborator

@stacimc stacimc commented May 14, 2024

Fixes

Fixes #4147 by @stacimc

Description

This PR adds the catalog indexer worker. It does not actually connect to it in the data refresh yet.

Some unit tests are added, but because of the nature of the worker the bulk of the tests will be integration tests modeled after the existing ingestion server integration tests. I was able to get these mostly working locally but pulled them out of this PR as I think it will make more sense to add the integration tests once the data refresh is fully implemented, possibly reusing issue #4340.

Almost all of this code is just a refactor of existing code. Where possible I've noted when files are almost entirely copied over from the ingestion server.

Note that the service is called catalog_indexer_worker to distinguish it from the existing indexer_worker that belongs to the ingestion server, which we must keep around for now.

Testing Instructions

just build && just up

Use elasticvue to Delete All Documents from one of your existing indices. I used audio-init-filtered. The index should now have 0 documents.

Now run just catalog/shell, and you should be able to curl the indexer worker.

# Replace the target_index name if you don't have audio-init-filtered
# Note the start_id/end_id we're using, to make it reindex only 100 records
curl -X POST -d '{"model_name": "audio", "table_name": "audio", "start_id": 0, "end_id": 100, "target_index": "audio-init-filtered"}' -H "Content-Type: application/json" 'http://catalog_indexer_worker:8003/task'

You should get back a response like:

{
  "message": "Successfully scheduled task.", 
  "task_id": "adbec2cbc93a4c2f895caf12ede3eb88", 
  "status_check": "http://catalog_indexer_worker:8003/task/adbec2cbc93a4c2f895caf12ede3eb88"
}

Now curl the status_check endpoint that was just returned:

curl 'http://catalog_indexer_worker:8003/task/adbec2cbc93a4c2f895caf12ede3eb88'

And you should see something like:

{
  "task_id": "adbec2cbc93a4c2f895caf12ede3eb88",
  "active": false,
  "model": "audio",
  "target_index": "audio-init-filtered",
  "progress": 100.0,
  "start_time": "2024-05-14 21:27:54.437745",
  "finish_time": "2024-05-14 21:27:54.575137",
  "error": false
}

In elasticvue, you should now see 100 docs in your target index.

If you used a filtered index, you can now query the API (http://localhost:50281/v1/audio) and see that the results are returned as expected. ⚠️ Important: In Elasticvue you must first refresh the index to make the documents available. Then you can inspect them in Elasticvue, or check the API. This will be handled by the DAG later.

You can also try running the just commands for the indexer worker.

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 (just catalog/generate-docs for catalog
    PRs) or the media properties generator (just catalog/generate-docs media-props
    for the catalog or 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.

@stacimc stacimc added 🟨 priority: medium Not blocking but should be addressed soon 🌟 goal: addition Addition of new feature 💻 aspect: code Concerns the software code in the repository 🧱 stack: api Related to the Django API 🧱 stack: ingestion server Related to the ingestion/data refresh server 🧱 stack: catalog Related to the catalog and Airflow DAGs labels May 14, 2024
@stacimc stacimc self-assigned this May 14, 2024
@stacimc stacimc mentioned this pull request May 28, 2024
13 tasks
@@ -0,0 +1,71 @@
"""
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copied from ingestion_server without changes to logic.

@@ -0,0 +1,58 @@
import logging as log
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copied from ingestion_server without changes to logic.

@@ -0,0 +1,335 @@
"""
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copied from ingestion_server without changes to logic. This provides the mappings from db record to ES document.

@@ -0,0 +1,51 @@
import logging as log
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copied from ingestion_server without changes to logic.

@stacimc stacimc force-pushed the add/catalog-indexer-worker branch from 12a58df to a331cb3 Compare June 14, 2024 22:51
@openverse-bot openverse-bot added 🧱 stack: analytics Related to the analytics setup 🧱 stack: mgmt Related to repo management and automations labels Jun 14, 2024
@stacimc stacimc marked this pull request as ready for review June 14, 2024 23:20
@stacimc stacimc requested review from a team as code owners June 14, 2024 23:20
@stacimc stacimc requested a review from a team as a code owner June 14, 2024 23:20
@sarayourfriend
Copy link
Collaborator

@stacimc I've opened a PR targeting this branch that switches Pipenv out for PDM, add a test recipe to the new justfile, and to run indexer worker tests in CI.

#4497

I didn't see a separate issue for implanting CI for the new project, so I wasn't sure where they would go, if not in this PR; but if you want to keep it as a fast-follow, no worries, it doesn't need to be merged into this PR, can be on its own if you'd prefer.

Copy link
Collaborator

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

This LGTM! On #4497 I can run just indexer_worker/test and all the tests pass. On this branch, just indexer_worker/test-local also passes after running through the local venv installation.

I have not spent much time reviewing the code line by line given how much of it is copy/paste. That's fine by me, as well as the decision to push tests off into integration style tests in later issues 👍

Copy link
Collaborator

@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 great! I was able to test this locally and it worked as expected. A couple of comments here but nothing blocking, if anything we can make issues going forward for addressing them as non-urgent follow ups (and possibly good first issues!).

indexer_worker/indexer_worker/tasks.py Outdated Show resolved Hide resolved
return None
return str(datetime.datetime.utcfromtimestamp(timestamp))

task_info = self.tasks[task_id]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this is something we can make an issue for, particularly given this might be longer-term code now: it would be great if this could be a dataclass or namedtuple, rather than a dictionary! And then we could have some typing around the self.tasks dictionary as well, which would be neat 😄

Copy link
Collaborator Author

@stacimc stacimc Jun 20, 2024

Choose a reason for hiding this comment

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

Of course! Sounds like a good first issue as well. Issue: #4534 👍

@stacimc stacimc merged commit 417ba9c into main Jun 20, 2024
49 checks passed
@stacimc stacimc deleted the add/catalog-indexer-worker branch June 20, 2024 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🌟 goal: addition Addition of new feature 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: analytics Related to the analytics setup 🧱 stack: api Related to the Django API 🧱 stack: catalog Related to the catalog and Airflow DAGs 🧱 stack: ingestion server Related to the ingestion/data refresh server 🧱 stack: mgmt Related to repo management and automations
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Implement new catalog indexer-worker
4 participants