Repository navigation
refactor(ingest): send MCEs as MCPs from the REST emitter and file source - #21356
aviraj-gour wants to merge 20 commits into
Conversation
❌ 3 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Smart test selectionpytest smoke testsMode: active. Only the selection below runs for the pytest smoke tests on this PR (applied:
Medium confidence: a wrong tag means tests are skipped, so check the tags above against what this PR touches. Selected scopes (36 files or classes, 130 tests)
Add the commit |
Connector Tests ResultsAll connector tests passed for commit To skip connector tests, add the Autogenerated by the connector-tests CI pipeline. |
7d5da50 to
9b8fa74
Compare
PR SummaryOverview REST emission no longer posts whole snapshots to Docs, examples, and goldens switch file-based recipes and samples from snapshot JSON to MCP records; Reviewed by Cursor Bugbot for commit 3922837. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9b8fa74. Configure here.
naeemdh
left a comment
There was a problem hiding this comment.
A few comments inline. One behavior change (empty-aspect MCEs in the file source) looks worth fixing or documenting before merge; the rest are minor.
| mce.proposedSnapshot.urn, | ||
| response.status_code, | ||
| ) | ||
| _warn_mce_deprecated() |
There was a problem hiding this comment.
nit: an MCE now gets the deprecation twice: as a DataHubDeprecationWarning (from emit() or the @deprecated on emit_mce) and again as this log line with the same text. One of the two is probably enough.
There was a problem hiding this comment.
Kept both on purpose. DataHubDeprecationWarning subclasses DeprecationWarning, which Python hides unless the caller is __main__, so library callers like the Airflow hook would get no notice without the log line. It's logged once per process, the same as DatahubKafkaEmitter.
32a43ee to
848be3f
Compare
naeemdh
left a comment
There was a problem hiding this comment.
Review: one thing worth settling before merge (the file source splitting an MCE into per-aspect writes, see file.py), plus three smaller notes. The emitter batching, conversion-failure handling, aspect filter and bootstrap rewrite look sound.
| self.config.aspect is None | ||
| or mcp.aspectName == self.config.aspect | ||
| ): | ||
| yield MetadataWorkUnit(f"{id}-{mcp.aspectName}", mcp=mcp) |
There was a problem hiding this comment.
One work unit per MCP means file → datahub-rest in SYNC/ASYNC now writes each aspect of an MCE as its own request. The timeline shows one change per aspect, and the MCE is no longer all-or-nothing. In ASYNC_BATCH mode the aspects can also fall into different batches.
The breaking-changes entry covers this, but timeline_test.py was moved from ingest_file_via_rest to graph_client.emit_mcps. That hides the behaviour change and drops the only e2e coverage of the file → rest path for these files.
Could we keep an MCE's MCPs together, e.g. one record per MCE that the sink sends with a single emit_mcps? If per-aspect is the intended trade-off, could we keep one smoke test on ingest_file_via_rest that asserts the per-aspect timeline?
There was a problem hiding this comment.
Per-aspect is the intended trade-off. The sink can already send an MCE as one emit_mcps batch, but only if the MCE itself reaches it, which is the old file-source behaviour this PR removes so that transformers and sinks see MCPs only. Keeping that grouping on MCPs would need a new record type that carries several MCPs, and I don't think that's worth it for an input we're deprecating. The file → rest path for MCE files is still covered end to end: data.json (loaded in conftest.py), cli_test_data.json, graph_data.json and schema_field_side_effect_data.json all go through ingest_file_via_rest. The timeline test moved to emit_mcps because it asserts how GMS diffs aspects, not how the file source groups them. I'd rather not add a smoke test that pins the per-aspect timeline of a deprecated path; the change is in breaking-changes.md.
| self.emitter.emit(record, emit_mode=emit_mode) | ||
| if isinstance(record, MetadataChangeEvent): | ||
| # Not emitter.emit(): that logs an MCE deprecation warning recipe users cannot act on. | ||
| self.emitter.emit_mcps(list(mcps_from_mce(record)), emit_mode=emit_mode) |
There was a problem hiding this comment.
Two small things here:
- In sink
ASYNCmode, MCE writes now follow_gms_emit_modeand become async in GMS, so a validation or DB error no longer shows in the run report. Before,/entities?action=ingestalways wrote synchronously. - An MCE with no aspects calls
emit_mcps([])and counts as a success with no warning.DatahubRestEmitter._emit_mcelogs a warning for the same input. Worth aself.report.warninghere so the record doesn't vanish silently.
There was a problem hiding this comment.
(1) That's the same behaviour sink ASYNC mode already has for MCPs, and it's in breaking-changes.md (REST emitter entry). (2) Fixed: the sink now logs and reports a warning for an MCE with no aspects and skips it, in every mode including ASYNC_BATCH.
| is_flag=True, | ||
| help="Deprecated and has no effect: MCEs are always converted into MCPs.", | ||
| ) | ||
| def metadata_file(json_file: str, rewrite: bool, unpack_mces: bool) -> None: |
There was a problem hiding this comment.
nit: --unpack-mces is now accepted and silently ignored. Could we print a short deprecation notice when it's passed, or mark the option hidden=True? Scripts that relied on the old --rewrite keeping the MCE format would then see why their output changed.
There was a problem hiding this comment.
Marked it deprecated=True, so click prints a notice when it's passed and the help shows "(DEPRECATED)". Scripts that relied on --rewrite keeping MCEs never passed this flag, so the breaking-changes entry is what covers them.
| def _emit_mce(self, mce: MetadataChangeEvent, emit_mode: EmitMode) -> None: | ||
| """Sends the MCE's aspects in one batch, which GMS stamps as one change unless an oversized MCE is split across requests.""" | ||
| # Deferred to break the cycle mcp_builder -> ingestion.api.workunit -> ingestion.api.common -> graph.client -> rest_emitter. | ||
| from datahub.emitter.mcp_builder import mcps_from_mce |
There was a problem hiding this comment.
nit: metadata-ingestion/AGENTS.md says imports always go at the top of the file. I see the cycle comment. mcps_from_mce only needs schema classes, so moving it (or a core helper) to a leaf module would let both rest_emitter and kafka_emitter import it at the top. Fine as a follow-up.
There was a problem hiding this comment.
Done in this PR: mcps_from_mce now lives in emitter/mcp.py and is imported at the top of both emitters and workunit.py; mcp_builder re-exports it.
naeemdh
left a comment
There was a problem hiding this comment.
Looks good overall; three small non-blocking nits inline.
| ) -> None: | ||
| # TODO: Add timing metrics | ||
| self.emitter.emit(record, emit_mode=emit_mode) | ||
| if isinstance(record, MetadataChangeEvent): |
There was a problem hiding this comment.
nit: when an MCE has no aspects, this branch reports a warning and returns normally, so _write_done_callback sees no exception and still calls report_record_written / on_success. With 10 MCEs of which 2 are empty, the report shows 2 skip warnings and 10 records written. Could the skip be tracked (e.g. a skipped counter, or a sentinel the done-callback checks) so total_records_written matches what was sent?
There was a problem hiding this comment.
Fixed in d060dc4: write_record_async now handles an MCE with no aspects before submitting it, in every mode. It logs and reports the warning, then acknowledges the record with on_success, as the Kafka sink does. Since it is never submitted, the done-callback does not run for it and total_records_written only counts what was sent.
| yield MetadataWorkUnit(id, mcp=obj) | ||
| else: | ||
| yield MetadataWorkUnit(id, mcp_raw=obj) | ||
| elif not obj.proposedSnapshot.aspects: |
There was a problem hiding this comment.
nit: this empty-MCE branch comes before the one that sets warned_mce, so a file whose MCEs all have no aspects never gets the "MetadataChangeEvents are deprecated" warning. Moving the once-per-file deprecation warning ahead of the empty-aspects check would cover any MCE in the file.
There was a problem hiding this comment.
Fixed in 8d547df: the once-per-file deprecation warning now comes before the empty-aspects check, so a file whose MCEs all have no aspects gets it too.
| report = mce_source.get_report() | ||
| summary = f"{report.events_produced} MCPs found - all valid" | ||
| for warning in report.warnings: | ||
| summary += f"\nWarning: {warning.message}: {warning.context}" |
There was a problem hiding this comment.
nit: StructuredLogEntry.context is a LossyList[str], so this prints e.g. Warning: ...: ['mce.json'] with brackets and quotes. Same for the failure line above (line 21). ', '.join(warning.context) would print the plain path.
There was a problem hiding this comment.
Fixed in 8d547df: both the warning and the failure line now print ', '.join(...context), so the output shows the plain path.
naeemdh
left a comment
There was a problem hiding this comment.
LGTM. Only the three non-blocking nits above.
…file Connectors now emit MCPs, so comments that said MCE were stale. `datahub check metadata-file` counts every record the file source produced, MCE or MCP, so it now reports "records found".
SQL sources no longer construct SqlWorkUnit, so their work unit iterables are plain MetadataWorkUnit. The class itself stays for custom sources that import or subclass it.
Every connector now emits MCPs, so the MCE branches in these test helpers never run and the MCE-shaped ignore_paths match nothing in the MCP-only goldens. The lookml hive check only inspected MCE snapshots, so it asserted nothing; it now reads the upstreamLineage MCPs and requires at least one.
Convert the 82 MCEs in bootstrap_mce.json to one MCP per aspect with expand_mces; the 21 records that were already MCPs are unchanged. The file holds the same (urn, aspect, systemMetadata) values in the same order, so loading it stores the same aspects; the run report now counts one record per aspect. Also delete an Azure AD golden no test reads and an example recipe that pointed at a file that does not exist.
The REST lineage example emits an UpstreamLineage MCP like its Kafka twin, the custom transformer PATCH example is a transform_aspect, and the file-ingestion JSON samples are MCPs. adding-source points new sources at MetadataChangeProposalWrapper and the SDK entity classes.
DataHubRestEmitter.emit() and emit_mce() now convert a MetadataChangeEvent with mcps_from_mce and emit each aspect through emit_mcp, so MCE input uses ingestProposal (or OpenAPI) and honours emit_mode instead of posting to /entities?action=ingest. Both warn with DataHubDeprecationWarning, and the deprecation is logged once per process. An MCE with no aspects emits nothing and logs a warning. The datahub-rest sink's SYNC/ASYNC path expands MCEs itself, like its ASYNC_BATCH path and the Kafka sink, so recipe users get no warning about emitter code they do not own. This mirrors the Kafka emitter change in #20962.
The file source turns each MetadataChangeEvent it reads into one MCP per aspect and reports one deprecation warning per file, so transformers and sinks only receive MCPs. Reading MCEs will be removed in a future release.
The file source reports an MCE with no aspects as a failure instead of dropping it, as the extractor did before MCEs were split in the source. Mark --unpack-mces as having no effect, complete the breaking-changes entries (PR links, check metadata-file, emit mode default, ASYNC sink errors), fix stale comments and docs, and tighten the file-source and REST emitter tests.
The REST emitter sent each aspect of an MCE as its own request, so GMS stamped them at different times and the timeline showed one change per aspect instead of one per MCE. emit(mce) and emit_mce now send the MCE's MCPs in one emit_mcps batch, as the old /entities?action=ingest call did. Inside an ingestion pipeline MCEs stay individual MCPs and the sink mode decides batching; breaking-changes.md notes the per-aspect timeline in the sink's SYNC and ASYNC modes. The timeline smoke test now uses MCP fixtures and writes each dataset version in one synchronous emit_mcps batch, keeping its assertions.
check metadata-file raised only the failure context, so an MCE with no aspects failed with just the file position. Include the failure message. Also note in breaking-changes.md that check metadata-file now counts MCPs and fails on an MCE with no aspects, and correct the import-cycle comment in the REST emitter.
The file source now turns MCEs into MCPs, so the `aspect` option can filter them like native MCP records instead of passing the whole MCE.
- The file source skips an MCE with no aspects with a report warning instead of failing the run, and gives each MCP from an MCE its own work unit id so failures name the aspect. - The datahub-rest sink sends an MCE's aspects as one emit_mcps batch in SYNC/ASYNC mode, matching DataHubRestEmitter. - datahub check metadata-file prints report warnings under its summary, so skipped records are visible.
- The file source catches errors from mcps_from_mce per record, so an MCE with an invalid URN is one report failure instead of stopping the file. - breaking-changes.md notes that MCE files sent through the datahub-rest sink in SYNC/ASYNC mode show one timeline change per aspect. - The aspect option and _emit_mce docstring describe MCE behaviour; a test covers emit(mce) over OpenAPI.
- MCE_DEPRECATION_MESSAGE and the once-per-process warn_mce_deprecated() live in generic_emitter, so the REST and Kafka emitters log it once between them instead of once each. - The datahub-rest sink explains why it unpacks MCEs itself instead of calling emitter.emit(). - Tests: the sink test builds the sink like its neighbours, and the empty-MCE test checks the warning names the record, not the file.
…ces, move mcps_from_mce to emitter.mcp
…mce from emitter.mcp The file source's empty-MCE warning now gives the URN as well as the record position. The file source, REST sink and serde tests import mcps_from_mce from its new home instead of the mcp_builder re-export. Adds tests for the REST emitter sending nothing for an MCE with no aspects, and for check metadata-file still accepting --unpack-mces.
…es and print plain report context A file whose MCEs all have no aspects now also gets the per-file deprecation warning. datahub check metadata-file joins report context instead of printing the LossyList repr.
An empty MCE used to be submitted to the executor, where it sent nothing but the done-callback still counted it in total_records_written. The sink now reports it as a warning and acknowledges it with on_success before submission, as the Kafka sink does, so it is not counted as written in any mode.
d060dc4 to
3922837
Compare

