forked from mlflow/mlflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created command context provider to set job group ID as part of run t…
…ags (mlflow#4521)
- Loading branch information
1 parent
e808a38
commit bc86f1d
Showing
5 changed files
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from mlflow.tracking.context.abstract_context import RunContextProvider | ||
from mlflow.utils import databricks_utils | ||
from mlflow.utils.mlflow_tags import MLFLOW_DATABRICKS_NOTEBOOK_COMMAND_ID | ||
|
||
|
||
class DatabricksCommandRunContext(RunContextProvider): | ||
def in_context(self): | ||
return databricks_utils.get_job_group_id() is not None | ||
|
||
def tags(self): | ||
job_group_id = databricks_utils.get_job_group_id() | ||
tags = {} | ||
if job_group_id is not None: | ||
tags[MLFLOW_DATABRICKS_NOTEBOOK_COMMAND_ID] = job_group_id | ||
return tags |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from unittest import mock | ||
|
||
from mlflow.utils.mlflow_tags import MLFLOW_DATABRICKS_NOTEBOOK_COMMAND_ID | ||
from mlflow.tracking.context.databricks_command_context import DatabricksCommandRunContext | ||
|
||
|
||
def test_databricks_command_run_context_in_context(): | ||
with mock.patch("mlflow.utils.databricks_utils.get_job_group_id", return_value="1"): | ||
assert DatabricksCommandRunContext().in_context() | ||
|
||
|
||
def test_databricks_command_run_context_tags(): | ||
with mock.patch("mlflow.utils.databricks_utils.get_job_group_id") as job_group_id_mock: | ||
assert DatabricksCommandRunContext().tags() == { | ||
MLFLOW_DATABRICKS_NOTEBOOK_COMMAND_ID: job_group_id_mock.return_value | ||
} | ||
|
||
|
||
def test_databricks_command_run_context_tags_nones(): | ||
with mock.patch("mlflow.utils.databricks_utils.get_job_group_id", return_value=None): | ||
assert DatabricksCommandRunContext().tags() == {} |