Added exception handling in dashboard sources (#10573)

* added exception handling in dashboard

* updated process owner logic

* Added redash source for fixes
This commit is contained in:
Onkar Ravgan 2023-03-15 14:00:03 +05:30 committed by GitHub
parent 47585e035a
commit 682626ffe8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 65 deletions

View File

@ -274,10 +274,36 @@ class DashboardServiceSource(TopologyRunnerMixin, Source, ABC):
entity=DashboardService, config=config entity=DashboardService, config=config
) )
def process_owner(self, dashboard_details: dict): # pylint: disable=unused-argument def process_owner(self, dashboard_details):
try:
owner = self.get_owner_details( # pylint: disable=assignment-from-none
dashboard_details=dashboard_details
)
if owner and self.source_config.overrideOwner:
self.metadata.patch_owner(
entity=Dashboard,
entity_id=self.context.dashboard.id,
owner=owner,
force=True,
)
except Exception as exc:
logger.debug(traceback.format_exc())
logger.warning(f"Error processing owner for {dashboard_details}: {exc}")
def get_owner_details( # pylint: disable=useless-return
self, dashboard_details # pylint: disable=unused-argument
) -> Optional[EntityReference]:
"""Get dashboard owner
Args:
dashboard_details:
Returns:
Optional[EntityReference]
"""
logger.debug( logger.debug(
f"Processing ownership is not supported for {self.service_connection.type.name}" f"Processing ownership is not supported for {self.service_connection.type.name}"
) )
return None
@staticmethod @staticmethod
def _get_add_lineage_request( def _get_add_lineage_request(

View File

@ -27,7 +27,6 @@ from metadata.generated.schema.api.data.createChart import CreateChartRequest
from metadata.generated.schema.api.data.createDashboard import CreateDashboardRequest from metadata.generated.schema.api.data.createDashboard import CreateDashboardRequest
from metadata.generated.schema.api.lineage.addLineage import AddLineageRequest from metadata.generated.schema.api.lineage.addLineage import AddLineageRequest
from metadata.generated.schema.entity.data.chart import Chart from metadata.generated.schema.entity.data.chart import Chart
from metadata.generated.schema.entity.data.dashboard import Dashboard
from metadata.generated.schema.entity.services.connections.dashboard.domoDashboardConnection import ( from metadata.generated.schema.entity.services.connections.dashboard.domoDashboardConnection import (
DomoDashboardConnection, DomoDashboardConnection,
) )
@ -95,8 +94,10 @@ class DomodashboardSource(DashboardServiceSource):
def get_dashboard_details(self, dashboard: DomoDashboardDetails) -> dict: def get_dashboard_details(self, dashboard: DomoDashboardDetails) -> dict:
return dashboard return dashboard
def get_owner_details(self, owners: List[DomoOwner]) -> Optional[EntityReference]: def get_owner_details(
for owner in owners: self, dashboard_details: DomoDashboardDetails
) -> Optional[EntityReference]:
for owner in dashboard_details.owners:
try: try:
owner_details = self.client.users_get(owner.id) owner_details = self.client.users_get(owner.id)
if owner_details.get("email"): if owner_details.get("email"):
@ -112,18 +113,6 @@ class DomodashboardSource(DashboardServiceSource):
) )
return None return None
def process_owner(
self, dashboard_details: DomoDashboardDetails
) -> Optional[Dashboard]:
owner = self.get_owner_details(owners=dashboard_details.owners)
if owner and self.source_config.overrideOwner:
self.metadata.patch_owner(
entity=Dashboard,
entity_id=self.context.dashboard.id,
owner=owner,
force=True,
)
def yield_dashboard( def yield_dashboard(
self, dashboard_details: DomoDashboardDetails self, dashboard_details: DomoDashboardDetails
) -> Iterable[CreateDashboardRequest]: ) -> Iterable[CreateDashboardRequest]:

View File

