Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
f9f443a
feat(ingest/looker): add opt-in GitHub link to Explores
aviraj-gour Nov 20, 2026
eb02102
refactor(ingest/looker): use host-neutral 'View in Git' label for Exp…
aviraj-gour Nov 20, 2026
c48997b
feat(ingest/looker): replace stale Explore Git links instead of keyin…
aviraj-gour Nov 20, 2026
42d0b13
fix(ingest/looker): address review on Explore Git links
aviraj-gour Nov 20, 2026
09fe0eb
refactor(ingest/looker): match managed Explore Git links by label only
aviraj-gour Nov 23, 2026
c8378bb
test(ingest/looker): pin Explore Git link target and per-project repos
aviraj-gour Nov 23, 2026
42e401a
fix(ingest/looker): URL-encode the branch in Explore Git links
aviraj-gour Nov 23, 2026
580f7a0
fix(ingest/looker): anchor lookml_link parsing and stamp links with r…
aviraj-gour Nov 23, 2026
4befb97
docs(ingest/looker): shorten the Explore Git links section
aviraj-gour Nov 23, 2026
0802ca7
fix(ingest/looker): don't fail the run when Explore links can't be read
aviraj-gour Nov 23, 2026
0897194
perf(ingest/looker): read Explore links on worker threads
aviraj-gour Nov 25, 2026
4b41156
fix(ingest/looker): accept user-less and alternate-host Git remotes
aviraj-gour Nov 25, 2026
dccd5fc
fix(ingest/looker): skip only the failing Explore when a link read fails
aviraj-gour Nov 27, 2026
9c70ace
refactor(ingest/looker): decide an Explore's Git link once
aviraj-gour Nov 27, 2026
c0b34fb
perf(ingest/looker): skip link reads for projects without a usable re…
aviraj-gour Nov 27, 2026
e67b9ec
fix(ingest/looker): report Explores with no LookML file link
aviraj-gour Nov 27, 2026
815e9dc
test(ingest/looker): trim Explore Git link tests and restore kept-lin…
aviraj-gour Nov 27, 2026
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
8 changes: 8 additions & 0 deletions metadata-ingestion/docs/sources/looker/looker_post.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ Explore usage is attached only to explores that were actually ingested in the sa

:::

#### Explore links to Git

Set `extract_explore_git_links: true` to add a **View in Git** button to each Explore, linking to the LookML file that defines it. The repository and branch come from the Explore's Looker project, so the API key must be able to read project settings.

With a DataHub connection, each run reads the Explore's links (one read per Explore) and replaces any outdated "View in Git" link, including one added by hand, so use another label for your own links. If DataHub can't be reached, the report shows a warning and links are skipped for the rest of the run; if only one Explore's links can't be read, only that Explore is skipped. Without a connection, links are only added.

Only github.com and gitlab.com remotes are supported. Projects that can't be read or have an unsupported remote get a warning, and their Explores keep any existing link. Explores from imported projects get no link. Turning the option off does not remove links.

#### LookML projects ingested under other platform instances

Explores link to the LookML views they read. Those view URNs must match the ones the `lookml` recipes emit, which include each recipe's `platform_instance`. By default the `looker` recipe builds every view URN with its own `platform_instance` and `env`. When LookML projects are ingested by separate `lookml` recipes with different platform instances, for example one recipe per git repository, map each project to its recipe's instance:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Union,
cast,
)
from urllib.parse import unquote, urlsplit

