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

feat(ingestion/powerbi): ingest powerbi app #11629

Merged
merged 24 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7593a77
ingest app as dashboard
sid-acryl Oct 15, 2024
e7855f7
emit app
sid-acryl Oct 15, 2024
b776d68
Merge branch 'master' into ing-732-app-ingestion
sid-acryl Oct 15, 2024
e26845c
Merge branch 'master' into ing-732-app-ingestion
sid-acryl Oct 16, 2024
2f7f715
import fix
sid-acryl Oct 16, 2024
3eff956
import fix
sid-acryl Oct 16, 2024
acc8b59
removed cache
sid-acryl Oct 16, 2024
f7328a3
updated concept mapping
sid-acryl Oct 16, 2024
3774d54
corrected urn id part
sid-acryl Oct 16, 2024
66960af
resolve merge conflict
sid-acryl Oct 17, 2024
202df81
test case for app ingest
sid-acryl Oct 17, 2024
38ea56e
Merge branch 'master' into ing-732-app-ingestion
sid-acryl Oct 17, 2024
4b2b18e
Merge branch 'master' into ing-732-app-ingestion
sid-acryl Oct 18, 2024
6058df7
test case for app ingest
sid-acryl Oct 18, 2024
0b66899
Merge branch 'ing-732-app-ingestion' of https://github.com/sid-acryl/…
sid-acryl Oct 18, 2024
f6df316
update test cases & doc
sid-acryl Oct 18, 2024
67f80d0
Merge branch 'master' into ing-732-app-ingestion
treff7es Oct 19, 2024
14197d0
Merge branch 'master' into ing-732-app-ingestion
sid-acryl Oct 21, 2024
5f49a78
Update metadata-ingestion/src/datahub/ingestion/source/powerbi/config.py
sid-acryl Oct 21, 2024
a011257
address review comments
sid-acryl Oct 21, 2024
7a8db26
Merge branch 'master' into ing-732-app-ingestion
sid-acryl Oct 22, 2024
2c3c63e
Merge branch 'master' into ing-732-app-ingestion
sid-acryl Oct 23, 2024
b7b2238
Merge branch 'master' into ing-732-app-ingestion
sid-acryl Oct 24, 2024
a1e5d7a
Merge branch 'master' into ing-732-app-ingestion
sid-acryl Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class BIAssetSubTypes(StrEnum):
# PowerBI
POWERBI_TILE = "PowerBI Tile"
POWERBI_PAGE = "PowerBI Page"
POWERBI_APP = "App"

# Mode
MODE_REPORT = "Report"
Expand Down
82 changes: 82 additions & 0 deletions metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
#########################################################
import logging
from datetime import datetime
from typing import Iterable, List, Optional, Tuple, Union

import datahub.emitter.mce_builder as builder
Expand Down Expand Up @@ -52,6 +53,7 @@
from datahub.ingestion.source.state.stateful_ingestion_base import (
StatefulIngestionSourceBase,
)
from datahub.metadata._schema_classes import AuditStampClass, EdgeClass
from datahub.metadata.com.linkedin.pegasus2avro.common import ChangeAuditStamps
from datahub.metadata.com.linkedin.pegasus2avro.dataset import (
FineGrainedLineage,
Expand Down Expand Up @@ -1306,6 +1308,84 @@ def extract_independent_datasets(
)
)

def emit_app(
self, workspace: powerbi_data_classes.Workspace
) -> Iterable[MetadataWorkUnit]:
sid-acryl marked this conversation as resolved.
Show resolved Hide resolved
if workspace.app is None:
return

edges: List[EdgeClass] = [
EdgeClass(
destinationUrn=builder.make_dashboard_urn(
platform=self.source_config.platform_name,
platform_instance=self.source_config.platform_instance,
name=powerbi_data_classes.Dashboard.get_urn_part_by_id(
app_dashboard.original_dashboard_id
),
)
)
for app_dashboard in workspace.app.dashboards
]

edges.extend(
[
EdgeClass(
destinationUrn=builder.make_dashboard_urn(
platform=self.source_config.platform_name,
platform_instance=self.source_config.platform_instance,
name=powerbi_data_classes.Report.get_urn_part_by_id(
app_report.original_report_id
),
)
)
for app_report in workspace.app.reports
]
)

