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 16 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
42 changes: 23 additions & 19 deletions metadata-ingestion/docs/sources/powerbi/powerbi_pre.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@

## Concept mapping

| PowerBI | Datahub |
|-----------------------|---------------------|
| `Dashboard` | `Dashboard` |
| `Dataset's Table` | `Dataset` |
| `Tile` | `Chart` |
| `Report.webUrl` | `Chart.externalUrl` |
| `Workspace` | `Container` |
| `Report` | `Dashboard` |
| `PaginatedReport` | `Dashboard` |
| `Page` | `Chart` |
| PowerBI | Datahub |
|-------------------|---------------------|
| `Dashboard` | `Dashboard` |
| `Dataset's Table` | `Dataset` |
| `Tile` | `Chart` |
| `Report.webUrl` | `Chart.externalUrl` |
| `Workspace` | `Container` |
| `Report` | `Dashboard` |
| `PaginatedReport` | `Dashboard` |
| `Page` | `Chart` |
| `App` | `Dashboard` |

- If `Tile` is created from report then `Chart.externalUrl` is set to Report.webUrl.
- The `Page` is unavailable for PowerBI PaginatedReport.
Expand Down Expand Up @@ -102,7 +103,7 @@ combine_result

`Pattern-2` is *not* supported for upstream table lineage extraction as it uses nested item-selector i.e. {Source{[Schema="public",Item="book"]}[Data], Source{[Schema="public",Item="issue_history"]}[Data]} as argument to M-QUery table function i.e. Table.Combine

`Pattern-1` is supported as it first assign the table from schema to variable and then variable is used in M-Query Table function i.e. Table.Combine
`Pattern-1` is supported as it first assigns the table from schema to variable and then variable is used in M-Query Table function i.e. Table.Combine

## Extract endorsements to tags

Expand All @@ -112,18 +113,20 @@ Please note that the default implementation overwrites tags for the ingested ent

## Profiling

The profiling implementation is done through querying [DAX query endpoint](https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/execute-queries). Therefore the principal needs to have permission to query the datasets to be profiled. Usually this means that the service principal should have `Contributor` role for the workspace to be ingested. Profiling is done with column based queries to be able to handle wide datasets without timeouts.
The profiling implementation is done through querying [DAX query endpoint](https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/execute-queries). Therefore, the principal needs to have permission to query the datasets to be profiled. Usually this means that the service principal should have `Contributor` role for the workspace to be ingested. Profiling is done with column-based queries to be able to handle wide datasets without timeouts.

Take into account that the profiling implementation exeutes fairly big amount of DAX queries and for big datasets this is substantial load to the PowerBI system.
Take into account that the profiling implementation executes a fairly big number of DAX queries, and for big datasets this is a significant load to the PowerBI system.

The `profiling_pattern` setting may be used to limit profiling actions to only a certain set of resources in PowerBI. Both allow and deny rules are matched against following pattern for every table in a PowerBI Dataset: `workspace_name.dataset_name.table_name`. User may limit profiling with these settings at table level, dataset level or workspace level.
The `profiling_pattern` setting may be used to limit profiling actions to only a certain set of resources in PowerBI. Both allowed and deny rules are matched against the following pattern for every table in a PowerBI Dataset: `workspace_name.dataset_name.table_name`. Users may limit profiling with these settings at table level, dataset level or workspace level.

