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

Upload task worker results to Backend API #22

Merged
merged 13 commits into from
Jul 25, 2024
Merged

Upload task worker results to Backend API #22

merged 13 commits into from
Jul 25, 2024

Conversation

elfkuzco
Copy link
Collaborator

@elfkuzco elfkuzco commented Jul 8, 2024

Rationale

Upload results from task worker to Backend API

Changes

  • move sys.exit calls from cli modules to entrypoint.py
  • add Location model to represent available test locations
  • country_code in Test model now means the test location and not necessarily the country the mirror is located
  • add mirror_url to Test which manager uses to build test file URL for the mirror
  • fetch list of test locations from Mullvad API
  • add update-locations sub-command to update the list of test locations
  • scheduler checks if there are any test locations in db before starting, attempts to create if none exist
  • create test entries in all the available location for each mirror that a worker is responsible for.
  • merge metrics results from task-worker with output of healthcheck (which contains ip data)
  • upload results to backend API

This was linked to issues Jul 8, 2024
@codecov-commenter
Copy link

codecov-commenter commented Jul 8, 2024

Codecov Report

Attention: Patch coverage is 48.82629% with 109 lines in your changes missing coverage. Please review.

Project coverage is 67.79%. Comparing base (0776842) to head (ede4da7).

Files Patch % Lines
backend/src/mirrors_qa_backend/entrypoint.py 0.00% 33 Missing ⚠️
backend/src/mirrors_qa_backend/locations.py 0.00% 32 Missing ⚠️
backend/src/mirrors_qa_backend/cli/scheduler.py 0.00% 14 Missing ⚠️
backend/src/mirrors_qa_backend/cli/locations.py 0.00% 7 Missing ⚠️
backend/src/mirrors_qa_backend/country.py 44.44% 5 Missing ⚠️
backend/src/mirrors_qa_backend/db/mirrors.py 33.33% 4 Missing ⚠️
backend/src/mirrors_qa_backend/db/worker.py 80.00% 2 Missing and 1 partial ⚠️
backend/src/mirrors_qa_backend/cli/mirrors.py 0.00% 2 Missing ⚠️
backend/src/mirrors_qa_backend/cli/worker.py 77.77% 2 Missing ⚠️
backend/src/mirrors_qa_backend/extract.py 50.00% 2 Missing ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #22      +/-   ##
==========================================
- Coverage   69.62%   67.79%   -1.83%     
==========================================
  Files          27       31       +4     
  Lines         711      829     +118     
  Branches       64       72       +8     
==========================================
+ Hits          495      562      +67     
- Misses        202      257      +55     
+ Partials       14       10       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@elfkuzco elfkuzco requested a review from rgaudin July 8, 2024 17:22
@elfkuzco
Copy link
Collaborator Author

New changes

  • Set up a many-to-many relationship between worker and mirror country. Thus, a worker can be responsible for testing many mirrors in a country and a country can be tested by many workers.
  • When --countries argument is omitted, all available mirror countries are assigned to the worker being created/updated
  • fetch all the available countries from db when no country codes are supplied by the caller
  • add update-worker subcommand to update the list of countries a worker is responsible for

Copy link
Member

@rgaudin rgaudin left a comment

Choose a reason for hiding this comment

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

Thank you, this is very good. I couldn't test it due to lack of time but am looking forward to it.

That said, more docstrings would be welcome, especially in dedicated modules. It's not always clear what those functions are used for.

Now the main issue I have:

Sorry for the lack of reply on Slack ; and thank you for going through with your plan on this Location change.
I think this contradicts what we decided earlier and it removes a lot of flexibility.
If I understand correctly, the backend is now querying mullvad for a list of countries to test from.
This create a dependency to mullvad at the backend level that we don't want. We want to be able to easily switch VPN providers, use none or even combine them.
That's why we want the worker to expose its capabilities. One worker could have mullvad (our choice) and use the API or a listig of local config files to inform the backend of whats possible for it. Another worker could have no VPN and use its direct ISP to test some countries (we dont support this ATM, not a priority), another worker from someone else could use another wireguard-compatible VPN provider (we dont support this neither ATM, not prio either).
What's important is that we keep this door open by keeping worker-related details on the worker and not moving it to the backend.

With that in mind, I dont see the advantage of having a Location table. Countries for test creation would be dynamic from what's currently available (from recently-seen workers)

dev/docker-compose.yaml Outdated Show resolved Hide resolved
backend/src/mirrors_qa_backend/extract.py Outdated Show resolved Hide resolved
backend/src/mirrors_qa_backend/country.py Outdated Show resolved Hide resolved
backend/src/mirrors_qa_backend/cli/scheduler.py Outdated Show resolved Hide resolved
backend/src/mirrors_qa_backend/locations.py Outdated Show resolved Hide resolved
worker/task/src/mirrors_qa_task/settings.py Outdated Show resolved Hide resolved
worker/task/src/mirrors_qa_task/worker.py Outdated Show resolved Hide resolved
worker/task/src/mirrors_qa_task/worker.py Outdated Show resolved Hide resolved
worker/task/src/mirrors_qa_task/settings.py Outdated Show resolved Hide resolved
@elfkuzco elfkuzco requested a review from rgaudin July 17, 2024 05:48
Copy link
Member

@rgaudin rgaudin left a comment

Choose a reason for hiding this comment

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

Let's merge this.
Please check and maybe apply the minor wording suggestions and merge. We'll deploy it.



def create_worker(worker_id: str, private_key_data: bytes, country_codes: list[str]):
def get_country_data(*country_codes: str) -> dict[str, str]:
Copy link
Member

Choose a reason for hiding this comment

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

That's a weird API. Any reason to change from single list[str] ?



def create_worker(worker_id: str, private_key_data: bytes, country_codes: list[str]):
def get_country_data(*country_codes: str) -> dict[str, str]:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def get_country_data(*country_codes: str) -> dict[str, str]:
def get_country_mapping(*country_codes: str) -> dict[str, str]:

Clearer than data which is very vague

def create_worker(worker_id: str, private_key_data: bytes, country_codes: list[str]):
"""Create a worker in the DB.

Assigns the countries for a worker to run tests from.
Copy link
Member

Choose a reason for hiding this comment

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

This is not clear enough. Maybe renaming to initial_country_codes would help

def update_worker(worker_id: str, country_codes: list[str]):
"""Update worker's data.

Updates the ountries for a worker to run tests from.
Copy link
Member

Choose a reason for hiding this comment

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

typo

You see you have a duplicated block to assign countries to a worker.
Given this is only useful for tests, maybe the create and update methods should not include it
and the cli command should call a new method after create/update instead. WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay. Makes sense.

@@ -67,6 +69,7 @@ services:
- BACKEND_API_URI=http://backend
- SLEEP_DURATION=5m
- TASK_WORKER_IMAGE=mirrors-qa-task-worker
- TEST_FILE_PATH=/zim/wikipedia/wikipedia_guw_all_nopic_2023-02.zim
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- TEST_FILE_PATH=/zim/wikipedia/wikipedia_guw_all_nopic_2023-02.zim
- TEST_FILE_PATH=/zim/wikipedia/speedtest_en_blob-mini_2024-05.zim

@elfkuzco elfkuzco merged commit 8e7ad26 into main Jul 25, 2024
4 checks passed
@elfkuzco elfkuzco deleted the task-worker branch July 25, 2024 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tester worker Worker manager
3 participants