-
Notifications
You must be signed in to change notification settings - Fork 96
Add and populate UCX workflow_runs
table
#2754
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
Merged
Merged
Changes from 58 commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
69ddb8f
Add history install
JCZuurmond 02d8a30
Add history install to `WorkspaceContext`
JCZuurmond 26314ea
Run history installation in create UCX catalog
JCZuurmond 786f097
Fix test
JCZuurmond 0180114
Add unit test for creating UCX history schema and table
JCZuurmond 1e7cdac
Test history installation to create history schema
JCZuurmond 50fb6e5
Format
JCZuurmond a3cd1c5
Create UCX catalog on `MockWorkspaceContext`
JCZuurmond 60389b5
Remove `Record` data class and table creation
JCZuurmond 8aeba40
Make test more robust
JCZuurmond 5161074
Use `SchemaDeployer` to deploy schema
JCZuurmond 4fe1de6
Add `WorkflowRun` dataclass
JCZuurmond 11c3cb9
Make test more robust
JCZuurmond 1ad8bb4
Create `workflow_runs` table
JCZuurmond 68145f9
Rename `HistoryInstallation` to `ProgressTrackingInstaller`
JCZuurmond 9c08d39
Rename progress tracking schem to 'multiworkspace'
JCZuurmond 2f0e019
Move WorkflowRun to separate module
JCZuurmond 302fc1d
Add workflow run recorder
JCZuurmond 8054949
Add start time to workflow
JCZuurmond c58d9ed
Expect start time on record
JCZuurmond af119bb
Add attempt to workflow run
JCZuurmond 01b438f
Add job name and start time to task parameters
JCZuurmond 1c9b31d
Add `WorkflowRunRecorder` to `RuntimeContext`
JCZuurmond 48a1a86
Expect workflow start time on initialisation
JCZuurmond c7d8dff
Record workflow run
JCZuurmond f967194
Add record workflow run task to migration progress workflow
JCZuurmond b84e60a
Format
JCZuurmond 9c25c06
Fix reference to catalog
JCZuurmond fdb643d
Fix TODO
JCZuurmond 34d44e5
Remove start time on Workflow
JCZuurmond 6cf4c97
Record UCX internal workflow name
JCZuurmond 097727c
Remove job name from job parameters
JCZuurmond cfb44ad
Remove WorkflowRun.status
JCZuurmond 4c8242c
Add missing UCX catalog parameter
JCZuurmond 4721364
Test progress tracking installer creates workflow runs table
JCZuurmond e249dae
Log when workflow run table is not found
JCZuurmond 01f207a
Test workflow run recorder records a record
JCZuurmond ea672e1
Make finished at timestamp more precise
JCZuurmond ee194ea
Fix UNKNOWN typo
JCZuurmond c60cc31
Test workflow run values
JCZuurmond 34975bf
Use non-escaping characters in UCX test catalog
JCZuurmond 2d83096
Test workflow runs is populated in the during real migration progress
JCZuurmond da602c9
Use workflow from named parameters at init
JCZuurmond 950d2f0
Add workspace id as task parameter
JCZuurmond 4be9454
Pass new parameters to main
JCZuurmond 08aef94
Remove WorkflowRuns.run_as
JCZuurmond d33986c
Get workspace id from job parameters
JCZuurmond 44f5f66
Set test local ucx catalog on installation context config
JCZuurmond 965a8fc
Rename progress tracking installer to installation
JCZuurmond e4e84fc
Add ProgressTrackingInstallation to MockInstallationContext
JCZuurmond 7070bba
Format
JCZuurmond fe943a0
Add unit test for workflow runs
JCZuurmond 64d8e43
Be saver with finished at test
JCZuurmond ec2aada
Format README
JCZuurmond 3280e85
Explain workflow runs in the README
JCZuurmond b3146b1
Fix `workflow_start_time` should be `start_time`
JCZuurmond 9502991
Format
JCZuurmond 57b7d8c
Get workspace id from workspace client
JCZuurmond c8de2c9
Fix typo's
JCZuurmond 32c1d5e
Add type hint for `WorkflowRunRecorder`
JCZuurmond 931dfeb
Improve comment
JCZuurmond 92fb2fb
Improve docstring
JCZuurmond 5adfc6a
Remove redundant argument
JCZuurmond b3f9be2
Add assert message
JCZuurmond d127cec
Get test workspace id from workspace client
JCZuurmond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,22 @@ | ||
import logging | ||
|
||
from databricks.labs.lsql.backends import SqlBackend | ||
from databricks.labs.lsql.deployment import SchemaDeployer | ||
from databricks.labs.ucx.progress.workflow_runs import WorkflowRun | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ProgressTrackingInstallation: | ||
"""Install resources for UCX's progress tracking.""" | ||
|
||
_SCHEMA = "multiworkspace" | ||
|
||
def __init__(self, sql_backend: SqlBackend, ucx_catalog: str) -> None: | ||
# `mod` is required parameter, but it's not used in this context. | ||
self._schema_deployer = SchemaDeployer(sql_backend, self._SCHEMA, mod=None, catalog=ucx_catalog) | ||
JCZuurmond marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def run(self) -> None: | ||
self._schema_deployer.deploy_schema() | ||
self._schema_deployer.deploy_table("workflow_runs", WorkflowRun) | ||
logger.info("Installation completed successfully!") |
This file contains hidden or 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,79 @@ | ||
import datetime as dt | ||
import logging | ||
from dataclasses import dataclass | ||
|
||
from databricks.labs.lsql.backends import SqlBackend | ||
from databricks.sdk.errors import NotFound | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@dataclass(frozen=True, kw_only=True) | ||
class WorkflowRun: | ||
started_at: dt.datetime | ||
"""The timestamp of the workflow run start.""" | ||
|
||
finished_at: dt.datetime | ||
"""The timestamp of the workflow run end.""" | ||
JCZuurmond marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
workspace_id: int | ||
"""The workspace id in which the workflow ran.""" | ||
|
||
workflow_name: str | ||
"""The workflow name that ran.""" | ||
|
||
workflow_id: int | ||
""""The workflow id of the workflow that ran.""" | ||
|
||
workflow_run_id: int | ||
"""The workflow run id.""" | ||
|
||
workflow_run_attempt: int | ||
"""The workflow run attempt.""" | ||
|
||
JCZuurmond marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
class WorkflowRunRecorder: | ||
"""Record workflow runs in a database.""" | ||
|
||
def __init__( | ||
self, | ||
sql_backend: SqlBackend, | ||
ucx_catalog: str, | ||
*, | ||
workspace_id: int, | ||
workflow_name: str, | ||
workflow_id: int, | ||
workflow_run_id: int, | ||
workflow_run_attempt: int, | ||
workflow_start_time: str, | ||
): | ||
self._sql_backend = sql_backend | ||
self._full_table_name = f"{ucx_catalog}.multiworkspace.workflow_runs" | ||
self._workspace_id = workspace_id | ||
self._workflow_name = workflow_name | ||
self._workflow_start_time = workflow_start_time | ||
self._workflow_id = workflow_id | ||
self._workflow_run_id = workflow_run_id | ||
self._workflow_run_attempt = workflow_run_attempt | ||
|
||
def record(self) -> None: | ||
"""Record a workflow run in the database.""" | ||
workflow_run = WorkflowRun( | ||
started_at=dt.datetime.fromisoformat(self._workflow_start_time), | ||
finished_at=dt.datetime.now(tz=dt.timezone.utc).replace(microsecond=0), | ||
workspace_id=self._workspace_id, | ||
workflow_name=self._workflow_name, | ||
workflow_id=self._workflow_id, | ||
workflow_run_id=self._workflow_run_id, | ||
workflow_run_attempt=self._workflow_run_attempt, | ||
) | ||
try: | ||
self._sql_backend.save_table( | ||
self._full_table_name, | ||
[workflow_run], | ||
WorkflowRun, | ||
mode="append", | ||
) | ||
except NotFound as e: | ||
logger.error(f"Workflow run table not found: {self._full_table_name}", exc_info=e) | ||
JCZuurmond marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 hidden or 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 hidden or 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,7 @@ | ||
def test_progress_tracking_installer_creates_workflow_runs_table(az_cli_ctx) -> None: | ||
az_cli_ctx.progress_tracking_installation.run() | ||
query = ( | ||
f"SELECT 1 FROM tables WHERE table_catalog = '{az_cli_ctx.config.ucx_catalog}' " | ||
"AND table_schema = 'multiworkspace' AND table_name = 'workflow_runs'" | ||
) | ||
assert any(az_cli_ctx.sql_backend.fetch(query, catalog="system", schema="information_schema")) |
This file contains hidden or 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,30 @@ | ||
import datetime as dt | ||
|
||
|
||
def test_workflow_run_recorder_records_workflow_run(installation_ctx) -> None: | ||
"""Ensure that the workflow run recorder records a workflow run""" | ||
start_time = dt.datetime.now(tz=dt.timezone.utc).replace(microsecond=0) | ||
named_parameters = { | ||
"workspace_id": 123456789, | ||
"workflow": "test", | ||
"job_id": "123", | ||
"parent_run_id": "456", | ||
"start_time": start_time.isoformat(), | ||
} | ||
ctx = installation_ctx.replace(named_parameters=named_parameters) | ||
ctx.progress_tracking_installation.run() | ||
select_workflow_runs_query = f"SELECT * FROM {ctx.ucx_catalog}.multiworkspace.workflow_runs" | ||
# Be confident that we are not selecting any workflow runs before the to-be-tested code | ||
assert not any(ctx.sql_backend.fetch(select_workflow_runs_query)) | ||
|
||
ctx.workflow_run_recorder.record() | ||
|
||
rows = list(ctx.sql_backend.fetch(select_workflow_runs_query)) | ||
assert len(rows) == 1 | ||
assert rows[0].started_at == start_time | ||
assert start_time <= rows[0].finished_at <= dt.datetime.now(tz=dt.timezone.utc) | ||
assert rows[0].workspace_id == 123456789 | ||
assert rows[0].workflow_name == "test" | ||
assert rows[0].workflow_id == 123 | ||
assert rows[0].workflow_run_id == 456 | ||
assert rows[0].workflow_run_attempt == 0 |
This file contains hidden or 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 hidden or 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,14 @@ | ||
from databricks.labs.ucx.progress.install import ProgressTrackingInstallation | ||
|
||
|
||
def test_progress_tracking_installation_run_creates_progress_tracking_schema(mock_backend) -> None: | ||
installation = ProgressTrackingInstallation(mock_backend, "ucx") | ||
installation.run() | ||
assert "CREATE SCHEMA IF NOT EXISTS ucx.multiworkspace" in mock_backend.queries[0] | ||
|
||
|
||
def test_progress_tracking_installation_run_creates_workflow_runs_table(mock_backend) -> None: | ||
installation = ProgressTrackingInstallation(mock_backend, "ucx") | ||
installation.run() | ||
# Dataclass to schema conversion is tested within the lsql package | ||
assert any("CREATE TABLE IF NOT EXISTS" in query for query in mock_backend.queries) |
This file contains hidden or 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,30 @@ | ||
import datetime as dt | ||
|
||
from databricks.labs.ucx.progress.workflow_runs import WorkflowRunRecorder | ||
|
||
|
||
def test_workflow_run_record_records_workflow_run(mock_backend) -> None: | ||
"""Ensure that the workflow run recorder records a workflow run""" | ||
start_time = dt.datetime.now(tz=dt.timezone.utc).replace(microsecond=0) | ||
workflow_run_recorder = WorkflowRunRecorder( | ||
mock_backend, | ||
ucx_catalog="ucx", | ||
workspace_id=123456789, | ||
workflow_name="workflow", | ||
workflow_id=123, | ||
workflow_run_id=456, | ||
workflow_run_attempt=0, | ||
workflow_start_time=start_time.isoformat(), | ||
) | ||
|
||
workflow_run_recorder.record() | ||
|
||
rows = mock_backend.rows_written_for("ucx.multiworkspace.workflow_runs", "append") | ||
assert len(rows) == 1 | ||
assert rows[0].started_at == start_time | ||
assert start_time <= rows[0].finished_at <= dt.datetime.now(tz=dt.timezone.utc) | ||
assert rows[0].workspace_id == 123456789 | ||
assert rows[0].workflow_name == "workflow" | ||
assert rows[0].workflow_id == 123 | ||
assert rows[0].workflow_run_id == 456 | ||
assert rows[0].workflow_run_attempt == 0 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.