## Admin Ingestion vs. Basic Ingestion
PowerBI provides two sets of API i.e. [Basic API and Admin API](https://learn.microsoft.com/en-us/rest/api/power-bi/).

The Basic API returns metadata of PowerBI resources where service principal has granted access explicitly on resources whereas Admin API returns metadata of all PowerBI resources irrespective of whether service principal has granted or doesn't granted access explicitly on resources.
The Basic API returns metadata of PowerBI resources where service principal has granted access explicitly on resources,
whereas Admin API returns metadata of all PowerBI resources irrespective of whether service principal has granted
or doesn't grant access explicitly on resources.

The Admin Ingestion (explain below) is the recommended way to execute PowerBI ingestion as this ingestion can extract most of the metadata.
The Admin Ingestion (explained below) is the recommended way to execute PowerBI ingestion as this ingestion can extract most of the metadata.


### Admin Ingestion: Service Principal As Admin in Tenant Setting and Added as Member In Workspace
Expand All @@ -142,8 +145,9 @@ PowerBI Source would be able to ingest below listed metadata of that particular
- Endorsement as tag
- Dashboards
- Reports
- Dashboard's Tiles
- Report's Pages
- Dashboard Tiles
- Report Pages
- App

If you don't want to add a service principal as a member in your workspace, then you can enable the `admin_apis_only: true` in recipe to use PowerBI Admin API only.

Expand All @@ -154,7 +158,7 @@ Caveats of setting `admin_apis_only` to `true`:


### Basic Ingestion: Service Principal As Member In Workspace
If you have added service principal as `member` in workspace then PowerBI Source would be able ingest below metadata of that particular workspace
If you have added service principal as `member` in workspace then PowerBI Source would be able to ingest below metadata of that particular workspace

- Dashboards
- Reports
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,11 @@ class PowerBiDashboardSourceConfig(
"To maintain backward compatibility, this is set to False.",
)

extract_app: bool = pydantic.Field(
default=False,
description="Whether to ingest workspace app. Default to false",
sid-acryl marked this conversation as resolved.
Show resolved Hide resolved
)

@root_validator(skip_on_failure=True)
def validate_extract_column_level_lineage(cls, values: Dict) -> Dict:
flags = [
Expand Down
105 changes: 104 additions & 1 deletion 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 @@ -59,6 +60,7 @@
FineGrainedLineageUpstreamType,
)
from datahub.metadata.schema_classes import (
AuditStampClass,
BrowsePathsClass,
ChangeTypeClass,
ChartInfoClass,
Expand All @@ -70,6 +72,7 @@
DatasetLineageTypeClass,
DatasetProfileClass,
DatasetPropertiesClass,
EdgeClass,
GlobalTagsClass,
OtherSchemaClass,
OwnerClass,
Expand Down Expand Up @@ -1006,7 +1009,9 @@ def to_chart_mcps(
)

# Browse path
browse_path = BrowsePathsClass(paths=[f"/powerbi/{workspace.name}"])
browse_path = BrowsePathsClass(
paths=[f"/{Constant.PLATFORM_NAME}/{workspace.name}"]
)
browse_path_mcp = self.new_mcp(
entity_urn=chart_urn,
aspect=browse_path,
Expand Down Expand Up @@ -1306,6 +1311,102 @@ 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

if not self.source_config.extract_app:
self.reporter.info(
title="App Ingestion Is Disabled",
message="You are missing workspace app metadata. Please set flag `extract_app` to `true` in recipe to ingest workspace app.",
context=f"workspace-name={workspace.name}, app-name = {workspace.app.name}",
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need a return here? when would .app be populated if app ingestion is disabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added return. .app will be populated on next run after setting extract_app to true


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

logger.debug(
f"Emitting metadata-workunits for app {workspace.app.name}({workspace.app.id})"
)
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="urn:li:corpuser:unknown",
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.App.get_urn_part_by_id(workspace.app.id),
)

# Browse path
browse_path: BrowsePathsClass = BrowsePathsClass(
paths=[f"/powerbi/{workspace.name}"]
)

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

yield MetadataChangeProposalWrapper(
entityUrn=dashboard_urn,
aspect=browse_path,
).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 +1419,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,35 @@ 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 App.get_urn_part_by_id(self.id)

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


@dataclass
class Workspace:
id: str
Expand All @@ -49,6 +78,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 @@ -233,9 +263,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 @@ -271,9 +306,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
Loading
Loading