feat: allow specify schemaRegistryTopicSuffixName (#17027)

* feat: allow specify schemaRegistryTopicSuffixName

* chore: use default value

* add comment

* fix doc
This commit is contained in:
Antoine Balliet 2024-07-15 17:35:01 +02:00 committed by GitHub
parent cd85fe4530
commit aeea2df86e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 2 deletions

View File

@ -75,6 +75,7 @@ class CommonBrokerSource(MessagingServiceSource, ABC):
): ):
super().__init__(config, metadata) super().__init__(config, metadata)
self.generate_sample_data = self.config.sourceConfig.config.generateSampleData self.generate_sample_data = self.config.sourceConfig.config.generateSampleData
self.service_connection = self.config.serviceConnection.root.config
self.admin_client = self.connection.admin_client self.admin_client = self.connection.admin_client
self.schema_registry_client = self.connection.schema_registry_client self.schema_registry_client = self.connection.schema_registry_client
self.context.processed_schemas = {} self.context.processed_schemas = {}
@ -236,15 +237,27 @@ class CommonBrokerSource(MessagingServiceSource, ABC):
return None return None
def _parse_topic_metadata(self, topic_name: str) -> Optional[Schema]: def _parse_topic_metadata(self, topic_name: str) -> Optional[Schema]:
# To find topic in artifact registry, dafault is "<topic_name>-value"
# But suffix can be overridden using schemaRegistryTopicSuffixName
topic_schema_registry_name = (
topic_name + self.service_connection.schemaRegistryTopicSuffixName
)
try: try:
if self.schema_registry_client: if self.schema_registry_client:
registered_schema = self.schema_registry_client.get_latest_version( registered_schema = self.schema_registry_client.get_latest_version(
topic_name + "-value" topic_schema_registry_name
) )
return registered_schema.schema return registered_schema.schema
except Exception as exc: except Exception as exc:
logger.debug(traceback.format_exc()) logger.debug(traceback.format_exc())
logger.warning(f"Failed to get schema for topic [{topic_name}]: {exc}") logger.warning(
(
f"Failed to get schema for topic [{topic_name}] "
f"(looking for {topic_schema_registry_name}) in registry: {exc}"
)
)
self.status.warning( self.status.warning(
topic_name, f"failed to get schema: {exc} for topic {topic_name}" topic_name, f"failed to get schema: {exc} for topic {topic_name}"
) )

View File

@ -82,6 +82,12 @@
"default": {}, "default": {},
"additionalProperties": true "additionalProperties": true
}, },
"schemaRegistryTopicSuffixName": {
"title": "Schema Registry Topic Suffix Name",
"description": "Schema Registry Topic Suffix Name. The suffix to be appended to the topic name to get topic schema from registry.",
"type": "string",
"default": "-value"
},
"schemaRegistrySSL": { "schemaRegistrySSL": {
"title": "Schema Registry SSL", "title": "Schema Registry SSL",
"description": "Schema Registry SSL Config. Configuration for enabling SSL for the Schema Registry connection.", "description": "Schema Registry SSL Config. Configuration for enabling SSL for the Schema Registry connection.",