if edges:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make these variable names more clear - edges = dashboards within the app?

also dashboard_urn being the app's urn is super confusing - let's make this more clear

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

dashboard_info: DashboardInfoClass = DashboardInfoClass(
title=workspace.app.name,
description=workspace.app.description
if workspace.app.description
else workspace.app.name,
# lastModified=workspace.app.last_update,
lastModified=ChangeAuditStamps(
lastModified=AuditStampClass(
actor=str(),
time=int(
datetime.strptime(
workspace.app.last_update, "%Y-%m-%dT%H:%M:%S.%fZ"
).timestamp()
),
)
if workspace.app.last_update
else None
),
dashboards=edges,
)

dashboard_urn: str = builder.make_dashboard_urn(
platform=self.source_config.platform_name,
platform_instance=self.source_config.platform_instance,
name=powerbi_data_classes.Dashboard.get_urn_part_by_id(
workspace.app.id
),
)

yield MetadataChangeProposalWrapper(
entityUrn=dashboard_urn,
aspect=dashboard_info,
).as_workunit()

yield MetadataChangeProposalWrapper(
entityUrn=dashboard_urn, aspect=StatusClass(removed=False)
).as_workunit()

yield MetadataChangeProposalWrapper(
sid-acryl marked this conversation as resolved.
Show resolved Hide resolved
entityUrn=dashboard_urn,
aspect=SubTypesClass(typeNames=[BIAssetSubTypes.POWERBI_APP]),
).as_workunit()