@ -182,18 +182,6 @@ class LookerSource(DashboardServiceSource):
return self._owners_ref.get(dashboard_details.user_id) return self._owners_ref.get(dashboard_details.user_id)
def process_owner(
self, dashboard_details: LookerDashboard
) -> Optional[MetadataDashboard]:
owner = self.get_owner_details(dashboard_details=dashboard_details)
if owner and self.source_config.overrideOwner:
self.metadata.patch_owner(
entity=MetadataDashboard,
entity_id=self.context.dashboard.id,
owner=owner,
force=True,
)
def yield_dashboard( def yield_dashboard(
self, dashboard_details: LookerDashboard self, dashboard_details: LookerDashboard
) -> CreateDashboardRequest: ) -> CreateDashboardRequest:

View File

@ -91,7 +91,13 @@ class PowerbiSource(DashboardServiceSource):
response = self.client.fetch_workspace_scan_result( response = self.client.fetch_workspace_scan_result(
scan_id=workspace_scan_id scan_id=workspace_scan_id
) )
self.workspace_data.extend(response.get("workspaces")) self.workspace_data.extend(
[
active_workspace
for active_workspace in response.get("workspaces")
if active_workspace.get("state") == "Active"
]
)
else: else:
logger.error("Error in fetching dashboards and charts") logger.error("Error in fetching dashboards and charts")
count += 1 count += 1

View File

@ -173,20 +173,6 @@ class RedashSource(DashboardServiceSource):
return EntityReference(id=user.id.__root__, type="user") return EntityReference(id=user.id.__root__, type="user")
return None return None
def process_owner(self, dashboard_details) -> Optional[LineageDashboard]:
try:
owner = self.get_owner_details(dashboard_details=dashboard_details)
if owner and self.source_config.overrideOwner:
self.metadata.patch_owner(
entity=LineageDashboard,
entity_id=self.context.dashboard.id,
owner=owner,
force=True,
)
except Exception as exc:
logger.debug(traceback.format_exc())
logger.warning(f"Error processing owner for {dashboard_details}: {exc}")
def get_dashboard_url(self, dashboard_details: dict) -> str: def get_dashboard_url(self, dashboard_details: dict) -> str:
if version.parse(self.service_connection.redashVersion) > version.parse( if version.parse(self.service_connection.redashVersion) > version.parse(
INCOMPATIBLE_REDASH_VERSION INCOMPATIBLE_REDASH_VERSION

View File

@ -88,16 +88,6 @@ class SupersetSourceMixin(DashboardServiceSource):
return None return None
def process_owner(self, dashboard_details: dict) -> Optional[Lineage_Dashboard]:
owner = self.get_owner_details(dashboard_details=dashboard_details)
if owner and self.source_config.overrideOwner:
self.metadata.patch_owner(
self.metadata,
entity=Lineage_Dashboard,
entity_id=self.context.dashboard.id,
force=True,
)
def get_owner_details(self, dashboard_details: dict) -> EntityReference: def get_owner_details(self, dashboard_details: dict) -> EntityReference:
for owner in dashboard_details.get("owners", []): for owner in dashboard_details.get("owners", []):
user = self._get_user_by_email(owner["email"]) user = self._get_user_by_email(owner["email"])

View File

@ -251,18 +251,6 @@ class TableauSource(DashboardServiceSource):
return EntityReference(id=user.id.__root__, type="user") return EntityReference(id=user.id.__root__, type="user")
return None return None
def process_owner(
self, dashboard_details: TableauDashboard
) -> Optional[LineageDashboard]:
owner = self.get_owner_details(dashboard_details=dashboard_details)
if owner and self.source_config.overrideOwner:
self.metadata.patch_owner(
entity=LineageDashboard,
entity_id=self.context.dashboard.id,
owner=owner,
force=True,
)
def yield_tag(self, *_, **__) -> OMetaTagAndClassification: def yield_tag(self, *_, **__) -> OMetaTagAndClassification:
""" """
Fetch Dashboard Tags Fetch Dashboard Tags