-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add dataset_status='normal|blocked' to job metrics (#3008)
* add dataset_status='normal|blocked' to job metrics * add tests + rename collection constant * fix test * Update jobs/cache_maintenance/src/cache_maintenance/queue_metrics.py Co-authored-by: Andrea Francis Soria Jimenez <[email protected]> * Update jobs/mongodb_migration/tests/migrations/test_20240731143600_queue_add_dataset_status_to_queue_metrics.py Co-authored-by: Andrea Francis Soria Jimenez <[email protected]> --------- Co-authored-by: Andrea Francis Soria Jimenez <[email protected]>
- Loading branch information
1 parent
64920b3
commit 9b08fd7
Showing
12 changed files
with
171 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...mongodb_migration/migrations/_20240731143600_queue_add_dataset_status_to_queue_metrics.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright 2024 The HuggingFace Authors. | ||
|
||
import logging | ||
|
||
from libcommon.constants import QUEUE_MONGOENGINE_ALIAS, TYPE_STATUS_AND_DATASET_STATUS_JOB_COUNTS_COLLECTION | ||
from libcommon.queue.dataset_blockages import DATASET_STATUS_NORMAL | ||
from libcommon.queue.metrics import JobTotalMetricDocument | ||
from mongoengine.connection import get_db | ||
|
||
from mongodb_migration.check import check_documents | ||
from mongodb_migration.migration import Migration | ||
|
||
|
||
# connection already occurred in the main.py (caveat: we use globals) | ||
class MigrationAddDatasetStatusToQueueMetrics(Migration): | ||
def up(self) -> None: | ||
# See https://docs.mongoengine.org/guide/migration.html#example-1-addition-of-a-field | ||
logging.info("If missing, add the 'dataset_status' field with the default value 'normal' to the jobs metrics") | ||
db = get_db(QUEUE_MONGOENGINE_ALIAS) | ||
db[TYPE_STATUS_AND_DATASET_STATUS_JOB_COUNTS_COLLECTION].update_many( | ||
{"dataset_status": {"$exists": False}}, {"$set": {"dataset_status": DATASET_STATUS_NORMAL}} | ||
) | ||
|
||
def down(self) -> None: | ||
logging.info("Remove the 'dataset_status' field from all the jobs metrics") | ||
db = get_db(QUEUE_MONGOENGINE_ALIAS) | ||
db[TYPE_STATUS_AND_DATASET_STATUS_JOB_COUNTS_COLLECTION].update_many({}, {"$unset": {"dataset_status": ""}}) | ||
|
||
def validate(self) -> None: | ||
logging.info("Ensure that a random selection of jobs metrics have the 'dataset_status' field") | ||
|
||
check_documents(DocCls=JobTotalMetricDocument, sample_size=10) |
51 changes: 51 additions & 0 deletions
51
...gration/tests/migrations/test_20240731143600_queue_add_dataset_status_to_queue_metrics.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright 2024 The HuggingFace Authors. | ||
|
||
|
||
from libcommon.constants import QUEUE_MONGOENGINE_ALIAS, TYPE_STATUS_AND_DATASET_STATUS_JOB_COUNTS_COLLECTION | ||
from libcommon.queue.dataset_blockages import DATASET_STATUS_BLOCKED, DATASET_STATUS_NORMAL | ||
from libcommon.resources import MongoResource | ||
from mongoengine.connection import get_db | ||
|
||
from mongodb_migration.migrations._20240731143600_queue_add_dataset_status_to_queue_metrics import ( | ||
MigrationAddDatasetStatusToQueueMetrics, | ||
) | ||
|
||
|
||
def test_queue_add_dataset_status_to_queue_metrics(mongo_host: str) -> None: | ||
with MongoResource( | ||
database="test_queue_add_dataset_status_to_queue_metrics", | ||
host=mongo_host, | ||
mongoengine_alias=QUEUE_MONGOENGINE_ALIAS, | ||
): | ||
db = get_db(QUEUE_MONGOENGINE_ALIAS) | ||
db[TYPE_STATUS_AND_DATASET_STATUS_JOB_COUNTS_COLLECTION].insert_many( | ||
[ | ||
{ | ||
"job_type": "job_type1", | ||
"status": "waiting", | ||
}, | ||
{"job_type": "job_type2", "status": "waiting", "dataset_status": DATASET_STATUS_BLOCKED}, | ||
] | ||
) | ||
|
||
migration = MigrationAddDatasetStatusToQueueMetrics( | ||
version="20240731143600", description="add 'dataset_status' field to jobs metrics" | ||
) | ||
migration.up() | ||
|
||
result = list(db[TYPE_STATUS_AND_DATASET_STATUS_JOB_COUNTS_COLLECTION].find({"job_type": "job_type1"})) | ||
assert len(result) == 1 | ||
assert result[0]["dataset_status"] == DATASET_STATUS_NORMAL | ||
|
||
result = list(db[TYPE_STATUS_AND_DATASET_STATUS_JOB_COUNTS_COLLECTION].find({"job_type": "job_type2"})) | ||
assert len(result) == 1 | ||
assert result[0]["dataset_status"] == DATASET_STATUS_BLOCKED | ||
|
||
migration.down() | ||
result = list(db[TYPE_STATUS_AND_DATASET_STATUS_JOB_COUNTS_COLLECTION].find()) | ||
assert len(result) == 2 | ||
assert "dataset_status" not in result[0] | ||
assert "dataset_status" not in result[1] | ||
|
||
db[TYPE_STATUS_AND_DATASET_STATUS_JOB_COUNTS_COLLECTION].drop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.