Skip to content

Commit

Permalink
fix(ingest): better handling around sink errors (#9003)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheth2 authored Oct 25, 2023
1 parent 1c77bca commit 32f5dcb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
10 changes: 9 additions & 1 deletion metadata-ingestion/src/datahub/ingestion/run/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,15 @@ def run(self) -> None:
record_envelopes = self.extractor.get_records(wu)
for record_envelope in self.transform(record_envelopes):
if not self.dry_run:
self.sink.write_record_async(record_envelope, callback)
try:
self.sink.write_record_async(
record_envelope, callback
)
except Exception as e:
# In case the sink's error handling is bad, we still want to report the error.
self.sink.report.report_failure(
f"Failed to write record: {e}"
)

except RuntimeError:
raise
Expand Down
33 changes: 13 additions & 20 deletions metadata-ingestion/src/datahub/ingestion/sink/datahub_kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
MetadataChangeEvent,
MetadataChangeProposal,
)
from datahub.metadata.schema_classes import MetadataChangeProposalClass


class KafkaSinkConfig(KafkaEmitterConfig):
Expand Down Expand Up @@ -58,27 +57,21 @@ def write_record_async(
],
write_callback: WriteCallback,
) -> None:
record = record_envelope.record
if isinstance(record, MetadataChangeEvent):
self.emitter.emit_mce_async(
callback = _KafkaCallback(
self.report, record_envelope, write_callback
).kafka_callback
try:
record = record_envelope.record
self.emitter.emit(
record,
callback=_KafkaCallback(
self.report, record_envelope, write_callback
).kafka_callback,
)
elif isinstance(
record, (MetadataChangeProposalWrapper, MetadataChangeProposalClass)
):
self.emitter.emit_mcp_async(
record,
callback=_KafkaCallback(
self.report, record_envelope, write_callback
).kafka_callback,
)
else:
raise ValueError(
f"The datahub-kafka sink only supports MetadataChangeEvent/MetadataChangeProposal[Wrapper] classes, not {type(record)}"
callback=callback,
)
except Exception as err:
# In case we throw an exception while trying to emit the record,
# catch it and report the failure. This might happen if the schema
# registry is down or otherwise misconfigured, in which case we'd
# fail when serializing the record.
callback(err, f"Failed to write record: {err}")

def close(self) -> None:
self.emitter.flush()

0 comments on commit 32f5dcb

Please sign in to comment.