Skip to content

Commit 01071c7

Browse files
committed
feat(ingestion/grafana) add option to pass grafana as is as dashboard owner
Also remove the unique id of the dashboard as a owner.
1 parent 697be41 commit 01071c7

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

metadata-ingestion/src/datahub/ingestion/source/grafana/entity_mcp_builder.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def build_dashboard_mcps(
167167
chart_urns: List[str],
168168
base_url: str,
169169
ingest_owners: bool,
170+
strip_user_ids_from_email: bool,
170171
ingest_tags: bool,
171172
) -> Tuple[str, List[MetadataChangeProposalWrapper]]:
172173
"""Build dashboard metadata change proposals"""
@@ -206,7 +207,7 @@ def build_dashboard_mcps(
206207

207208
# Ownership aspect
208209
if dashboard.uid and ingest_owners:
209-
owner = _build_ownership(dashboard)
210+
owner = _build_ownership(dashboard, strip_user_ids_from_email)
210211
if owner:
211212
mcps.append(
212213
MetadataChangeProposalWrapper(
@@ -378,24 +379,22 @@ def _build_dashboard_properties(dashboard: Dashboard) -> Dict[str, str]:
378379
return props
379380

380381

381-
def _build_ownership(dashboard: Dashboard) -> Optional[OwnershipClass]:
382+
def _build_ownership(
383+
dashboard: Dashboard, strip_user_ids_from_email: bool
384+
) -> Optional[OwnershipClass]:
382385
"""Build ownership information"""
383386
owners = []
384387

385-
if dashboard.uid:
386-
owners.append(
387-
OwnerClass(
388-
owner=make_user_urn(dashboard.uid),
389-
type=OwnershipTypeClass.TECHNICAL_OWNER,
390-
)
391-
)
392-
393388
if dashboard.created_by:
394-
owner_id = dashboard.created_by.split("@")[0]
389+
if strip_user_ids_from_email:
390+
owner_id = dashboard.created_by.split("@")[0]
391+
else:
392+
owner_id = dashboard.created_by
393+
395394
owners.append(
396395
OwnerClass(
397396
owner=make_user_urn(owner_id),
398-
type=OwnershipTypeClass.DATAOWNER,
397+
type=OwnershipTypeClass.TECHNICAL_OWNER,
399398
)
400399
)
401400

metadata-ingestion/src/datahub/ingestion/source/grafana/grafana_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ class GrafanaSourceConfig(
8383
ingest_owners: bool = Field(
8484
default=True, description="Whether to ingest dashboard ownership information"
8585
)
86+
strip_user_ids_from_email: bool = Field(
87+
True,
88+
description="When enabled, converts Grafana user emails of the form [email protected] to urn:li:corpuser:name "
89+
"when assigning ownership",
90+
)
8691
skip_text_panels: bool = Field(
8792
default=False,
8893
description="Whether to skip text panels during ingestion. "

metadata-ingestion/src/datahub/ingestion/source/grafana/grafana_source.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ def _process_dashboard(self, dashboard: Dashboard) -> Iterable[MetadataWorkUnit]
392392
chart_urns=chart_urns,
393393
base_url=self.config.url,
394394
ingest_owners=self.config.ingest_owners,
395+
strip_user_ids_from_email=self.config.strip_user_ids_from_email,
395396
ingest_tags=self.config.ingest_tags,
396397
)
397398

metadata-ingestion/tests/unit/grafana/test_grafana_entity_mcp_builder.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,23 @@ def test_build_dashboard_properties(mock_dashboard):
7272

7373

7474
def test_build_ownership(mock_dashboard):
75-
ownership = _build_ownership(mock_dashboard)
75+
ownership = _build_ownership(mock_dashboard, True)
7676
assert isinstance(ownership, OwnershipClass)
77-
assert len(ownership.owners) == 2
77+
assert len(ownership.owners) == 1
7878
assert {owner.owner for owner in ownership.owners} == {
79-
"urn:li:corpuser:dash1",
8079
"urn:li:corpuser:test",
8180
}
8281

8382

83+
def test_build_ownership_full_email(mock_dashboard):
84+
ownership = _build_ownership(mock_dashboard, False)
85+
assert isinstance(ownership, OwnershipClass)
86+
assert len(ownership.owners) == 1
87+
assert {owner.owner for owner in ownership.owners} == {
88+
"urn:li:corpuser:[email protected]",
89+
}
90+
91+
8492
def test_build_chart_mcps(mock_panel, mock_dashboard):
8593
dataset_urn, chart_urn, chart_mcps = build_chart_mcps(
8694
panel=mock_panel,
@@ -147,6 +155,7 @@ def test_build_dashboard_mcps(mock_dashboard):
147155
chart_urns=chart_urns,
148156
base_url="http://grafana.test",
149157
ingest_owners=True,
158+
strip_user_ids_from_email=True,
150159
ingest_tags=True,
151160
)
152161

@@ -193,7 +202,7 @@ def test_build_dashboard_mcps(mock_dashboard):
193202
)
194203
assert ownership_mcp is not None
195204
assert isinstance(ownership_mcp.aspect, OwnershipClass) # type safety
196-
assert len(ownership_mcp.aspect.owners) == 2
205+
assert len(ownership_mcp.aspect.owners) == 1
197206

198207

199208
def test_build_chart_mcps_no_tags(mock_panel, mock_dashboard):
@@ -222,6 +231,7 @@ def test_build_dashboard_mcps_no_owners(mock_dashboard):
222231
chart_urns=[],
223232
base_url="http://grafana.test",
224233
ingest_owners=True,
234+
strip_user_ids_from_email=True,
225235
ingest_tags=True,
226236
)
227237

0 commit comments

Comments
 (0)