feat(sdk): support downstreams for metrics

Closed
AN
3d ago
+557-10

Summary

  • Add an opt-in set_upstream_metrics API on chart, dashboard, and dataset so they can write the consumer-owned upstreamMetrics aspect. Omitting it leaves existing edges alone; [] clears them. Metric URNs are rejected from dataset lineage setters.
  • Snowflake semantic views still emit no metric downstream edges. Semantic-view metadata names where a metric is defined, and that logical dataset is already the metric's upstream, so the reverse edge would be a dataset-metric cycle.

Related to CAT-3323.

Test plan

  • metadata-ingestion/tests/unit/sdk_v2/test_upstream_metrics.py covers omit, replace, clear, dedupe, and metric-URN rejection on chart and dataset upstreams
  • Existing chart, dashboard, and dataset SDK goldens stay unchanged
  • test_no_upstream_metrics_emitted_for_semantic_view asserts a table-bound metric still points at its logical dataset and no workunit carries upstreamMetrics
  • Confirm a chart upsert that omits upstream_metrics does not clear edges previously written by updateLineage

Made with Cursor


Summary by cubic

Adds an opt-in set_upstream_metrics API on chart, dashboard, and dataset entities so consumers can declare the metrics they read, stored on the upstreamMetrics aspect. Metric URNs are now rejected from dataset lineage setters to prevent accidental dataset–metric edges.

  • Omitting the argument leaves existing edges unchanged; [] emits an empty list that clears them on upsert.
  • Accepts metric URNs, Metric entities, or strings; validates input and dedupes before writing.
  • Dataset lineage setters (set_upstreams, set_input_datasets, add_input_dataset) on datasets, charts, and dashboards now raise when given a metric URN.
  • Snowflake semantic views still emit no metric downstream edges: their metadata names where a metric is defined, and a reverse edge would create a dataset–metric cycle.