sqlmesh-observability 0.1.0a2__tar.gz → 0.1.0a3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. sqlmesh_observability-0.1.0a3/.github/workflows/ci.yml +67 -0
  2. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/.github/workflows/release.yml +2 -0
  3. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/AGENTS.md +4 -2
  4. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/CONTRIBUTING.md +7 -1
  5. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/PKG-INFO +3 -1
  6. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/docs/index.md +3 -0
  7. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/docs/limitations.md +4 -0
  8. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/docs/report.md +31 -3
  9. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/pyproject.toml +3 -0
  10. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/scripts/build_demo.py +16 -1
  11. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/payload.py +56 -1
  12. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/reader.py +57 -7
  13. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/report.py +19 -4
  14. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/web/report.css +33 -0
  15. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/web/report.js +400 -9
  16. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability.egg-info/PKG-INFO +3 -1
  17. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability.egg-info/SOURCES.txt +3 -0
  18. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability.egg-info/requires.txt +4 -0
  19. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability.egg-info/scm_file_list.json +3 -0
  20. sqlmesh_observability-0.1.0a3/src/sqlmesh_observability.egg-info/scm_version.json +8 -0
  21. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/tests/scale_fixture.py +27 -0
  22. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/tests/test_e2e.py +9 -0
  23. sqlmesh_observability-0.1.0a3/tests/test_lineage.py +127 -0
  24. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/tests/test_package.py +1 -1
  25. sqlmesh_observability-0.1.0a3/tests/test_report_browser.py +299 -0
  26. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/tests/test_report_data.py +75 -1
  27. sqlmesh_observability-0.1.0a2/src/sqlmesh_observability.egg-info/scm_version.json +0 -8
  28. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/.github/workflows/docs.yml +0 -0
  29. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/.gitignore +0 -0
  30. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/LICENSE +0 -0
  31. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/NOTICE +0 -0
  32. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/README.md +0 -0
  33. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/docs/alerts.md +0 -0
  34. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/docs/audits.md +0 -0
  35. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/docs/cli.md +0 -0
  36. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/docs/configuration.md +0 -0
  37. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/docs/getting-started.md +0 -0
  38. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/docs/how-it-works.md +0 -0
  39. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/docs/monitors.md +0 -0
  40. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/docs/verification.md +0 -0
  41. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/docs/warehouse-tables.md +0 -0
  42. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/mkdocs.yml +0 -0
  43. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/scripts/ci.sh +0 -0
  44. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/scripts/test-against-sqlmesh-main.sh +0 -0
  45. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/setup.cfg +0 -0
  46. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/__init__.py +0 -0
  47. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/alerts.py +0 -0
  48. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/app.py +0 -0
  49. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/audits/__init__.py +0 -0
  50. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/audits/column_anomaly.sql +0 -0
  51. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/audits/freshness_anomaly.sql +0 -0
  52. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/audits/macros.py +0 -0
  53. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/audits/volume_anomaly.sql +0 -0
  54. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/cli.py +0 -0
  55. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/collector.py +0 -0
  56. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/hook.py +0 -0
  57. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/monitors.py +0 -0
  58. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/textfmt.py +0 -0
  59. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability/writer.py +0 -0
  60. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability.egg-info/dependency_links.txt +0 -0
  61. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability.egg-info/entry_points.txt +0 -0
  62. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/src/sqlmesh_observability.egg-info/top_level.txt +0 -0
  63. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/tests/conftest.py +0 -0
  64. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/tests/test_alerts.py +0 -0
  65. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/tests/test_anomaly_audits.py +0 -0
  66. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/tests/test_app.py +0 -0
  67. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/tests/test_column_monitors.py +0 -0
  68. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/tests/test_install.py +0 -0
  69. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/tests/test_passive_monitors.py +0 -0
  70. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/tests/test_report.py +0 -0
  71. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/tests/test_report_ui.py +0 -0
  72. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/tests/test_sqlmesh_contract.py +0 -0
  73. {sqlmesh_observability-0.1.0a2 → sqlmesh_observability-0.1.0a3}/tests/test_warehouse_log.py +0 -0
