feat(ingest/powerbi): add workspace_apis metadata mode and definition-based enrichment

Merged
BR
18d ago
+9504-74

Summary

Adds metadata_api_mode: workspace_apis to the Power BI connector: a way to ingest Power BI without tenant admin API access. Today the connector depends on the Admin Scanner API, which many customers refuse to grant to a service principal. In the new mode the connector never calls the admin APIs:

  • Semantic-model schemas, M expressions and lineage come from the Fabric item-definition APIs (getDefinition, TMDL for semantic models, PBIR for reports, RDL for paginated reports).
  • Ownership comes from workspace role assignments (GET /groups/{id}/users).
  • Dashboards, tiles, reports and pages come from the existing per-workspace endpoints.

Required permissions are only the Contributor role on each ingested workspace plus the tenant settings "Allow service principals to use Power BI APIs" and "Service principals can use Fabric APIs". No Entra application permissions change. Default behaviour (admin_scan) is unchanged.

Limitations of workspace_apis

What you give up, or need, compared with admin_scan:

  • Admin-only options are rejected. extract_endorsements_to_tags, filter_dataset_endorsements, extract_app, modified_since and admin_apis_only fail config validation with workspace_apis. There is no endorsement filtering, no Power BI apps, and no incremental workspace selection: every run reads every workspace in scope.
  • Owners are workspace members, not per-item owners. Ownership comes from workspace role assignments (Admin, Member, Contributor, Viewer), so every dashboard and report in a workspace gets the same owners. A non-empty ownership.owner_criteria is matched against those role names and must include at least one of them; item-level rights such as ReadWriteReshareExplore never match.
  • Contributor is required for schemas and lineage. With only Viewer, datasets are ingested by id and name but have no tables, columns, measures or upstream lineage, and the run reports a failure for each refused semantic model.
  • Items with encrypted sensitivity labels can't be read. Fabric refuses getDefinition for them unless the principal has usage rights to remove the label. A refused semantic model is a failure; a refused report only loses visual field usage (a warning).
  • Push and streaming semantic models have no definition. They are ingested by id and name only, without tables, schema or lineage, and reported as a warning (Semantic Model Definition Not Supported), not a failure.
  • Commercial cloud only. The connector only knows the commercial Fabric API endpoint (environment: COMMERCIAL).
  • More API calls. One scan per scan_batch_size workspaces is replaced by per-item requests, including a long-running getDefinition per semantic model (bounded by scan_timeout). Large tenants take longer and can hit Fabric's throttling of 500 calls per minute per principal; throttled calls are retried.
  • One partition per table. Lineage is read from a table's first TMDL partition, the same as the scan path. Tables whose partitions use different sources (hand-managed over XMLA) only get the first source's lineage.

Enrichment read from the definitions (all opt-in, default off)

FlagEmits
extract_model_relationshipsmodel relationships as schemaMetadata.foreignKeys (sourceFields on the from-table, foreignFields on the to-table)
extract_report_field_usagevisual field usage as inputFields on report pages, plus visualTypes / visualCount properties; DAX measures become same-platform fine-grained lineage
extract_refresh_historythe latest completed dataset refresh as an Operation aspect (works in both modes)
(always, in workspace mode)DirectLake lineage to OneLake through the lakehouse SQL analytics endpoint

Also in this PR

  • Fixes a pre-existing bug where fine-grained lineage was duplicated once per upstream table (golden_test_cll.json loses one duplicate entry).
  • Column lineage is now filtered with the same dataset_type_mapping predicate as table lineage, so column edges never point at a table that was filtered out.
  • Failure classification: anything that leaves a semantic model or workspace without its entities is a report.failure, so a run can never stay green and let stale-entity removal soft-delete tables. Refused report definitions (e.g. encrypted sensitivity labels) only lose visual field usage and are warnings.

New modules

rest_api_wrapper/fabric_resolver.py (Fabric REST client, LRO polling bounded by scan_timeout), rest_api_wrapper/tmdl_parser.py, rest_api_wrapper/report_definition_parser.py.

Testing

  • Unit tests for the config validators, TMDL parser, PBIR/legacy/RDL report parser, Fabric resolver (LRO, timeouts, binary parts), workspace users, mapper enrichment, and the definition-driven workspace fill.
  • Integration test test_workspace_apis_mode.py with a new golden file and mock TMDL/PBIR definitions.
  • Verified end to end against a real tenant on a local DataHub instance: 20 workspaces, ~7.8k records, no failures; Snowflake → Power BI table → DAX table → pages → report → dashboard lineage, foreign keys and page input fields all visible in the UI. All fixture identifiers are synthetic.
  • Connector review (silent failures, test coverage, type design, lineage correctness) run and all blockers addressed.

Docs

powerbi_pre.md gains a "Workspace APIs ingestion (no admin API access)" section with the requirements table and the Viewer-role behaviour; powerbi_recipe.yml shows the new options. The mode and every new flag are opt-in. One change reaches existing admin_scan runs: column-level lineage now follows the same dataset_type_mapping filter as table-level lineage, so a narrowed mapping drops column edges to the platforms it leaves out, and duplicate column edges are removed. That is recorded in docs/how/breaking-changes.md.

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly PR Title Format)
  • Links to related issues (if applicable)
  • Tests for the changes have been added/updated (if applicable)
  • Docs related to the changes have been added/updated (if applicable). If a new feature has been added a Usage Guide has been added for the same.
  • For any breaking change/potential downtime/deprecation/big changes an entry has been made in Breaking Changes — added for the column-lineage dataset_type_mapping filter

🤖 Generated with Claude Code


Summary by cubic

Adds metadata_api_mode: workspace_apis to the Power BI connector so ingestion works without tenant-admin API access. Semantic-model schemas, M expressions, and lineage come from the Fabric item-definition APIs (TMDL for semantic models, PBIR for reports), and ownership comes from workspace role assignments; only the Contributor role per workspace plus a Fabric tenant setting is required. The default admin_scan mode is unchanged.

New Features

  • extract_model_relationships, extract_report_field_usage, and extract_refresh_history are opt-in and emit model relationships as foreign keys, visual field usage on report pages, and dataset refresh history as an Operation aspect.
  • DirectLake lineage to OneLake is resolved through the lakehouse SQL analytics endpoint.
  • getDefinition requests and long-running-operation result downloads now wait up to scan_timeout, so large models no longer time out after the operation has succeeded.

Bug Fixes

  • Duplicate fine-grained lineage edges are removed, and column lineage follows the same dataset_type_mapping filter as table lineage; recorded in the breaking-changes docs.
  • In workspace_apis mode, failures that lose entities (unhandled workspace failures, TMDL table-part parse errors, report-pages fetch failures, missing or empty definition parts) fail the run so stale-entity removal never deletes partial metadata; Phase 2 failures stay warnings in admin_scan.
  • Push and streaming semantic models, and addRowsAPIEnabled datasets skipping getDefinition, are warnings rather than failures.
  • Paginated reports aren't queried for pages, and one without an RDL dataset binding falls back to /datasources.
  • Quoted DirectLake partition sources are unquoted; unresolved OneLake sources, unparsed partition sources, and Import/DirectQuery tables with no M upstreams withhold lineage as warnings.
  • Measure, calculated-table, and visual field references match case-insensitively; SQL endpoint IDs in TMDL and dataset IDs in RDL match REST API IDs case-insensitively.
  • owner_criteria must include a workspace role with workspace_apis; criteria naming only item-level access rights are rejected.