import lkml
from looker_sdk.error import SDKError
Expand Down Expand Up @@ -51,7 +52,11 @@
NamingPatternMapping,
ViewNamingPatternMapping,
)
from datahub.ingestion.source.looker.looker_constant import IMPORTED_PROJECTS_PREFIX
from datahub.ingestion.source.looker.looker_constant import (
GIT_SCP_REMOTE_PATTERN,
IMPORTED_PROJECTS_PREFIX,
LOOKML_LINK_PATH_PATTERN,
)
from datahub.ingestion.source.looker.looker_dataclasses import ProjectInclude
from datahub.ingestion.source.looker.looker_file_loader import LookerViewFileLoader
from datahub.ingestion.source.looker.looker_lib_wrapper import LookerAPI
Expand Down Expand Up @@ -204,6 +209,35 @@ def extract_project_from_imported_file_path(
return file_path.split("/")[1] or None


def lookml_file_path_from_link(lookml_link: Optional[str]) -> Optional[str]:
"""Repo-relative path from a LookML IDE link like "/projects/p/files/views%2Fa.view.lkml?line=3"."""
if not lookml_link:
return None
# Anchored on the link layout, so a project named "files" is not mistaken for the marker.
match = LOOKML_LINK_PATH_PATTERN.match(urlsplit(lookml_link).path)
return unquote(match[1]) if match else None


def https_repo_url_from_git_remote(remote: str) -> Optional[str]:
"""https URL of a scheme:// or user@host:path Git remote, without credentials or port; None if malformed."""
try:
if "://" in remote:
parts = urlsplit(remote)
host, path = parts.hostname, parts.path
else:
scp_match = GIT_SCP_REMOTE_PATTERN.match(remote)
if not scp_match:
return None
host, path = scp_match[1].lower(), scp_match[2]
except ValueError:
return None
repo_path = path.strip("/").removesuffix(".git")
# Needs at least owner/repo; never fall back to guessing a host.
if not host or "/" not in repo_path:
return None
return f"https://{host}/{repo_path}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The host is copied as-is, so real GitHub/GitLab remotes on alternate hosts are rejected by GitReference as unsupported: ssh://git@ssh.github.com:443/org/repo.git (GitHub's SSH-over-443), altssh.gitlab.com, www.github.com. Could we map those to github.com and gitlab.com here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 4b41156: ssh.github.com, www.github.com and altssh.gitlab.com now map to github.com / gitlab.com, with test cases.



@dataclass
class LookerViewId:
project_name: str
Expand Down Expand Up @@ -1064,6 +1098,8 @@ class LookerExplore:
join_definitions: Optional[List[LookerExploreJoin]] = None
fields: Optional[List[ViewField]] = None # the fields exposed in this explore
source_file: Optional[str] = None
# Repo-relative path of the defining file; the API's source_file is only the file name.
lookml_file_path: Optional[str] = None
tags: List[str] = dataclasses_field(default_factory=list)

@field_validator("name", mode="after")
Expand Down Expand Up @@ -1409,6 +1445,7 @@ def from_api( # noqa: C901
),
upstream_views_file_path=upstream_views_file_path,
source_file=explore.source_file,
lookml_file_path=lookml_file_path_from_link(explore.lookml_link),
tags=list(explore.tags) if explore.tags is not None else [],
join_definitions=join_definitions or None,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ class LookerDashboardSourceConfig(
description="Produce URLs used to render Looker Explores as Previews inside of DataHub UI. Embeds must be "
"enabled inside of Looker to use this feature.",
)
extract_explore_git_links: bool = Field(
False,
description="Add a 'View in Git' link to each Explore, pointing at the LookML file that defines it. "
"The repository and production branch come from the Explore's Looker project, so no Git settings are needed "
"in the recipe. Only GitHub and GitLab remotes are supported.",
)
stateful_ingestion: Optional[StatefulStaleMetadataRemovalConfig] = Field(
default=None, description=""
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

IMPORTED_PROJECTS = "imported_projects"
IMPORTED_PROJECTS_PREFIX = f"{IMPORTED_PROJECTS}/"
DIMENSIONS = "dimensions"
Expand All @@ -16,3 +18,16 @@
VIEW_FIELD_TYPE_ATTRIBUTE = "type"
VIEW_FIELD_INTERVALS_ATTRIBUTE = "intervals"
VIEW_FIELD_TIMEFRAMES_ATTRIBUTE = "timeframes"

# Identifies the links the looker source manages on Explores: links with this label are
# replaced or removed on each run, so changing it would orphan links already written.
EXPLORE_GIT_LINK_LABEL = "View in Git"
# Reading an Explore's links failed with a bad token (401) or throttling (429): it would
# fail for every Explore, so link reads stop for the run instead of skipping one Explore.
EXPLORE_GIT_LINK_RUN_WIDE_HTTP_STATUSES = frozenset({401, 429})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: 403 behaves run-wide in practice too. A DataHub token without dataset read privilege gets 403 on every Explore, so a big instance makes one failing read and adds one warning context per Explore. Consider adding 403 here, or stopping after a few consecutive 403s.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The aspect GET checks READ against the specific URN (AspectResource → isAPIAuthorizedEntityUrns(..., List.of(urn))), and policy resource filters can match on the entity's URN, tag, domain, container, owner or platform instance, so a 403 can be about one Explore. Making it run-wide would let one restricted Explore turn off links for all the others. When the token is denied everywhere, the report still shows a single warning entry (contexts are a capped LossyList), and 403s aren't retried, so each read fails fast.

# Looker's default when a project has no production branch configured.
LOOKER_DEFAULT_GIT_BRANCH = "master"
# LookML IDE link path: /projects/<project>/files/<url-encoded repo path>
LOOKML_LINK_PATH_PATTERN = re.compile(r"^/projects/[^/]+/files/(.+)$")
# SCP-style SSH remotes like git@github.com:org/repo.git
GIT_SCP_REMOTE_PATTERN = re.compile(r"^[^@/]+@([^:/]+):(.+)$")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: git also accepts SCP remotes without a user (github.com:org/repo.git), which this pattern reports as malformed. ^(?:[^@/]+@)?([^:/]+):(.+)$ would accept them, and the owner/repo check later still applies.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 4b41156, with one change to the suggested pattern: ^(?:[^@/]+@)?([^:/@]+):([^@]+)$. With ([^:/]+):(.+), a credential remote missing its scheme (user:token@github.com/org/repo) parses with user as the host and the token in the path, and the "Unsupported Git host" warning then echoes it. Excluding @ after the optional user keeps that case malformed; GitHub and GitLab repo paths can't contain @. Added test cases for the user-less form and for the credential case.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
LookmlModel,
LookmlModelExplore,
LookWithQuery,
Project,
Query,
User,
WriteQuery,
Expand Down Expand Up @@ -120,6 +121,7 @@ class LookerAPIStats(BaseModel):
search_dashboards_calls: int = 0
all_user_calls: int = 0
generate_sql_query_calls: int = 0
project_calls: int = 0


class _DataHubLookerApiSettings(looker_api_settings.ApiSettings):
Expand Down Expand Up @@ -316,6 +318,16 @@ def lookml_model_explore(
transport_options=self.transport_options,
)

def project(self, project_id: str) -> Project:
self.client_stats.project_calls += 1
return self.client.project(
project_id,
fields=self.__fields_mapper(
["git_remote_url", "git_production_branch_name"]
),
transport_options=self.transport_options,
)

@lru_cache(maxsize=1000)
def folder_ancestors(
self,
Expand Down
Loading
Loading