def get_workspace_workunit(
self, workspace: powerbi_data_classes.Workspace
) -> Iterable[MetadataWorkUnit]:
Expand All @@ -1318,6 +1398,8 @@ def get_workspace_workunit(
# Return workunit to a Datahub Ingestion framework
yield workunit

yield from self.emit_app(workspace=workspace)

for dashboard in workspace.dashboards:
try:
# Fetch PowerBi users for dashboards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ class DatasetKey(ContainerKey):
dataset: str


@dataclass
class AppDashboard:
id: str
original_dashboard_id: str


@dataclass
class AppReport:
id: str
original_report_id: str


@dataclass
class App:
id: str
name: str
description: Optional[str]
last_update: Optional[str]
dashboards: List["AppDashboard"]
reports: List["AppReport"]

def get_urn_part(self):
return f"apps.{self.id}"


@dataclass
class Workspace:
id: str
Expand All @@ -49,6 +74,7 @@ class Workspace:
dashboard_endorsements: Dict[str, List[str]]
scan_result: dict
independent_datasets: List["PowerBIDataset"]
app: Optional["App"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not need to be in quotes

Suggested change
app: Optional["App"]
app: Optional[App]


def get_urn_part(self, workspace_id_as_urn_part: Optional[bool] = False) -> str:
# shouldn't use workspace name, as they can be the same?
Expand Down Expand Up @@ -229,9 +255,14 @@ class Report:
pages: List["Page"]
users: List["User"]
tags: List[str]
app_reference: Optional["App"]

def get_urn_part(self):
return f"reports.{self.id}"
return Report.get_urn_part_by_id(self.id)

@staticmethod
def get_urn_part_by_id(id_: str) -> str:
return f"reports.{id_}"


@dataclass
Expand Down Expand Up @@ -267,9 +298,14 @@ class Dashboard:
users: List["User"]
tags: List[str]
webUrl: Optional[str]
app_reference: Optional["App"]

def get_urn_part(self):
return f"dashboards.{self.id}"
return Dashboard.get_urn_part_by_id(self.id)

@staticmethod
def get_urn_part_by_id(id_: str) -> str:
return f"dashboards.{id_}"

def __members(self):
return (self.id,)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from abc import ABC, abstractmethod
from datetime import datetime, timedelta
from functools import lru_cache
from time import sleep
from typing import Any, Dict, Iterator, List, Optional, Union

Expand All @@ -13,6 +14,7 @@
from datahub.configuration.common import AllowDenyPattern, ConfigurationError
from datahub.ingestion.source.powerbi.config import Constant
from datahub.ingestion.source.powerbi.rest_api_wrapper.data_classes import (
App,
Column,
Dashboard,
Measure,
Expand Down Expand Up @@ -97,6 +99,8 @@ def __init__(
),
)

self.get_app = lru_cache(maxsize=128)(self.__get_app)
sid-acryl marked this conversation as resolved.
Show resolved Hide resolved

@abstractmethod
def get_groups_endpoint(self) -> str:
pass
Expand Down Expand Up @@ -143,6 +147,13 @@ def get_dataset_parameters(
def get_users(self, workspace_id: str, entity: str, entity_id: str) -> List[User]:
pass

@abstractmethod
def _get_app(
self,
app_id: str,
) -> Optional[Dict]:
pass

def _get_authority_url(self):
return f"{DataResolverBase.AUTHORITY}{self.__tenant_id}"

Expand Down Expand Up @@ -221,6 +232,7 @@ def get_dashboards(self, workspace: Workspace) -> List[Dashboard]:
tiles=[],
users=[],
tags=[],
app_reference=None, # It is getting set later from scan_result
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do we use app_reference for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it, not in used

)
for instance in dashboards_dict
if (
Expand Down Expand Up @@ -282,6 +294,7 @@ def fetch_reports():
users=[], # It will be fetched using Admin Fetcher based on condition
tags=[], # It will be fetched using Admin Fetcher based on condition
dataset=workspace.datasets.get(raw_instance.get(Constant.DATASET_ID)),
app_reference=None, # It is getting set later from scan-result
)
for raw_instance in fetch_reports()
if Constant.APP_ID
Expand Down Expand Up @@ -414,6 +427,37 @@ def itr_pages(

page_number += 1

def __get_app(
self,
app_id: str,
) -> Optional[App]:

raw_app: Optional[Dict] = self._get_app(
app_id=app_id,
)

if raw_app is None:
return None

assert (
Constant.ID in raw_app
), f"{Constant.ID} is required field not present in server response"

assert (
Constant.NAME in raw_app
), f"{Constant.NAME} is required field not present in server response"

return App(
id=raw_app[Constant.ID],
name=raw_app[Constant.NAME],
description=raw_app.get(Constant.DESCRIPTION),
last_update=raw_app.get(Constant.LAST_UPDATE),
dashboards=[], # dashboards and reports of App are available in scan-result response
reports=[], # There is an App section in documentation https://learn.microsoft.com/en-us/rest/api/power-bi/dashboards/get-dashboards-in-group#code-try-0
# However the report API mentioned in that section is not returning the reports
# We will collect these details from the scan-result.
)


class RegularAPIResolver(DataResolverBase):
# Regular access endpoints
Expand Down Expand Up @@ -683,6 +727,27 @@ def profile_dataset(

table.column_count = column_count

def _get_app(
self,
app_id: str,
) -> Optional[Dict]:

app_endpoint = self.API_ENDPOINTS[Constant.GET_WORKSPACE_APP].format(
MY_ORG_URL=DataResolverBase.MY_ORG_URL,
APP_ID=app_id,
)
# Hit PowerBi
logger.debug(f"Request to app URL={app_endpoint}")

response = self._request_session.get(
url=app_endpoint,
headers=self.get_authorization_header(),
)

response.raise_for_status()

return response.json()


class AdminAPIResolver(DataResolverBase):
# Admin access endpoints
Expand Down Expand Up @@ -996,3 +1061,22 @@ def profile_dataset(
) -> None:
logger.debug("Profile dataset is unsupported in Admin API")
return None

def _get_app(
self,
app_id: str,
) -> Optional[Dict]:

app_endpoint = self.API_ENDPOINTS[Constant.GET_WORKSPACE_APP].format(
POWERBI_ADMIN_BASE_URL=DataResolverBase.ADMIN_BASE_URL,
APP_ID=app_id,
)
# Hit PowerBi
logger.debug(f"Request to app URL={app_endpoint}")

for page in self.itr_pages(endpoint=app_endpoint):
for app in page:
if Constant.ID in app and app_id == app[Constant.ID]:
return app

return None
Loading
Loading