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

Exclude ucx dashboards from Lakeview dashboard crawler #3450

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions src/databricks/labs/ucx/assessment/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,18 +310,22 @@ def __init__(
schema: str,
*,
include_dashboard_ids: list[str] | None = None,
exclude_dashboard_ids: list[str] | None = None,
include_query_ids: list[str] | None = None,
):
super().__init__(sql_backend, "hive_metastore", schema, "lakeview_dashboards", Dashboard)
self._ws = ws
self._include_dashboard_ids = include_dashboard_ids
self._exclude_dashboard_ids = exclude_dashboard_ids
self._include_query_ids = include_query_ids

def _crawl(self) -> Iterable[Dashboard]:
dashboards = []
for sdk_dashboard in self._list_dashboards():
if sdk_dashboard.dashboard_id is None:
continue
if sdk_dashboard.dashboard_id in (self._exclude_dashboard_ids or []):
continue
dashboard = Dashboard.from_sdk_lakeview_dashboard(sdk_dashboard)
dashboards.append(dashboard)
return dashboards
Expand Down
1 change: 1 addition & 0 deletions src/databricks/labs/ucx/contexts/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ def lakeview_crawler(self) -> LakeviewDashboardCrawler:
self.sql_backend,
self.inventory_database,
include_dashboard_ids=self.config.include_dashboard_ids,
exclude_dashboard_ids=list(self.install_state.dashboards.values()),
include_query_ids=self.config.include_query_ids,
)

Expand Down
30 changes: 30 additions & 0 deletions tests/unit/assessment/test_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,36 @@ def get_dashboards(dashboard_id: str) -> SdkLakeviewDashboard:
ws.lakeview.list.assert_not_called()


def test_lakeview_dashboard_crawler_skips_exclude_dashboard_ids(caplog, mock_backend) -> None:
ws = create_autospec(WorkspaceClient)
dashboards = [SdkLakeviewDashboard(dashboard_id="did1"), SdkLakeviewDashboard(dashboard_id="did2")]
ws.lakeview.list.side_effect = lambda: (dashboard for dashboard in dashboards) # Expects an iterator
crawler = LakeviewDashboardCrawler(ws, mock_backend, "test", exclude_dashboard_ids=["did2"])

crawler.snapshot()

rows = mock_backend.rows_written_for("hive_metastore.test.lakeview_dashboards", "overwrite")
assert rows == [Row(id="did1", name=None, parent=None, query_ids=[], tags=[], creator_id=None)]
ws.lakeview.list.assert_called_once()


def test_lakeview_dashboard_crawler_skips_exclude_dashboard_ids_takes_priority_over_include_dashboard_ids(
caplog, mock_backend
) -> None:
ws = create_autospec(WorkspaceClient)
ws.lakeview.get.side_effect = lambda dashboard_id: SdkLakeviewDashboard(dashboard_id=dashboard_id)
crawler = LakeviewDashboardCrawler(
ws, mock_backend, "test", include_dashboard_ids=["did1", "did2"], exclude_dashboard_ids=["did2"]
)

crawler.snapshot()

rows = mock_backend.rows_written_for("hive_metastore.test.lakeview_dashboards", "overwrite")
assert rows == [Row(id="did1", name=None, parent=None, query_ids=[], tags=[], creator_id=None)]
ws.lakeview.list.assert_not_called()
ws.lakeview.get.assert_has_calls([call("did1"), call("did2")])


def test_lakeview_dashboard_crawler_list_queries_includes_query_ids(mock_backend) -> None:
ws = create_autospec(WorkspaceClient)
datasets = [
Expand Down
Loading