@@ -0,0 +1,67 @@
1
+ name: ci
2
+
3
+ # Lint, types, and tests on every push and pull request. SQLMesh is installed normally (not
4
+ # editable), so mypy sees its type hints, which an editable local checkout hides. Sign-off on pull
5
+ # requests is checked by the DCO GitHub App, not here.
6
+ on:
7
+ push:
8
+ branches: [main]
9
+ pull_request:
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ concurrency:
15
+ group: ci-${{ github.ref }}
16
+ cancel-in-progress: true
17
+
18
+ env:
19
+ # The execution-observation API is not in a SQLMesh release yet; pin a tested main commit
20
+ # (the same one the docs and release workflows use).
21
+ SQLMESH_REF: 3df452cc9f47a435439cda087c3a419a1778b2b9
22
+ SQLMESH__DISABLE_ANONYMIZED_ANALYTICS: "1"
23
+ REQUIRE_BROWSER_TESTS: "1" # fail, don't skip, if Chromium is missing
24
+
25
+ jobs:
26
+ checks:
27
+ runs-on: ubuntu-24.04
28
+ steps:
29
+ - uses: actions/checkout@v7
30
+ with:
31
+ fetch-depth: 0 # setuptools_scm reads the version from git history
32
+
33
+ - uses: actions/setup-python@v7
34
+ with:
35
+ python-version: "3.12"
36
+
37
+ - name: Install
38
+ run: |
39
+ python -m pip install --upgrade pip
40
+ python -m pip install "sqlmesh @ git+https://github.com/SQLMesh/sqlmesh@${SQLMESH_REF}"
41
+ python -m pip install -e ".[dev]"
42
+ python -m playwright install --with-deps chromium # tests/test_report_browser.py
43
+
44
+ - name: Guard rails
45
+ run: |
46
+ ! grep -rn "set_console" src/ || { echo "src/ must not call set_console"; exit 1; }
47
+ ! grep -rn "sqlmesh.materializations" src/ || { echo "src/ must not patch materializations"; exit 1; }
48
+
49
+ - name: Lint
50
+ run: |
51
+ ruff check src tests scripts
52
+ ruff format --check src tests scripts
53
+
54
+ - name: Type check
55
+ run: mypy src
56
+
57
+ - name: Python 3.9 syntax
58
+ run: |
59
+ python - <<'EOF'
60
+ import ast, pathlib
61
+ for path in sorted(pathlib.Path("src").rglob("*.py")):
62
+ ast.parse(path.read_text(), str(path), feature_version=(3, 9))
63
+ EOF
64
+
65
+ - name: Test
66
+ run: pytest -q -p no:warnings
67
+
@@ -16,6 +16,7 @@ env:
16
16
  # main commit as the docs site.
17
17
  SQLMESH_REF: 3df452cc9f47a435439cda087c3a419a1778b2b9
18
18
  SQLMESH__DISABLE_ANONYMIZED_ANALYTICS: "1"
19
+ REQUIRE_BROWSER_TESTS: "1" # fail, don't skip, if Chromium is missing
19
20
 
20
21
  jobs:
21
22
  test:
@@ -34,6 +35,7 @@ jobs:
34
35
  python -m pip install --upgrade pip
35
36
  python -m pip install "sqlmesh @ git+https://github.com/SQLMesh/sqlmesh@${SQLMESH_REF}"
36
37
  python -m pip install -e ".[dev]"
38
+ python -m playwright install --with-deps chromium # tests/test_report_browser.py
37
39
 
38
40
  - name: Lint
39
41
  run: |
