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

Check dataset connection before migration job (and other apps) #792

Merged
merged 22 commits into from
Feb 10, 2023

Conversation

severo
Copy link
Collaborator

@severo severo commented Feb 8, 2023

Before starting the services (api, admin) and workers, we ensure the database is accessible and the assets directory (if needed) exists.

In the case of the migration job: if the database cannot be accessed, we skip the migration, to avoid blocking Helm

Fixes #763. Replaces #767. Depends on #791.

@codecov-commenter
Copy link

codecov-commenter commented Feb 8, 2023

Codecov Report

Base: 90.72% // Head: 90.66% // Decreases project coverage by -0.06% ⚠️

Coverage data is based on head (aadaa18) compared to base (f0d048e).
Patch coverage: 83.78% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #792      +/-   ##
==========================================
- Coverage   90.72%   90.66%   -0.06%     
==========================================
  Files         105      105              
  Lines        5259     5292      +33     
==========================================
+ Hits         4771     4798      +27     
- Misses        488      494       +6     
Flag Coverage Δ
jobs_mongodb_migration 80.29% <100.00%> (+0.04%) ⬆️
libs_libcommon 92.82% <94.73%> (+0.02%) ⬆️
services_admin 86.84% <70.00%> (-0.29%) ⬇️
services_api 89.27% <71.42%> (-0.23%) ⬇️
workers_datasets_based 92.82% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
libs/libcommon/src/libcommon/storage.py 95.45% <66.66%> (-4.55%) ⬇️
services/admin/src/admin/app.py 88.63% <70.00%> (-5.81%) ⬇️
services/api/src/api/app.py 90.47% <71.42%> (-3.97%) ⬇️
jobs/mongodb_migration/tests/test_resources.py 100.00% <100.00%> (ø)
libs/libcommon/src/libcommon/resources.py 95.55% <100.00%> (+1.11%) ⬆️
libs/libcommon/tests/test_resources.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@HuggingFaceDocBuilder
Copy link
Collaborator

HuggingFaceDocBuilder commented Feb 8, 2023

The documentation is not available anymore as the PR was closed or merged.

@severo severo force-pushed the check-dataset-connection-before-migration-job branch from c284964 to a334a52 Compare February 10, 2023 16:22
@severo severo force-pushed the check-dataset-connection-before-migration-job branch from a334a52 to 92948e6 Compare February 10, 2023 16:25
@severo severo marked this pull request as ready for review February 10, 2023 16:27
Base automatically changed from use-classmethod to main February 10, 2023 16:29
@severo severo force-pushed the check-dataset-connection-before-migration-job branch from 92948e6 to 4c1d030 Compare February 10, 2023 16:30
@severo severo force-pushed the check-dataset-connection-before-migration-job branch from 4c1d030 to ce2b651 Compare February 10, 2023 16:31
@severo
Copy link
Collaborator Author

severo commented Feb 10, 2023

@rtrompier this PR should fix #763.

@severo severo changed the title Check dataset connection before migration job Check dataset connection before migration job (and other apps) Feb 10, 2023
):
if cache_resource.check() is False:
logging.info(
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if it should be an info, maybe Warning since it will avoid running the migrations

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@albertvillanova albertvillanova left a comment

Choose a reason for hiding this comment

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

Some nits below...

As this function returns a boolean, maybe you could try to find a name using the third-person singular, like the pathlib does for path.exists()...

Comment on lines 38 to 44
if libraries_resource.check() is False:
raise RuntimeError("The datasets and numba libraries could not be configured. Exiting.")
if cache_resource.check() is False:
raise RuntimeError("The connection to the cache database could not be established. Exiting.")
if queue_resource.check() is False:
raise RuntimeError("The connection to the queue database could not be established. Exiting.")

Copy link
Member

Choose a reason for hiding this comment

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

The same here...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -51,6 +51,9 @@ def allocate(self):
storage_paths.add(self.numba_path)
self.storage_paths = storage_paths

def check(self) -> bool:
return True
Copy link
Member

Choose a reason for hiding this comment

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

What is the point of this function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had put check() in the base class with NotImplementedError, so I had to implement it. But it was poor design, I moved it to MongoResource, now it's more logical.

@severo
Copy link
Collaborator Author

severo commented Feb 10, 2023

As this function returns a boolean, maybe you could try to find a name using the third-person singular, like the pathlib does for path.exists()...

good advice, I'll try to remember it for the next time too

Copy link
Member

@albertvillanova albertvillanova left a comment

Choose a reason for hiding this comment

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

Thanks!

@severo
Copy link
Collaborator Author

severo commented Feb 10, 2023

Thanks for the reviews!!!

@severo severo merged commit 6666942 into main Feb 10, 2023
@severo severo deleted the check-dataset-connection-before-migration-job branch February 10, 2023 17:20
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.

Check if the database exists/is accessible in the migration job
5 participants