Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -1413,10 +1413,10 @@ def _emit_dataset(
mirror_lineage = self._build_catalog_lineage(topic)
if mirror_lineage is not None:
extra_aspects.append(mirror_lineage)

if self.source_config.external_url_base:
base_url = self.source_config.external_url_base.rstrip("/")
external_url = f"{base_url}/{dataset_name}"
# A Schema Registry subject is not addressable under a broker's topic path.
if self.source_config.external_url_base:
base_url = self.source_config.external_url_base.rstrip("/")
external_url = f"{base_url}/{dataset_name}"

domain_urn: Optional[str] = None
for domain, pattern in self.source_config.domain.items():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class KafkaSourceConfig(
)
external_url_base: Optional[str] = Field(
default=None,
description="Base URL for external platform (e.g. Aiven) where topics can be viewed. The topic name will be appended to this base URL.",
description="Base URL for external platform (e.g. Aiven) where topics can be viewed. The topic name will be appended to this base URL. Applied to topics only; Schema Registry subjects ingested with `ingest_schemas_as_entities` get no link.",
)
profiling: ProfilerConfig = Field(
default_factory=ProfilerConfig,
Expand Down
35 changes: 35 additions & 0 deletions metadata-ingestion/tests/unit/kafka/test_kafka_source_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,41 @@ def test_external_url_base_links_each_topic(
assert props.externalUrl == "https://console.example.com/topics/orders"


def test_external_url_base_skips_schema_subjects(
kafka_clients: KafkaClientMocks, make_kafka_source: SourceFactory
) -> None:
"""A subject is not addressable under a broker's topic path, so a topic URL
built for it would 404."""
kafka_clients.set_topics(["orders"])
kafka_clients.registry.return_value.get_subjects.return_value = ["orders-value"]
kafka_clients.registry.return_value.get_latest_version.return_value = RegisteredSchema(
schema_id=1,
guid=None,
schema=Schema(
schema_str='{"type":"record","name":"Order","fields":[{"name":"id","type":"string"}]}',
schema_type="AVRO",
),
subject="orders-value",
version=1,
)

source = make_kafka_source(
{
"external_url_base": "https://console.example.com/topics/",
"ingest_schemas_as_entities": True,
}
)
urls = {
props.name: props.externalUrl
for props in emitted_aspects(source, DatasetPropertiesClass)
}

assert urls == {
"orders": "https://console.example.com/topics/orders",
"orders-value": None,
}


def test_one_failing_topic_does_not_abort_the_run(
kafka_clients: KafkaClientMocks, make_kafka_source: SourceFactory
) -> None:
Expand Down
Loading