@@ -87,8 +87,9 @@ scripts/ ci.sh (every check), build_demo.py (the site's demo report)
87
87
  change breaks it, fix the package or the contract test deliberately, never silently.
88
88
  - Keep `tests/test_e2e.py` passing: the warehouse log, report, app, and alerts must agree on one
89
89
  history.
90
- - Report tests check the decoded payload and the HTML fallback. Drawing happens in the browser:
91
- check it against `python scripts/build_demo.py --synthetic 1500 out.html`. Payload changes
90
+ - Report tests check the decoded payload and the HTML fallback. What the browser draws is
91
+ tested by `tests/test_report_browser.py` (Playwright, headless Chromium); a change to
92
+ `web/report.js` needs a browser test, and the suite must pass with no console errors. Payload changes
92
93
  bump `SCHEMA_VERSION` in `payload.py` and `report.js` together, and the 1,500-model page must
93
94
  stay under the size budget in `tests/test_report_data.py`.
94
95
 
@@ -98,6 +99,7 @@ scripts/ ci.sh (every check), build_demo.py (the site's demo report)
98
99
  pip install -e ".[dev]" # development install
99
100
  scripts/ci.sh # every check a change must pass
100
101
  pytest tests/test_report.py -q # one file
102
+ python -m playwright install chromium # once, for tests/test_report_browser.py
101
103
  python scripts/build_demo.py out.html # build the demo report locally
102
104
  pip install -e ".[docs]" && mkdocs serve # preview the docs site
103
105
  ```
@@ -19,16 +19,22 @@ git config commit.gpgsign true
19
19
  git commit -S -s -m "..."
20
20
  ```
21
21
 
22
- The hosted repository will enforce this with branch protection ("Require signed commits") and a DCO check on pull requests.
22
+ The [DCO GitHub App](https://github.com/apps/dco) fails a pull request when any of its commits has no `Signed-off-by:` line. Cryptographic signing is not enforced yet.
23
23
 
24
24
  ## Development
25
25
 
26
26
  ```bash
27
27
  python -m venv .venv && source .venv/bin/activate
28
28
  pip install -e ".[dev]"
29
+ python -m playwright install chromium # for the report's browser tests
29
30
  scripts/ci.sh # lint, format, types, Python 3.9 syntax, and tests
30
31
  ```
31
32
 
33
+ `tests/test_report_browser.py` opens generated reports in headless Chromium and checks what the
34
+ page draws: every view, filters from the URL, the model tree, long lists, expanding a row to its
35
+ chart, the theme switch, and phone widths. Without Playwright's Chromium these tests skip; CI
36
+ installs it and fails if they are skipped.
37
+
32
38
  To test against an unreleased SQLMesh, install a local checkout first
33
39
  (`pip install -e /path/to/sqlmesh -e ".[dev]"`); `scripts/test-against-sqlmesh-main.sh` runs the
34
40
  suite against SQLMesh `main`.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlmesh-observability
3
- Version: 0.1.0a2
3
+ Version: 0.1.0a3
4
4
  Summary: Elementary-style data observability for SQLMesh projects
5
5
  License-Expression: Apache-2.0
6
6
  Requires-Python: >=3.9
@@ -22,6 +22,8 @@ Requires-Dist: sqlmesh[web]; extra == "dev"
22
22
  Requires-Dist: ruff; extra == "dev"
23
23
  Requires-Dist: starlette>=0.27; extra == "dev"
24
24
  Requires-Dist: uvicorn>=0.22; extra == "dev"
25
+ Requires-Dist: playwright>=1.49; python_version >= "3.10" and extra == "dev"
26
+ Requires-Dist: pytest-playwright>=0.6; python_version >= "3.10" and extra == "dev"
25
27
  Dynamic: license-file
26
28
 
27
29
  # sqlmesh-observability
@@ -37,6 +37,9 @@ The [demo report](demo/index.html) is rebuilt from the current code on every cha
37
37
  4. A new `payments` model fails its blocking `not_null` audit, so prod is not promoted. The
38
38
  report still shows the failure, with sample rows.
39
39
 
40
+ `raw.orders` is declared as an external model feeding `orders`, which feeds `daily_revenue` and
41
+ `payments`, so the Lineage tab has a small graph to show.
42
+
40
43
  The [1,500-model demo](demo/scale.html) shows the report at scale: seeded data for 1,500 models
41
44
  across 15 schemas and 20 owners, with 90 days of history cut to the latest 30 intervals.
42
45
 
@@ -23,4 +23,8 @@
23
23
  there is no date-range picker.
24
24
  - **Time zones.** Audit day buckets use the warehouse session time zone. Freshness compares
25
25
  naive timestamps with SQLMesh's UTC execution time.
26
+ - **Lineage is model-level.** For column-level lineage use SQLMesh's VS Code extension, which
27
+ loads the project. Tables SQLMesh doesn't know
28
+ as models (undeclared raw tables) don't appear. Declare them as external models to see them.
29
+ Lineage needs SQLMesh state; when state can't be read, the Lineage view says so.
26
30
  - **Alerts:** see [Alerts, things to know](alerts.md#things-to-know).
@@ -42,8 +42,9 @@ warnings, green for passing. Every colored mark also has a text label.
42
42
  | View | Shows |
43
43
  | --- | --- |
44
44
  | Dashboard | The environment's status, three summaries (audit results, model health, monitored models), one count per signal split into pass, warn, and fail, daily trends, and the open issues: blocking failures and errors, then latest-interval anomalies, then non-blocking failures. |
45
- | Models | Every model with its status, owner, recent interval health, failing audits, anomalies, and latest interval. |
46
- | Model page | Owner, version, interval health, a chart for run duration and for each metric with its expected band and anomaly markers, columns, schema changes, and audit history. |
45
+ | Models | Every model with its status, owner, recent interval health, failing audits, anomalies, downstream count, and latest interval. |
46
+ | Model page | Owner, version, downstream count, interval health, a chart for run duration and for each metric with its expected band and anomaly markers, its direct upstream and downstream models, columns, schema changes, and audit history. |
47
+ | Lineage | One model's upstream and downstream models as a graph, or the Impact list of models with open issues by how many models they affect. See [Lineage](#lineage). |
47
48
  | Test results | Each audit's latest interval by default, or every interval. |
48
49
  | Incidents | Every failed audit in scope. |
49
50
  | Runs | Recent plans and runs, with counts and durations. |
@@ -66,6 +67,33 @@ promoted.
66
67
  Filters are kept in the page address, so a link such as
67
68
  `report.html#models?status=fail&owner=team-03` opens with them applied.
68
69
 
70
+ ## Lineage
71
+
72
+ Lineage comes from SQLMesh state: each snapshot in the environment records the models it reads.
73
+ That includes external models declared in the project and new models whose plan was stopped
74
+ before promotion. The report never loads your model files to get it.
75
+
76
+ The **Graph** shows one model with its upstream models to the left and downstream models to the
77
+ right. It opens on the model whose open issue affects the most downstream models. Click any
78
+ model to centre the graph on it.
79
+
80
+ - **Depth** (1, 2, 3, or all) sets how many levels to follow each way. The default is 2.
81
+ - **Direction** shows upstream, downstream, or both.
82
+ - **Issues only** keeps the chosen model and the models with failures or anomalies, and folds
83
+ the healthy models between them into one "N healthy models" step.
84
+
85
+ Each model's card shows its status, schema, kind, and owner, how many models are downstream of
86
+ it, and the names of its failed audits and anomalous metrics (or its latest interval when
87
+ healthy). External models have a dashed outline. A graph draws at most 150
88
+ models, and at most 20 in one column; the rest of a column folds into "+N more", which lists
89
+ them when clicked.
90
+
91
+ **Impact** lists every model with an open issue, sorted by how many models depend on it,
92
+ directly or further down. Expand a row to see those models. The open issues on the dashboard
93
+ and the models list show the same downstream count.
94
+
95
+ Without JavaScript, each open issue lists its direct downstream models.
96
+
69
97
  ## History window
70
98
 
71
99
  Each model's interval health, run durations, audit history, and metric charts keep the latest
@@ -126,7 +154,7 @@ Requests are handled one at a time. Each one reads the log and SQLMesh state aga
126
154
  ## The data format
127
155
 
128
156
  The JSON embedded in the page (and served at `/data.json`) carries a `schema_version`, currently
129
- `1`. A page that meets a version it doesn't know shows only the no-JavaScript summary. The fields
157
+ `2` (version 2 added lineage). A page that meets a version it doesn't know shows only the no-JavaScript summary. The fields
130
158
  are documented in `src/sqlmesh_observability/payload.py`; they may change before 1.0, and any
131
159
  change bumps `schema_version`.
132
160
 
@@ -36,6 +36,9 @@ dev = [
36
36
  "ruff",
37
37
  "starlette>=0.27",
38
38
  "uvicorn>=0.22",
39
+ # Browser tests for the report renderer (tests/test_report_browser.py); 3.10+ only.
40
+ "playwright>=1.49; python_version >= '3.10'",
41
+ "pytest-playwright>=0.6; python_version >= '3.10'",
39
42
  ]
40
43
 
41
44
  [project.scripts]
@@ -17,6 +17,9 @@ The history gives the report something to show:
17
17
  statuses, and a jump in average amount.
18
18
  - A forward-only change that adds a column to orders (a schema change).
19
19
  - A new payments model whose blocking audit fails, so prod is not promoted.
20
+
21
+ Lineage: ``raw.orders`` is declared as an external model and feeds ``analytics.orders``, which
22
+ feeds ``analytics.daily_revenue``; ``analytics.payments`` reads ``analytics.orders`` too.
20
23
  """
21
24
 
22
25
  from __future__ import annotations
@@ -78,6 +81,18 @@ def build(root: Path, output: Path) -> Path:
78
81
  (root / "models").mkdir(parents=True)
79
82
  (root / "config.py").write_text(CONFIG.replace("__DB__", repr(str(root / "demo.duckdb"))))
80
83
  copy_audits(root)
84
+ (root / "external_models.yaml").write_text(
85
+ "- name: raw.orders\n columns:\n ds: date\n id: int\n status: text\n"
86
+ " amount: double\n updated_at: timestamp\n"
87
+ )
88
+ _model(
89
+ root,
90
+ "analytics.daily_revenue",
91
+ "SELECT ds, COUNT(*) AS orders, SUM(amount) AS revenue FROM analytics.orders "
92
+ "WHERE ds BETWEEN @start_ds AND @end_ds GROUP BY ds",
93
+ "not_null(columns := (revenue))",
94
+ "finance-team",
95
+ )
81
96
  _model(root, "analytics.orders", ORDERS, ORDERS_AUDITS, "commerce-team")
82
97
  _model(
83
98
  root,
@@ -127,7 +142,7 @@ def build(root: Path, output: Path) -> Path:
127
142
  "analytics.payments",
128
143
  "SELECT CAST(@start_ds AS DATE) AS ds, "
129
144
  "CASE WHEN i % 4 = 0 THEN NULL ELSE i END AS payment_id, i * 1.5 AS amount "
130
- "FROM range(8) t(i)",
145
+ "FROM range(8) t(i) WHERE EXISTS (SELECT 1 FROM analytics.orders)",
131
146
  "not_null(columns := (payment_id))",
132
147
  "payments-team",
133
148
  )
@@ -33,6 +33,15 @@ Schema version 1::
33
33
  signals {audits, volume, freshness, schema, columns: {pass, warn, fail} | null}
34
34
  runs [{id, command, environment, status, started_at, finished_at, duration_ms,
35
35
  model_runs, failed_runs, audits, failing_audits, blocking_failures}]
36
+ lineage {extra: [model names], kinds: [kind names],
37
+ kind: [kind index or -1], parents: [[node indexes]], impact: [count]}
38
+
39
+ Lineage nodes ``0 .. len(models) - 1`` are ``models``; node ``len(models) + i`` is
40
+ ``extra[i]``, a model in the environment with no observability rows (an external source,
41
+ say). ``impact`` is the number of distinct models downstream of each node. Each issue
42
+ carries its model's ``impact``.
43
+
44
+ Version 2 added ``lineage`` and ``issues[].impact``.
36
45
 
37
46
  Codes: ``health`` 0 pass, 1 warn, 2 fail, 3 error, 4 skip. Audit ``status`` 0 pass, 1 fail,
38
47
  2 error, 3 skip. Point ``flags`` bit 1 anomaly, bit 2 error, bit 4 still training. Indexes are
@@ -42,6 +51,7 @@ Codes: ``health`` 0 pass, 1 warn, 2 fail, 3 error, 4 skip. Audit ``status`` 0 pa
42
51
  from __future__ import annotations
43
52
 
44
53
  import json
54
+ import logging
45
55
  import typing as t
46
56
 
47
57
  from sqlmesh_observability.reader import audit_key
@@ -55,7 +65,9 @@ if t.TYPE_CHECKING:
55
65
  ReportData,
56
66
  )
57
67
 
58
- SCHEMA_VERSION = 1
68
+ logger = logging.getLogger(__name__)
69
+
70
+ SCHEMA_VERSION = 2
59
71
  DEFAULT_HISTORY = 30
60
72
 
61
73
  _HEALTH = {"pass": 0, "warn": 1, "fail": 2, "error": 3, "skip": 4}
@@ -431,6 +443,10 @@ def build_payload(data: "ReportData", history: int = DEFAULT_HISTORY) -> t.Dict[
431
443
  for inv in data.invocations
432
444
  ],
433
445
  }
446
+ lineage = _lineage(data, model_index)
447
+ payload["lineage"] = lineage
448
+ for issue in issues:
449
+ issue["impact"] = lineage["impact"][issue["model"]] if issue["model"] >= 0 else 0
434
450
  # Tables last: everything above interned into them.
435
451
  payload["dates"] = list(tables.dates)
436
452
  payload["owners"] = list(tables.owners)
@@ -439,6 +455,45 @@ def build_payload(data: "ReportData", history: int = DEFAULT_HISTORY) -> t.Dict[
439
455
  return _sort_dates(payload)
440
456
 
441
457
 
458
+ def _lineage(data: "ReportData", model_index: t.Mapping[str, int]) -> t.Dict[str, t.Any]:
459
+ """Every model in the environment as one node table, with parents and downstream impact."""
460
+ index = dict(model_index)
461
+ extra = [n.model_name for n in data.lineage if n.model_name not in index]
462
+ for name in extra:
463
+ index[name] = len(index)
464
+ size = len(index)
465
+ kinds: t.Dict[str, int] = {}
466
+ kind = [-1] * size
467
+ parents: t.List[t.List[int]] = [[] for _ in range(size)]
468
+ children: t.List[t.List[int]] = [[] for _ in range(size)]
469
+ for node in data.lineage:
470
+ i = index[node.model_name]
471
+ if node.kind is not None:
472
+ kind[i] = kinds.setdefault(node.kind, len(kinds))
473
+ for parent in node.parents:
474
+ if parent in index:
475
+ parents[i].append(index[parent])
476
+ children[index[parent]].append(i)
477
+
478
+ from sqlmesh.utils.dag import DAG
479
+
480
+ impact = [0] * size
481
+ try:
482
+ dag: "DAG[int]" = DAG({i: set(p) for i, p in enumerate(parents)})
483
+ for i in range(size):
484
+ if children[i]:
485
+ impact[i] = len(dag.downstream(i))
486
+ except Exception: # SQLMesh's DAG refuses a cycle; state should never hold one
487
+ logger.debug("sqlmesh-observability: lineage has a cycle; impact counts off", exc_info=True)
488
+ return {
489
+ "extra": extra,
490
+ "kinds": list(kinds),
491
+ "kind": kind,
492
+ "parents": [sorted(p) for p in parents],
493
+ "impact": impact,
494
+ }
495
+
496
+
442
497
  def _audit_issue(
443
498
  audit: "AuditRecord",
444
499
  kind: str,
@@ -10,7 +10,7 @@ from __future__ import annotations
10
10
  import datetime
11
11
  import logging
12
12
  import typing as t
13
- from dataclasses import dataclass
13
+ from dataclasses import dataclass, field
14
14
  from pathlib import Path
15
15
 
16
16
  from sqlglot import exp
@@ -147,6 +147,15 @@ class SchemaChange:
147
147
  recorded_at: t.Optional[str]
148
148
 
149
149
 
150
+ @dataclass(frozen=True)
151
+ class LineageNode:
152
+ """One model in the environment's DAG, from SQLMesh state."""
153
+
154
+ model_name: str
155
+ kind: t.Optional[str] # SQLMesh model kind name, e.g. ``EXTERNAL`` or ``FULL``
156
+ parents: t.Tuple[str, ...] # model names
157
+
158
+
150
159
  @dataclass(frozen=True)
151
160
  class ModelReport:
152
161
  """Scoped audit history and state metadata for one model."""
@@ -186,6 +195,8 @@ class ReportData:
186
195
  invocations: t.Tuple["InvocationRecord", ...] = () # newest first
187
196
  # Passive monitors configured in install(): any of volume, freshness, schema, columns.
188
197
  monitors: t.Tuple[str, ...] = ()
198
+ # Every model in the environment with its parents, sorted by name. Empty without state.
199
+ lineage: t.Tuple[LineageNode, ...] = ()
189
200
 
190
201
 
191
202
  @dataclass(frozen=True)
@@ -194,6 +205,8 @@ class _StateSnapshotInfo:
194
205
  owners: t.Dict[str, t.Optional[str]]
195
206
  columns: t.Dict[str, t.Tuple[t.Tuple[str, str], ...]]
196
207
  gateway: t.Optional[str] = None
208
+ # model name -> (kind, parent model names)
209
+ lineage: t.Dict[str, t.Tuple[t.Optional[str], t.Tuple[str, ...]]] = field(default_factory=dict)
197
210
 
198
211
 
199
212
  def _fmt_ts(value: t.Any) -> t.Optional[str]:
@@ -327,7 +340,11 @@ def _read_state_from_gateway(
327
340
  if cols:
328
341
  columns[snapshot.name] = cols
329
342
  return _StateSnapshotInfo(
330
- active_versions=active_versions, owners=owners, columns=columns, gateway=gateway
343
+ active_versions=active_versions,
344
+ owners=owners,
345
+ columns=columns,
346
+ gateway=gateway,
347
+ lineage={snap.name: _lineage_entry(snap) for snap in env.snapshots},
331
348
  )
332
349
  except Exception:
333
350
  logger.debug(
@@ -352,6 +369,13 @@ def _prepare_for_fork() -> None:
352
369
  import pandas # noqa: F401
353
370
 
354
371
 
372
+ def _lineage_entry(snapshot: t.Any) -> t.Tuple[t.Optional[str], t.Tuple[str, ...]]:
373
+ """(kind name, parent model names) of a ``Snapshot`` or ``SnapshotTableInfo``."""
374
+ kind = getattr(snapshot, "model_kind_name", None)
375
+ parents = tuple(sorted({parent.name for parent in getattr(snapshot, "parents", ())}))
376
+ return (None if kind is None else str(getattr(kind, "value", kind)), parents)
377
+
378
+
355
379
  def _node_metadata(snapshot: t.Any) -> t.Tuple[t.Optional[str], t.Tuple[t.Tuple[str, str], ...]]:
356
380
  node = snapshot.node
357
381
  owner = getattr(node, "owner", None)
@@ -365,8 +389,13 @@ def _node_metadata(snapshot: t.Any) -> t.Tuple[t.Optional[str], t.Tuple[t.Tuple[
365
389
 
366
390
  def _hydrate_snapshots(
367
391
  config: "Config", gateway: str, wanted: t.Mapping[str, str]
368
- ) -> t.Tuple[t.Dict[str, t.Optional[str]], t.Dict[str, t.Tuple[t.Tuple[str, str], ...]]]:
369
- """Owner and columns for snapshots outside the environment, by ``{model_name: snapshot_id}``.
392
+ ) -> t.Tuple[
393
+ t.Dict[str, t.Optional[str]],
394
+ t.Dict[str, t.Tuple[t.Tuple[str, str], ...]],
395
+ t.Dict[str, t.Tuple[t.Optional[str], t.Tuple[str, ...]]],
396
+ ]:
397
+ """Owner, columns, and lineage for snapshots outside the environment, by
398
+ ``{model_name: snapshot_id}``.
370
399
 
371
400
  Read-only, through the state reader, with the same gateway order as the environment read.
372
401
  A plan that stops before promotion has already stored its snapshots in state.
@@ -376,8 +405,9 @@ def _hydrate_snapshots(
376
405
 
377
406
  owners: t.Dict[str, t.Optional[str]] = {}
378
407
  columns: t.Dict[str, t.Tuple[t.Tuple[str, str], ...]] = {}
408
+ lineage: t.Dict[str, t.Tuple[t.Optional[str], t.Tuple[str, ...]]] = {}
379
409
  if not wanted:
380
- return owners, columns
410
+ return owners, columns, lineage
381
411
  _prepare_for_fork()
382
412
  ids = [SnapshotId(name=name, identifier=identifier) for name, identifier in wanted.items()]
383
413
  candidates: t.List[str] = []
@@ -403,9 +433,10 @@ def _hydrate_snapshots(
403
433
  owners[snapshot.name] = owner
404
434
  if cols:
405
435
  columns[snapshot.name] = cols
436
+ lineage[snapshot.name] = _lineage_entry(snapshot)
406
437
  if snapshots:
407
438
  break
408
- return owners, columns
439
+ return owners, columns, lineage
409
440
 
410
441
 
411
442
  def _fetch_model_runs(
@@ -976,6 +1007,7 @@ def _build_report_data(
976
1007
  extra_columns: t.Optional[t.Mapping[str, t.Tuple[t.Tuple[str, str], ...]]] = None,
977
1008
  invocations: t.Sequence[InvocationRecord] = (),
978
1009
  monitors: t.Tuple[str, ...] = (),
1010
+ lineage: t.Tuple[LineageNode, ...] = (),
979
1011
  ) -> ReportData:
980
1012
  by_model: t.Dict[str, t.List[AuditRecord]] = {}
981
1013
  for record in records:
@@ -1071,6 +1103,21 @@ def _build_report_data(
1071
1103
  anomalies=tuple(anomalies),
1072
1104
  invocations=_with_counts(invocations, runs, records),
1073
1105
  monitors=monitors,
1106
+ lineage=lineage,
1107
+ )
1108
+
1109
+
1110
+ def _lineage_nodes(
1111
+ entries: t.Mapping[str, t.Tuple[t.Optional[str], t.Tuple[str, ...]]],
1112
+ ) -> t.Tuple[LineageNode, ...]:
1113
+ """Lineage nodes sorted by name. Parents outside the environment are dropped."""
1114
+ return tuple(
1115
+ LineageNode(
1116
+ model_name=name,
1117
+ kind=kind,
1118
+ parents=tuple(p for p in parents if p in entries and p != name),
1119
+ )
1120
+ for name, (kind, parents) in sorted(entries.items())
1074
1121
  )
1075
1122
 
1076
1123
 
@@ -1179,7 +1226,9 @@ def load_report_data_for(
1179
1226
  if record.snapshot_id and record.model_name not in wanted:
1180
1227
  wanted[record.model_name] = record.snapshot_id
1181
1228
  wanted = {name: sid for name, sid in wanted.items() if name not in known}
1182
- extra_owners, extra_columns = _hydrate_snapshots(config, resolved_gateway, wanted)
1229
+ extra_owners, extra_columns, extra_lineage = _hydrate_snapshots(
1230
+ config, resolved_gateway, wanted
1231
+ )
1183
1232
 
1184
1233
  return _build_report_data(
1185
1234
  hydrated,
@@ -1194,4 +1243,5 @@ def load_report_data_for(
1194
1243
  extra_columns=extra_columns,
1195
1244
  invocations=invocations,
1196
1245
  monitors=_configured_monitors(monitor_settings),
1246
+ lineage=_lineage_nodes({**(state_info.lineage if state_info else {}), **extra_lineage}),
1197
1247
  )
@@ -67,6 +67,20 @@ def _fallback(payload: t.Mapping[str, t.Any]) -> str:
67
67
  else:
68
68
  status = "Healthy"
69
69
 
70
+ lineage = payload["lineage"]
71
+ names = [m["n"] for m in models] + lineage["extra"]
72
+ children: t.Dict[int, t.List[int]] = {}
73
+ for child, parents in enumerate(lineage["parents"]):
74
+ for parent in parents:
75
+ children.setdefault(parent, []).append(child)
76
+
77
+ def downstream(model: int) -> str:
78
+ direct = sorted(names[c].replace('"', "") for c in children.get(model, []))
79
+ if not direct:
80
+ return "-"
81
+ shown = ", ".join(direct[:10])
82
+ return shown + (f", and {len(direct) - 10:,} more" if len(direct) > 10 else "")
83
+
70
84
  def row(issue: t.Mapping[str, t.Any]) -> str:
71
85
  model = models[issue["model"]]["n"].replace('"', "") if issue["model"] >= 0 else "-"
72
86
  if issue["kind"] == "anomaly":
@@ -81,15 +95,16 @@ def _fallback(payload: t.Mapping[str, t.Any]) -> str:
81
95
  return (
82
96
  f"<tr><td><code>{_esc(model)}</code></td><td><code>{_esc(signal)}</code></td>"
83
97
  f"<td>{_esc(issue['interval'] or '-')}</td><td>{_esc(value)}</td>"
84
- f"<td>{_esc(issue['kind'])}</td></tr>"
98
+ f"<td>{_esc(issue['kind'])}</td>"
99
+ f"<td>{_esc(downstream(issue['model']) if issue['model'] >= 0 else '-')}</td></tr>"
85
100
  )
86
101
 
87
102
  groups = []
88
103
  for group_id, title, kinds, empty in _GROUPS:
89
104
  rows = [row(i) for i in payload["issues"] if i["kind"] in kinds]
90
- body = "".join(rows) or f'<tr><td colspan="5" class="note">{_esc(empty)}</td></tr>'
105
+ body = "".join(rows) or f'<tr><td colspan="6" class="note">{_esc(empty)}</td></tr>'
91
106
  groups.append(
92
- f'<tbody id="{group_id}"><tr class="group-head"><td colspan="5">{_esc(title)} · '
107
+ f'<tbody id="{group_id}"><tr class="group-head"><td colspan="6">{_esc(title)} · '
93
108
  f"{len(rows)}</td></tr>{body}</tbody>"
94
109
  )
95
110
 
@@ -113,7 +128,7 @@ def _fallback(payload: t.Mapping[str, t.Any]) -> str:
113
128
  f"<li><strong>{len(payload['issues']):,}</strong>open issues</li>"
114
129
  f"<li><strong>{len(models):,}</strong>models</li></ul>"
115
130
  "<table><thead><tr><th>Model</th><th>Signal</th><th>Interval</th><th>Value</th>"
116
- f"<th>Severity</th></tr></thead>{''.join(groups)}</table>"
131
+ f"<th>Severity</th><th>Downstream</th></tr></thead>{''.join(groups)}</table>"
117
132
  '<p class="note">Turn on JavaScript to see model pages, test results, runs, and charts.'
118
133
  "</p></section></div>"
119
134
  )
@@ -312,6 +312,39 @@ pre.sql {
312
312
  .null { color: var(--t3); font-style: italic; }
313
313
  .detail-error { color: var(--red); white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; margin: 0 0 12px; }
314
314
 
315
+ /* Lineage */
316
+ .lineage-controls .seg { flex: none; }
317
+ .lineage-canvas { overflow: auto; max-height: 72vh; padding: 8px; background: var(--ground); border-radius: 0 0 8px 8px; }
318
+ .lineage-canvas svg { display: block; margin: 0 auto; }
319
+ .lineage .edge { fill: none; stroke: var(--seam-strong); stroke-width: 1.5; }
320
+ .lineage .node rect { fill: var(--panel); stroke: var(--seam); stroke-width: 1; }
321
+ .lineage a.node:hover rect, .lineage a.node:focus-visible rect { stroke: var(--blue); }
322
+ .lineage a.node:focus { outline: none; }
323
+ .lineage .node.focus rect { stroke: var(--series); stroke-width: 2; fill: var(--blue-bg); }
324
+ .lineage .node.external rect { stroke-dasharray: 4 3; fill: var(--raised); }
325
+ .lineage .node .name { fill: var(--t1); font: 600 12.5px var(--mono); }
326
+ .lineage .node .line { fill: var(--t2); font: 11.5px var(--sans); }
327
+ .lineage .node .line.meta, .lineage .node .line.muted { fill: var(--t3); }
328
+ .lineage .node .line.fail { fill: var(--red); font-weight: 600; }
329
+ .lineage .node .line.warn { fill: var(--amber); font-weight: 600; }
330
+ .lineage .node .impact { fill: var(--t3); font: 11.5px var(--sans); }
331
+ .lineage .node .dot { fill: var(--grey); }
332
+ .lineage .node .dot.pass { fill: var(--green-mark); } .lineage .node .dot.warn { fill: var(--amber-mark); }
333
+ .lineage .node .dot.fail { fill: var(--red-mark); }
334
+ .lineage .node.more, .lineage .node.step { cursor: pointer; }
335
+ .lineage .node.more rect, .lineage .node.step rect { fill: var(--raised); stroke-dasharray: 4 3; }
336
+ .lineage .node.more:hover rect, .lineage .node.step:hover rect, .lineage .node.more:focus-visible rect, .lineage .node.step:focus-visible rect { stroke: var(--blue); }
337
+ .lineage .node.more .name, .lineage .node.step .name { font: 600 12px var(--sans); fill: var(--t2); }
338
+ .lineage-more { border-top: 1px solid var(--seam); padding: 12px 16px; }
339
+ .lineage-more h3 { font-size: 13px; margin-bottom: 8px; }
340
+ .lineage-more ul, .impact-list { list-style: none; margin: 0; padding: 0; columns: 3 220px; column-gap: 20px; }
341
+ .lineage-more li, .impact-list li { display: flex; align-items: center; gap: 6px; padding: 2px 0; break-inside: avoid; }
342
+ .lineage-panel dl { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 8px 12px; margin: 0; }
343
+ .lineage-panel dt { color: var(--t3); }
344
+ .lineage-panel dd { margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
345
+ .chip-link { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 5px; background: var(--raised); color: var(--t1); }
346
+ a.chip-link:hover { text-decoration: none; background: var(--hover); }
347
+
315
348
  /* Jump search */
316
349
  .jump { position: relative; }
317
350
  .jump .field { width: 240px; }