Summary
Connectors emit MCPs only. This PR turns the last two SDK entry points that still pass MetadataChangeEvents on into MCP-only paths, deprecates MCE input there, and clears out dead MCE code in tests, examples and docs. One commit per change, so it reviews best commit by commit.
refactor(ingest): describe MCP output in comments and check metadata-filerefactor(ingest/sql): drop SqlWorkUnit from return type hintstest(ingest): drop dead MCE branches from connector testsignore_pathsthat no golden reaches; the lookml lineage check was vacuous and now reads MCPupstreamLineagerefactor(ingest): store the bootstrap sample data as MCPsbootstrap_mce.jsonas 220 MCPsdocs(ingest): teach MCPs in examples and docsadding-source.md, file-source JSON samples, sphinx builder pagefix(ingest/rest): send MCEs as MCPs from the REST emitterdatahub-restsink expands MCEs itself inSYNC/ASYNC(ASYNC_BATCHalready did), so recipe users get no warningfix(ingest/file): read MCEs as MCPs in the file sourcefix(ingest/file): report MCEs without aspects and correct MCE docsfix(ingest): send an MCE's aspects as one batch from the REST emitteremit(mce)/emit_mcesend all aspects in oneingestProposalBatchrequest so GMS stamps them as one change; an oversized MCE is split across requests by the existing batch chunkingfix(ingest): show the reason in check metadata-file failuresdatahub check metadata-fileprints the failure message, not only its contextfix(ingest/file): apply the aspect filter to MCE-derived MCPsaspectoption filters the MCPs made from an MCE like native MCP recordsfix(ingest): skip MCEs without aspects and batch MCEs in the REST sinkdatahub-restsink sends an MCE as oneemit_mcpsbatch inSYNC/ASYNC;check metadata-filelists report warnings under its summaryfix(ingest/file): report an MCE that fails conversion and keep readingmcps_from_mcecannot convert (e.g. an invalid URN) is one report failure for that record instead of stopping the file; docs for the per-aspect timeline of MCE filesrefactor(ingest): share the MCE deprecation warning across emittersMCE_DEPRECATION_MESSAGEand the once-per-processwarn_mce_deprecated()move togeneric_emitter, so the REST and Kafka emitters log it once between themdocs(ingest): remove lineage example that duplicates lineage_emitter_mcpw_rest.pylineage_emitter_rest.py, which after the docs commit was the same aslineage_emitter_mcpw_rest.pyfix(ingest/file): title MCE report entries and drop --unpack-mces plumbingcheck metadata-fileno longer passesunpack_mces_into_mcpsto the extractorfix(ingest): report empty MCEs in the REST sink, deprecate --unpack-mces, move mcps_from_mce to emitter.mcpdatahub-restsink reports an MCE with no aspects as a warning and skips it in every mode;--unpack-mcesis marked deprecated;mcps_from_mcemoves todatahub.emitter.mcp, which drops the deferred imports in the Kafka emitter andMetadataWorkUnitfix(ingest): name the URN of skipped empty MCEs and import mcps_from_mce from emitter.mcpmcps_from_mcefrom its new home; tests for the REST emitter's empty-MCE path and for--unpack-mcesmcps_from_mcestays as the migration path. It now lives indatahub.emitter.mcp, which imports no ingestion code;datahub.emitter.mcp_builderre-exports it, so existing imports keep working.datahub check metadata-file --unpack-mceshas no effect and prints a deprecation notice. Builders,MetadataWorkUnit(mce=)and the MCE transformer branches are untouched here.Evidence
MetadataWorkUnit(mce=...)for MCE files;emit(mce)posted to/entities?action=ingest.After:
test_file_source_converts_mces_to_mcps: work units equalmcps_from_mceof each MCE, exactly one report warning naming only the MCE file. Fails without the file source change.test_file_source_skips_mce_without_aspects: no work units, no failures, one warning naming the record and its URN, andcheck metadata-fileprints it.test_file_source_reports_unconvertible_mce_and_continues: an MCE with an invalid URN is one failure and the next MCE is still read. Fails without the fix (the source raisedAssertionError).test_serde_to_jsonon MCE fixtures now checks withgolden_mces_as_mcps+fail_on_output_mces.test_rest_emitter.py(+6):emit(mce)makes oneingestProposalBatchrequest, or one OpenAPI request withopenapi_ingestionon, with the aspects in order andsystemMetadatacarried over, and an explicitemit_modewins over the default; deprecatedemit_mceuses the default emit mode; a failure reaches the callback and raises; the warning logs once per process; an MCE with no aspects sends no request.test_rest_sink.py: the sink sends an MCE as oneemit_mcpsbatch with the resolvedemit_mode, and reports and skips an MCE with no aspects in both the single and batch paths.test_check_metadata_file_accepts_deprecated_unpack_mces:check metadata-file --unpack-mcesstill runs.upstreamLineageis stripped from the output.remote_file_golden.jsonrewritten as MCPs; the same recipe run locally onmce_list.jsonproduces identical JSON.TestSetupRecordingfailures come from the recording extra not being installed); ruff and mypy clean on the changed files.test_remote.py,test_flink.py,test_s3.py,test_informix.py,test_snowplow.py::test_snowplow_iglu_autodiscovery.Merge Danger
Door: two-way
Revert restores the MCE paths; no stored data changes shape.
Blast Radius: SDK users
DatahubRestEmitter/DataHubGraph.emit(mce)oremit_mcenow gets a deprecation warning and sends the MCE's aspects as oneingestProposalBatchrequest that followsemit_mode(defaultSYNC_PRIMARY) instead of always writing synchronously; an empty MCE is not sent.datahub-restsink inSYNC/ASYNCmode send each MCE as one MCP batch, and skip an MCE with no aspects with a report warning; if GMS rejects one aspect, others from the same MCE may already be stored.filesource over MCE files: custom transformers that handle only MCEs stop seeing those records; afilesink downstream writes MCPs; with thedatahub-restsink inSYNC/ASYNCmode each aspect is its own request, so the timeline shows one change per aspect instead of one per MCE; an MCE with no aspects is skipped with a warning; an MCE that fails conversion is one failed record and the rest of the file is still read.docs/how/breaking-changes.md(Deprecations and Other notable changes).🤖 Generated with Claude Code