vibedata-airflow 0.2.0__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.
- vibedata_airflow-0.2.0/.gitignore +8 -0
- vibedata_airflow-0.2.0/CHANGELOG.md +21 -0
- vibedata_airflow-0.2.0/PKG-INFO +181 -0
- vibedata_airflow-0.2.0/README.md +168 -0
- vibedata_airflow-0.2.0/pyproject.toml +31 -0
- vibedata_airflow-0.2.0/src/vibedata_airflow/__init__.py +18 -0
- vibedata_airflow-0.2.0/src/vibedata_airflow/airflow_api.py +129 -0
- vibedata_airflow-0.2.0/src/vibedata_airflow/code_version.py +100 -0
- vibedata_airflow-0.2.0/src/vibedata_airflow/connections.py +82 -0
- vibedata_airflow-0.2.0/src/vibedata_airflow/correlation.py +52 -0
- vibedata_airflow-0.2.0/src/vibedata_airflow/dag.py +523 -0
- vibedata_airflow-0.2.0/src/vibedata_airflow/environment.py +219 -0
- vibedata_airflow-0.2.0/src/vibedata_airflow/probe.py +232 -0
- vibedata_airflow-0.2.0/src/vibedata_airflow/record.py +522 -0
- vibedata_airflow-0.2.0/src/vibedata_airflow/runtime.py +557 -0
- vibedata_airflow-0.2.0/src/vibedata_airflow/secret_readers.py +118 -0
- vibedata_airflow-0.2.0/src/vibedata_airflow/secrets_check.py +219 -0
- vibedata_airflow-0.2.0/src/vibedata_airflow/vd.py +23 -0
- vibedata_airflow-0.2.0/tests/conftest.py +130 -0
- vibedata_airflow-0.2.0/tests/test_airflow_api_hooks.py +155 -0
- vibedata_airflow-0.2.0/tests/test_code_version.py +107 -0
- vibedata_airflow-0.2.0/tests/test_correlation_and_connections.py +79 -0
- vibedata_airflow-0.2.0/tests/test_dag_wrapper.py +332 -0
- vibedata_airflow-0.2.0/tests/test_environment.py +95 -0
- vibedata_airflow-0.2.0/tests/test_package_imports.py +19 -0
- vibedata_airflow-0.2.0/tests/test_probe.py +175 -0
- vibedata_airflow-0.2.0/tests/test_real_airflow.py +103 -0
- vibedata_airflow-0.2.0/tests/test_real_airflow_hooks.py +125 -0
- vibedata_airflow-0.2.0/tests/test_real_airflow_run.py +288 -0
- vibedata_airflow-0.2.0/tests/test_record.py +332 -0
- vibedata_airflow-0.2.0/tests/test_record_platforms.py +359 -0
- vibedata_airflow-0.2.0/tests/test_runtime.py +548 -0
- vibedata_airflow-0.2.0/tests/test_secret_check_dag.py +229 -0
- vibedata_airflow-0.2.0/tests/test_secrets_check.py +386 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
The public API is what the package documents in its README and exports from `vibedata_airflow` (the `vd` namespace, `check_runtime_set`, `ProbeError`); everything else is internal. While the version is 0.x, a breaking change bumps the minor version.
|
|
4
|
+
|
|
5
|
+
## 0.2.0
|
|
6
|
+
|
|
7
|
+
- Run record on BigQuery (`BigQueryHook`), Fabric Warehouse (`OdbcHook`, Microsoft Entra over TDS) and Snowflake (`SnowflakeHook`) (VD-8681), with the immutability, schema check (`RecordSchemaError`, never altered), identifier validation and quoting the Redshift and Databricks writers have. `RECORD_SCHEMA_VERSION` is still 1; the tables have the same columns on every platform.
|
|
8
|
+
- `triggered_by` is the `user_id` of the run's `vd_trigger` conf object (`{user_id, intent_id, request_id}`), and NULL when there is none. **Breaking:** the 0.1 conf key `vd_triggered_by` is no longer read. `intent_id` and `request_id` are not recorded: the run row has no column for them.
|
|
9
|
+
- `vd.dag(..., secrets=[...])` and the `vd_secret_check` task: a worker read of each declared secret and of the Secret Store itself, before any workload task, failing the run with each unreadable secret named and no value shown. A sandbox DAG always gets the task. **Breaking:** `vd_secret_check` is a reserved task id, and a sandbox DAG whose Secret Store is AWS Secrets Manager, Google Secret Manager or Azure Key Vault now needs `secretStoreLocation` in `_vd_namespace.json`.
|
|
10
|
+
- A sandbox target may name `dataset` and `project` (BigQuery) where other platforms have `schema` and `database`.
|
|
11
|
+
- The probe requires the provider for `bigquery`, `fabric_warehouse` and `snowflake`.
|
|
12
|
+
- A Data Platform with no run-record dialect is still refused: `motherduck` and the Fabric Lakehouse have none. BigQuery, Fabric Warehouse and Snowflake have no connection mapping yet, so a dbt or dlt task on them is refused.
|
|
13
|
+
|
|
14
|
+
## 0.1.0
|
|
15
|
+
|
|
16
|
+
- First release (VD-8640): `vd.dag`, `vd.dbt_task`, `vd.dlt_task`, `vd.asset`, `vd.publish_readiness`, the run record (`vd_orchestration_runs`, `vd_orchestration_task_runs`, schema version 1) and the post-install runtime probe (`vd.probe_task`, `vd.probe_dag`, `python -m vibedata_airflow.probe`).
|
|
17
|
+
- Every run is stamped with a code version (the task's bundle, deploy file, Variable or content hash) because MWAA has no bundle version without a Git bundle.
|
|
18
|
+
- The run record is keyed by `(dag_id, run_id)` and a task row by `(dag_id, run_id, task_id, try_number)`; a record that cannot be written fails `vd_record_run` after two retries, including when the production audit-schema Variable is unset.
|
|
19
|
+
- The probe requires the Data Platform's adapter, dlt driver and provider packages by default.
|
|
20
|
+
- The dlt link from `audit_runs` back to a run needs `vibedata-dlt-core>=0.18.0`.
|
|
21
|
+
- Connection mappings for Databricks and Redshift; a Data Platform with no mapping is refused.
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: vibedata-airflow
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: VibeData helper for Airflow 3 DAGs that run dbt and dlt on the worker: a fail-closed DAG wrapper, dbt and dlt tasks, asset readiness, a run record tied to the code version, and a post-install runtime probe.
|
|
5
|
+
Author-email: Vibedata <eng@acceleratedata.ai>
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Requires-Dist: packaging>=24
|
|
9
|
+
Provides-Extra: dev
|
|
10
|
+
Requires-Dist: pytest-mock>=3.12; extra == 'dev'
|
|
11
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# vibedata-airflow
|
|
15
|
+
|
|
16
|
+
One helper for the Airflow 3 DAGs a Domain runs: dbt and dlt on the worker, a run record that ties every run to its code version, and a probe for the installed runtime set.
|
|
17
|
+
|
|
18
|
+
Pure Python. Airflow is the host environment's and is never installed by this package; every Airflow import is deferred, so the package (and its probe) imports where Airflow is absent. It makes no call to Studio at run time.
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from datetime import timedelta
|
|
22
|
+
from vibedata_airflow import vd
|
|
23
|
+
|
|
24
|
+
with vd.dag(
|
|
25
|
+
"orders_daily",
|
|
26
|
+
schedule="0 6 * * *", # cron literal, or [vd.asset("orders")]; honoured in production only
|
|
27
|
+
timezone="UTC",
|
|
28
|
+
backfill_from="2026-01-01", # the backfill start, and the start date (never pass start_date)
|
|
29
|
+
catchup=False,
|
|
30
|
+
max_active_runs=1,
|
|
31
|
+
retries=2,
|
|
32
|
+
retry_delay=timedelta(minutes=10),
|
|
33
|
+
execution_timeout=timedelta(hours=2),
|
|
34
|
+
owner="sales-data",
|
|
35
|
+
secrets=[
|
|
36
|
+
"sources.shopify.credentials.api_key"
|
|
37
|
+
], # read by the worker before any task runs
|
|
38
|
+
):
|
|
39
|
+
landed = vd.dlt_task("shopify_orders") # ingestion/shopify_orders_pipeline.py
|
|
40
|
+
built = vd.dbt_task(selector="orders_daily") # dbt build --selector orders_daily
|
|
41
|
+
vd.publish_readiness("orders", after=built) # asset event carrying the interval
|
|
42
|
+
landed >> built
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
An asset-scheduled consumer writes `schedule=[vd.asset("orders")]`.
|
|
46
|
+
|
|
47
|
+
## Public API
|
|
48
|
+
|
|
49
|
+
| Name | What it does |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| `vd.dag(dag_id, *, schedule, timezone, backfill_from, catchup, max_active_runs, retries, execution_timeout, owner, retry_delay=5m, pool=None, secrets=(), ...)` | The DAG, built for the environment it is in (below). The committed arguments are all required; `start_date` is derived from `backfill_from`. Adds the secret access-check task before every workload task (when it has one, below) and the run-record task after the DAG's last tasks. |
|
|
52
|
+
| `vd.dbt_task(selector, *, task_id=None, target="prod", project_dir=None, extra_args=())` | One task: `dbt build --selector <selector>`. Pushes a compact summary: the `invocation_id`, node counts by status, up to 50 failed node names. |
|
|
53
|
+
| `vd.dlt_task(pipeline, *, task_id=None, script=None, extra_args=())` | One task: runs the committed `ingestion/<pipeline>_pipeline.py`. Its summary carries no `load_id` (below). |
|
|
54
|
+
| `vd.asset(name)` | The Airflow `Asset` `vd://<domainKey>/<name>` (`vd://<domainKey>/<intentKey>/<name>` in a sandbox). The only way to name an asset. |
|
|
55
|
+
| `vd.publish_readiness(name, *, after=None)` | Emits an event on `vd.asset(name)` with the interval and run id as metadata, only when the run's data interval has closed; otherwise the task skips and no event exists. |
|
|
56
|
+
| `vd.probe_task(...)`, `vd.probe_dag(...)` | The post-install probe as a task, or as a manual-trigger DAG. Requires the Data Platform's packages by default. |
|
|
57
|
+
| `check_runtime_set(...)`, `python -m vibedata_airflow.probe` | The probe from code or a shell. |
|
|
58
|
+
|
|
59
|
+
## Environments and the fail-closed rule
|
|
60
|
+
|
|
61
|
+
The same committed file runs in a sandbox (one Intent's namespace of the Ephemeral Orchestrator) and in production. These inputs decide which, all read on the worker:
|
|
62
|
+
|
|
63
|
+
| Input | Where | Meaning |
|
|
64
|
+
| --- | --- | --- |
|
|
65
|
+
| `vd_domain.json` | beside the DAG file, committed | `domainKey`, and the `orchestratorKind`, `dataPlatformKind`, `secretStoreKind` |
|
|
66
|
+
| `VD_ORCH_ENVIRONMENT` | environment-wide process variable | `production` or `ephemeral`, set by the customer |
|
|
67
|
+
| `_vd_namespace.json` | beside the DAG file, written by a sandbox deploy only | `intentKey`, `target` (database, schema, catalog, project or dataset), `secretStoreLocation` |
|
|
68
|
+
| the Airflow Variable `vd_<domainKey>_secret_store` | production only, writable by environment admins | the Secret Store's location, read by the secret access check |
|
|
69
|
+
| the run's conf | sandbox: `vd_interval_start`, `vd_interval_end`, `LOAD__MODE`, `LOAD__ROWS`; both environments: `vd_trigger` | the interval and load bounds (sandbox only); who triggered the run (below) |
|
|
70
|
+
|
|
71
|
+
| Marker | Namespace file | Result |
|
|
72
|
+
| --- | --- | --- |
|
|
73
|
+
| `production` | absent | DAG id `vd_<domainKey>__<dag_id>`, the committed schedule, connection `vd_<domainKey>_platform`, no load bounds. The run record needs the Airflow Variable `vd_<domainKey>_audit_schema` (below) |
|
|
74
|
+
| `ephemeral` | present | `vd_<domainKey>__<intentKey>__<dag_id>`, schedule `None`, pool `vd_<domainKey>__<intentKey>`, connection `vd_<domainKey>_ephemeral`, the Intent's target and load bounds |
|
|
75
|
+
| anything else, `production` with a namespace file, an unreadable `vd_domain.json`, a Data Platform with no run-record dialect, a sandbox target that names no schema, or declared `secrets` on a Secret Store the worker does not read | either | schedule `None` and a `vd_guard` task that fails naming the inconsistency; every workload task also refuses to start, so nothing runs |
|
|
76
|
+
|
|
77
|
+
A guarded DAG's id is `vd_<domainKey>__invalid__<dag_id>`. The guard is decided from the deployed files and the marker alone; no Airflow Variable or Connection is read when a DAG is parsed. Nothing in the namespace file or the run's conf can change the committed schedule, connection or Domain key.
|
|
78
|
+
|
|
79
|
+
The task ids `vd_guard`, `vd_record_run`, `vd_runtime_probe` and `vd_secret_check` are reserved; a workload task that asks for one is refused when the DAG is parsed.
|
|
80
|
+
|
|
81
|
+
## Connections
|
|
82
|
+
|
|
83
|
+
A workload task's process gets the environment variables the committed dbt profile and dlt destination read, filled from the Airflow connection for the environment. The mapping is one row per Data Platform kind (`dataPlatformKind` in `vd_domain.json`): `redshift` and `databricks`. A kind with no row is refused with an error that lists the supported kinds. BigQuery, Fabric Warehouse and Snowflake have a run-record writer (below) but no connection row in this release, so a dbt or dlt task on them is refused there. Values go to the child process only and are never logged.
|
|
84
|
+
|
|
85
|
+
## The code version
|
|
86
|
+
|
|
87
|
+
Airflow has a bundle version only for a versioned (Git) DAG bundle; on MWAA and Composer it is `None`. The Task SDK's `dag_run` does not carry it at all, so the helper reads the task's own bundle (`ti.bundle_instance.version`), which a worker sets and `dag.test()` does not. Every run is stamped anyway, from the first source that has a value, and the record says which one:
|
|
88
|
+
|
|
89
|
+
| `code_version_source` | Source |
|
|
90
|
+
| --- | --- |
|
|
91
|
+
| `bundle` | `ti.bundle_instance.version`, when the worker's DAG bundle is versioned |
|
|
92
|
+
| `file` | `_vd_version.json` beside the DAG file: `{"codeVersion": "<git sha>"}`, written by the deploy step or the customer's CI |
|
|
93
|
+
| `variable` | the Airflow Variable `vd_<domainKey>_code_version` |
|
|
94
|
+
| `hash` | `sha256:` of the DAG file and everything beside it (the files the deploy writes are excluded), so a run is never unversioned. If a file cannot be read, `names-sha256:` of the file names stands in; if the directory cannot be listed, the constant `unreadable` |
|
|
95
|
+
|
|
96
|
+
A `hash` is a fingerprint to compare for equality, not a commit to look up.
|
|
97
|
+
|
|
98
|
+
## Correlation values
|
|
99
|
+
|
|
100
|
+
Every workload task's process gets `VD_ORCH_ITEM` (the DAG id as committed), `VD_ORCH_RUN_ID`, `VD_ORCH_TASK_ID`, `VD_ORCH_TRY`, `VD_ORCH_INTERVAL_START`, `VD_ORCH_INTERVAL_END` and `VD_ORCH_CODE_VERSION`, each mirrored as `DBT_ENV_CUSTOM_ENV_<name>` so dbt copies it into `run_results.json` `metadata.env`.
|
|
101
|
+
|
|
102
|
+
For dlt, the values reach the audit tables only with `vibedata-dlt-core>=0.18.0` in the environment: from that release `finalize` writes `orch_run_id`, `orch_task_id`, `orch_try` and the interval into `audit_runs`. An older dlt-core ignores them, and a dlt load then has no link to its run.
|
|
103
|
+
|
|
104
|
+
## The run record
|
|
105
|
+
|
|
106
|
+
The final task (`vd_record_run`, `trigger_rule="all_done"`) writes one row per run to `vd_orchestration_runs` and one row per task to `vd_orchestration_task_runs`, in the Domain's audit schema, through the Airflow provider hook for the Data Platform. The package carries no database driver.
|
|
107
|
+
|
|
108
|
+
| `dataPlatformKind` | Hook | Provider | Statement dialect |
|
|
109
|
+
| --- | --- | --- | --- |
|
|
110
|
+
| `redshift` | `RedshiftSQLHook` | `apache-airflow-providers-amazon` | `"` quoting, `VARCHAR(65535)`, backslash literals |
|
|
111
|
+
| `databricks` | `DatabricksSqlHook` | `apache-airflow-providers-databricks` | backtick quoting, `STRING`, backslash literals |
|
|
112
|
+
| `bigquery` | `BigQueryHook` (standard SQL) | `apache-airflow-providers-google` | backtick quoting, `STRING` / `INT64`, backslash-escaped literals; a project may be hyphenated |
|
|
113
|
+
| `fabric_warehouse` | `OdbcHook` | `apache-airflow-providers-odbc` | `"` quoting, `VARCHAR(8000)` / `DATETIME2(6)`, T-SQL literals, no `CREATE TABLE IF NOT EXISTS` |
|
|
114
|
+
| `snowflake` | `SnowflakeHook` | `apache-airflow-providers-snowflake` | unquoted validated names (folded to upper case), `VARCHAR` / `TIMESTAMP_NTZ`, backslash literals |
|
|
115
|
+
|
|
116
|
+
Platform notes:
|
|
117
|
+
|
|
118
|
+
- **Fabric Warehouse goes through the ODBC provider.** A Warehouse accepts TDS connections with Microsoft Entra authentication only: SQL authentication is not supported. `apache-airflow-providers-microsoft-mssql` opens its session with `pymssql`, which cannot authenticate to Entra, while the ODBC provider hands the connection's `Authentication=ActiveDirectoryServicePrincipal` (or any other Entra mode) to ODBC Driver 18, the driver dbt-fabric already needs on the worker. The hook is opened on the target's Warehouse (`database`) and given the driver explicitly: the provider ignores a `driver` in a connection's extra unless `[providers.odbc] allow_driver_in_extra` is set, and without one it opens no session, so the connection's `driver` is passed through, else `ODBC Driver 18 for SQL Server`. The package declares no driver; `pyodbc`, the driver manager and ODBC Driver 18 are the worker's. Fabric varchar is UTF-8 capped at 8000 bytes, which holds because the summary column is ASCII-only JSON. T-SQL has no `CREATE TABLE IF NOT EXISTS`, so the writer reads the catalog first and creates a table only when it is absent, and believes a failed create only if the table is still absent afterwards.
|
|
119
|
+
- **BigQuery's** hook defaults to legacy SQL, which has no DML and no `INFORMATION_SCHEMA`, so it is opened with `use_legacy_sql=False`. Its own `get_records` demands a location the record has no use for, so statements and reads both go through `run` and its PEP 249 cursor, one query job each, with the location BigQuery infers from the datasets the statement names. The target is `project.dataset` (`dataset` alone uses the connection's project); in a sandbox the namespace file's `dataset` and `project` stand where other platforms have `schema` and `database`.
|
|
120
|
+
- **Snowflake** folds an unquoted name to upper case and keeps a quoted one as written. A quoted lower-case `"vd_orchestration_runs"` would be invisible to every ordinary query, so the writer validates each part and leaves it unquoted, which is how every other Snowflake object is spelled. Statements are never split on `;`, because a summary can hold one inside a literal.
|
|
121
|
+
- **None of the three SQL surfaces was run against a live service in this release's tests.** The writer's statements run end to end on sqlite and the three hooks are exercised in CI's `airflow` job, but each platform's own parser, and the column-catalog queries, are checked by the platform matrix, not here.
|
|
122
|
+
|
|
123
|
+
- The run row: `item`, `dag_id`, `run_id`, `run_type`, `environment`, `intent_key`, `logical_date`, `interval_start`, `interval_end`, `code_version`, `code_version_source`, `status`, `triggered_by`, `airflow_user`, `trigger_assets`, `run_after`, `started_at`, `recorded_at`. The Task SDK gives a task no queue time, so none is recorded.
|
|
124
|
+
- A task row: `dag_id`, `run_id`, `item`, `task_id`, `try_number`, `state`, `child_kind`, `child_id`, `child_link`, `summary`. It is the task's **latest try** when the record is written: `try_number` and the summary come from the try that pushed last, and earlier tries of a retried task have no row. A task that pushed no summary has `try_number` 0, and a task whose state Airflow did not report has a NULL `state`.
|
|
125
|
+
- A dbt task row carries `child_kind` `invocation_id` and the id. A dlt task row carries no child id: the task cannot see the `load_id` the pipeline's process writes, so `child_id` is NULL and `child_link` names the `audit_runs` columns (`orch_run_id`, `orch_task_id`, `orch_try`) that find the load from this run's ids. That join exists only with `vibedata-dlt-core>=0.18.0`.
|
|
126
|
+
- Keys: a run is `(dag_id, run_id)`, because a scheduled `run_id` is derived from the time alone and two DAGs scheduled together share it; a task row is `(dag_id, run_id, task_id, try_number)`.
|
|
127
|
+
- `triggered_by` is the `user_id` of the `vd_trigger` object in the run's conf, which Studio writes (`{user_id, intent_id, request_id}`); a run with no `vd_trigger`, or one without a usable `user_id`, records NULL. 0.1 read `vd_triggered_by`; it is no longer read, because nothing writes it. The run row has no column for `intent_id` or `request_id` (its `intent_key` is the sandbox namespace's key, not Studio's Intent id), and adding one would change `RECORD_SCHEMA_VERSION`, so neither is recorded. On MWAA the Airflow user is per IAM role, so `airflow_user` names the role. The conf value is asserted by the trigger caller and is not authenticated by this package.
|
|
128
|
+
- Rows are immutable: each is inserted only if its key is absent (the warehouses enforce no uniqueness, so the key is held by the insert, not by a constraint). A table whose columns this version does not recognise is refused with `RecordSchemaError`, never altered. The shape is `RECORD_SCHEMA_VERSION`.
|
|
129
|
+
- The audit target in a sandbox is `target.auditSchema`, `target.schema` or `target.dataset` (BigQuery) from the namespace file, in its `target.catalog` (Databricks), `target.database` (Redshift, Snowflake, Fabric Warehouse) or `target.project` (BigQuery) when it names one. In production it is the Airflow Variable `vd_<domainKey>_audit_schema`, written `schema` or `catalog.schema` (`database.schema` on Redshift, Snowflake and Fabric Warehouse, `project.dataset` on BigQuery). Every part is validated and quoted. With a catalog, Databricks tables are `catalog.schema.table`, the column check reads `<catalog>.information_schema`, and the hook is opened on that catalog and schema (a Snowflake or Fabric Warehouse hook on that database); on Redshift the hook's session is opened on the named database, because Redshift refuses a write to a database other than the session's. Without one, the connection's own catalog or database is used.
|
|
130
|
+
- A record that cannot be written is a failed task, in production as in a sandbox: `vd_record_run` retries twice, one minute apart, and then fails, so the run is not green without its record. That includes a production `vd_<domainKey>_audit_schema` Variable that is unset or cannot be read: the Variable is read by `vd_record_run`, not when the DAG is parsed, so the workloads run and the record task fails. A run that fails before the record task, or whose record task fails, is found through the orchestrator's API, not in these tables.
|
|
131
|
+
- A summary is stored as JSON of at most 8,000 characters. One that is longer loses trailing failed node names (`failed_nodes_truncated`) and stays valid JSON.
|
|
132
|
+
- XCom carries ids and compact summaries only; never data, a cursor or a watermark.
|
|
133
|
+
|
|
134
|
+
## The secret access check
|
|
135
|
+
|
|
136
|
+
The worker reads a Domain's source secrets itself, as its own execution identity (the MWAA execution role, the Composer service account, the generic environment's identity), straight from the cloud secret manager and outside Studio's Credential Broker. Studio cannot act as that identity, so the proof is a read the worker makes before any dbt or dlt task runs. `vd.dag` adds a `vd_secret_check` task upstream of every workload task, and of `vd.publish_readiness`:
|
|
137
|
+
|
|
138
|
+
- **A sandbox on a Secret Store the worker reads has it whether or not it declares any secret**, because it also proves the worker can read the Domain's Secret Store at all (a sandbox on `none`, `local_toml`, a platform-native store or `studio_key_vault` gets none unless it declares secrets, and then the DAG is guarded). **Production has it only when `vd.dag(..., secrets=[...])` declares secrets**, so an existing production DAG gains no task.
|
|
139
|
+
- **`secrets` lists dotted dlt keys**, the names a pipeline reads (`sources.shopify.credentials.api_key`). The agent writes them from its dlt sources; `orch validate` is the static counterpart. Declared secrets on a Secret Store the worker does not read (`none`, `local_toml`, the platform-native stores, `studio_key_vault`) guard the DAG.
|
|
140
|
+
- **Each declared secret is read by name, and so is the store itself.** AWS Secrets Manager and Google Secret Manager: the customer-created sentinel (`<prefix>.studio/sentinel`, `<prefix>studio-sentinel`); a missing sentinel is a failure, because the sentinel read is how the grant is proved. Azure Key Vault: one `get` of a random name, where *not found* proves the grant and *forbidden* denies it, since a get-only grant cannot list.
|
|
141
|
+
- **The names the store holds are Studio's.** AWS: the name prefix from the ARN, then the dotted key as `/`-separated segments. Google: the injective codec (`_` to `_u`, `.` to `__`, `/` to `_s`) under the prefix. Azure: the key lower-cased, `.` as `--`, `_` as `-`.
|
|
142
|
+
- **Where the location comes from.** Sandbox: `secretStoreLocation` in `_vd_namespace.json`, so nothing a DAG author or a run's conf can edit decides which store a sandbox reads. Production: the Airflow Variable `vd_<domainKey>_secret_store`. The form is the kind's: AWS an ARN prefix ending in `/` (`arn:aws:secretsmanager:<region>:<account>:secret:<namePrefix>/`), Google `projects/<projectId>` or `projects/<projectId>/secrets/<namePrefix>`, Azure the vault URL.
|
|
143
|
+
- **The identity is the worker's own and the read is direct**: boto3's default credential chain, Google Application Default Credentials, `DefaultAzureCredential`, through the cloud's SDK, never an Airflow connection or the Airflow secrets backend. Airflow's Key Vault backend reports a refused read as *not found*, which would turn a denied grant into a pass. The package declares none of these SDKs. `boto3` (AWS) arrives with `apache-airflow-providers-amazon`, which an MWAA image carries, and `google-cloud-secret-manager` (Google) arrives with `apache-airflow-providers-google`, which the orchestration runtime set installs. Nothing in the runtime set installs the Azure SDK: for `azure_key_vault` the operator installs `azure-identity` and `azure-keyvault-secrets` (the orchestration constraints files already pin both), or `apache-airflow-providers-microsoft-azure`. A reader that cannot be built, because its SDK is absent or its credential setup fails, fails the check naming every declared secret and the store, with the original error.
|
|
144
|
+
- **It never prints a value.** A reader drops the value inside its own function and returns nothing, so no value reaches a log line, an exception or an XCom. A failure names each unreadable secret with the provider's own code and message: `the worker cannot read 2 Domain secret(s): sources.a.token (denied: AccessDeniedException: ...); ...`. Every name is tried, so one failure does not hide the next.
|
|
145
|
+
- It is a task, not a retry: `retries=0`, because a missing grant does not fix itself. A failed check leaves the workload tasks `upstream_failed`, and the run record still writes, with status `failed`.
|
|
146
|
+
|
|
147
|
+
## The post-install probe
|
|
148
|
+
|
|
149
|
+
MWAA reports a failed `requirements.txt` install as a successful environment update, so "Available" says nothing about what imports. The probe reads the installed distributions on the worker and fails when a required package is missing or, with a constraints file, off its pin.
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from vibedata_airflow import vd
|
|
153
|
+
|
|
154
|
+
probe = vd.probe_dag(
|
|
155
|
+
constraints_path="/usr/local/airflow/dags/orchestration-constraints.txt"
|
|
156
|
+
) # trigger after each update
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
python -m vibedata_airflow.probe --constraints orchestration-constraints.txt --platform databricks
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
The required set is `vibedata-airflow`, `vibedata-dlt-core`, `dbt-core`, `dlt` and `apache-airflow-providers-git`, plus the Data Platform's own packages:
|
|
164
|
+
|
|
165
|
+
| Data Platform | Also required |
|
|
166
|
+
| --- | --- |
|
|
167
|
+
| `databricks` | `dbt-databricks`, `databricks-sql-connector`, `databricks-sdk`, `apache-airflow-providers-databricks` |
|
|
168
|
+
| `redshift` | `dbt-redshift`, `psycopg2-binary`, `apache-airflow-providers-amazon` |
|
|
169
|
+
| `bigquery` | `apache-airflow-providers-google` |
|
|
170
|
+
| `fabric_warehouse` | `apache-airflow-providers-odbc` |
|
|
171
|
+
| `snowflake` | `apache-airflow-providers-snowflake` |
|
|
172
|
+
|
|
173
|
+
For `databricks` and `redshift` these are the dbt adapter, the drivers dlt's own extra declares (`dlt[databricks]`, `dlt[redshift]`) and the provider whose hook writes the run record. For `bigquery`, `fabric_warehouse` and `snowflake` only the provider is required: their dbt adapters are not in the orchestration runtime set, so requiring them would fail every environment built from it. `dbt-redshift` connects through `redshift-connector`, so it does not bring dlt's `psycopg2-binary` with it. An environment that installs the source build `psycopg2` instead passes `required=`.
|
|
174
|
+
|
|
175
|
+
`vd.probe_task()` and `vd.probe_dag()` take the platform from `platform_kind=`, else from `dataPlatformKind` in the `vd_domain.json` beside the calling file; the shell command takes `--platform`. With no platform named and no Domain file, only the core set is required, so name the platform wherever the file is absent. `required=` replaces the whole set and `--require` adds to it. A package the constraints name but is not required is checked when installed and reported when absent.
|
|
176
|
+
|
|
177
|
+
## Install
|
|
178
|
+
|
|
179
|
+
Install into the Airflow environment under `orchestration-constraints.txt`, so dbt, dlt and the adapters match the pins the Agent Server uses. That file is published from this repository's `constraints/` directory, which VD-8641 adds; it is not part of this package and does not exist before that change. The package itself declares only `packaging`, and expects Airflow, dbt, dlt and the providers from the host.
|
|
180
|
+
|
|
181
|
+
The unit tests run without Airflow. `tests/test_real_airflow.py` parses the DAG with real Airflow 3, `tests/test_real_airflow_run.py` runs the task bodies under `dag.test()`, and `tests/test_real_airflow_hooks.py` aims the Redshift, Snowflake, ODBC (Fabric Warehouse) and BigQuery hooks at a target; each skips where Airflow or its provider is absent, and CI's `airflow` job installs them and runs them. The Databricks hook, the cloud secret SDKs and every warehouse's SQL are not run against a live service in CI.
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# vibedata-airflow
|
|
2
|
+
|
|
3
|
+
One helper for the Airflow 3 DAGs a Domain runs: dbt and dlt on the worker, a run record that ties every run to its code version, and a probe for the installed runtime set.
|
|
4
|
+
|
|
5
|
+
Pure Python. Airflow is the host environment's and is never installed by this package; every Airflow import is deferred, so the package (and its probe) imports where Airflow is absent. It makes no call to Studio at run time.
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from datetime import timedelta
|
|
9
|
+
from vibedata_airflow import vd
|
|
10
|
+
|
|
11
|
+
with vd.dag(
|
|
12
|
+
"orders_daily",
|
|
13
|
+
schedule="0 6 * * *", # cron literal, or [vd.asset("orders")]; honoured in production only
|
|
14
|
+
timezone="UTC",
|
|
15
|
+
backfill_from="2026-01-01", # the backfill start, and the start date (never pass start_date)
|
|
16
|
+
catchup=False,
|
|
17
|
+
max_active_runs=1,
|
|
18
|
+
retries=2,
|
|
19
|
+
retry_delay=timedelta(minutes=10),
|
|
20
|
+
execution_timeout=timedelta(hours=2),
|
|
21
|
+
owner="sales-data",
|
|
22
|
+
secrets=[
|
|
23
|
+
"sources.shopify.credentials.api_key"
|
|
24
|
+
], # read by the worker before any task runs
|
|
25
|
+
):
|
|
26
|
+
landed = vd.dlt_task("shopify_orders") # ingestion/shopify_orders_pipeline.py
|
|
27
|
+
built = vd.dbt_task(selector="orders_daily") # dbt build --selector orders_daily
|
|
28
|
+
vd.publish_readiness("orders", after=built) # asset event carrying the interval
|
|
29
|
+
landed >> built
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
An asset-scheduled consumer writes `schedule=[vd.asset("orders")]`.
|
|
33
|
+
|
|
34
|
+
## Public API
|
|
35
|
+
|
|
36
|
+
| Name | What it does |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| `vd.dag(dag_id, *, schedule, timezone, backfill_from, catchup, max_active_runs, retries, execution_timeout, owner, retry_delay=5m, pool=None, secrets=(), ...)` | The DAG, built for the environment it is in (below). The committed arguments are all required; `start_date` is derived from `backfill_from`. Adds the secret access-check task before every workload task (when it has one, below) and the run-record task after the DAG's last tasks. |
|
|
39
|
+
| `vd.dbt_task(selector, *, task_id=None, target="prod", project_dir=None, extra_args=())` | One task: `dbt build --selector <selector>`. Pushes a compact summary: the `invocation_id`, node counts by status, up to 50 failed node names. |
|
|
40
|
+
| `vd.dlt_task(pipeline, *, task_id=None, script=None, extra_args=())` | One task: runs the committed `ingestion/<pipeline>_pipeline.py`. Its summary carries no `load_id` (below). |
|
|
41
|
+
| `vd.asset(name)` | The Airflow `Asset` `vd://<domainKey>/<name>` (`vd://<domainKey>/<intentKey>/<name>` in a sandbox). The only way to name an asset. |
|
|
42
|
+
| `vd.publish_readiness(name, *, after=None)` | Emits an event on `vd.asset(name)` with the interval and run id as metadata, only when the run's data interval has closed; otherwise the task skips and no event exists. |
|
|
43
|
+
| `vd.probe_task(...)`, `vd.probe_dag(...)` | The post-install probe as a task, or as a manual-trigger DAG. Requires the Data Platform's packages by default. |
|
|
44
|
+
| `check_runtime_set(...)`, `python -m vibedata_airflow.probe` | The probe from code or a shell. |
|
|
45
|
+
|
|
46
|
+
## Environments and the fail-closed rule
|
|
47
|
+
|
|
48
|
+
The same committed file runs in a sandbox (one Intent's namespace of the Ephemeral Orchestrator) and in production. These inputs decide which, all read on the worker:
|
|
49
|
+
|
|
50
|
+
| Input | Where | Meaning |
|
|
51
|
+
| --- | --- | --- |
|
|
52
|
+
| `vd_domain.json` | beside the DAG file, committed | `domainKey`, and the `orchestratorKind`, `dataPlatformKind`, `secretStoreKind` |
|
|
53
|
+
| `VD_ORCH_ENVIRONMENT` | environment-wide process variable | `production` or `ephemeral`, set by the customer |
|
|
54
|
+
| `_vd_namespace.json` | beside the DAG file, written by a sandbox deploy only | `intentKey`, `target` (database, schema, catalog, project or dataset), `secretStoreLocation` |
|
|
55
|
+
| the Airflow Variable `vd_<domainKey>_secret_store` | production only, writable by environment admins | the Secret Store's location, read by the secret access check |
|
|
56
|
+
| the run's conf | sandbox: `vd_interval_start`, `vd_interval_end`, `LOAD__MODE`, `LOAD__ROWS`; both environments: `vd_trigger` | the interval and load bounds (sandbox only); who triggered the run (below) |
|
|
57
|
+
|
|
58
|
+
| Marker | Namespace file | Result |
|
|
59
|
+
| --- | --- | --- |
|
|
60
|
+
| `production` | absent | DAG id `vd_<domainKey>__<dag_id>`, the committed schedule, connection `vd_<domainKey>_platform`, no load bounds. The run record needs the Airflow Variable `vd_<domainKey>_audit_schema` (below) |
|
|
61
|
+
| `ephemeral` | present | `vd_<domainKey>__<intentKey>__<dag_id>`, schedule `None`, pool `vd_<domainKey>__<intentKey>`, connection `vd_<domainKey>_ephemeral`, the Intent's target and load bounds |
|
|
62
|
+
| anything else, `production` with a namespace file, an unreadable `vd_domain.json`, a Data Platform with no run-record dialect, a sandbox target that names no schema, or declared `secrets` on a Secret Store the worker does not read | either | schedule `None` and a `vd_guard` task that fails naming the inconsistency; every workload task also refuses to start, so nothing runs |
|
|
63
|
+
|
|
64
|
+
A guarded DAG's id is `vd_<domainKey>__invalid__<dag_id>`. The guard is decided from the deployed files and the marker alone; no Airflow Variable or Connection is read when a DAG is parsed. Nothing in the namespace file or the run's conf can change the committed schedule, connection or Domain key.
|
|
65
|
+
|
|
66
|
+
The task ids `vd_guard`, `vd_record_run`, `vd_runtime_probe` and `vd_secret_check` are reserved; a workload task that asks for one is refused when the DAG is parsed.
|
|
67
|
+
|
|
68
|
+
## Connections
|
|
69
|
+
|
|
70
|
+
A workload task's process gets the environment variables the committed dbt profile and dlt destination read, filled from the Airflow connection for the environment. The mapping is one row per Data Platform kind (`dataPlatformKind` in `vd_domain.json`): `redshift` and `databricks`. A kind with no row is refused with an error that lists the supported kinds. BigQuery, Fabric Warehouse and Snowflake have a run-record writer (below) but no connection row in this release, so a dbt or dlt task on them is refused there. Values go to the child process only and are never logged.
|
|
71
|
+
|
|
72
|
+
## The code version
|
|
73
|
+
|
|
74
|
+
Airflow has a bundle version only for a versioned (Git) DAG bundle; on MWAA and Composer it is `None`. The Task SDK's `dag_run` does not carry it at all, so the helper reads the task's own bundle (`ti.bundle_instance.version`), which a worker sets and `dag.test()` does not. Every run is stamped anyway, from the first source that has a value, and the record says which one:
|
|
75
|
+
|
|
76
|
+
| `code_version_source` | Source |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| `bundle` | `ti.bundle_instance.version`, when the worker's DAG bundle is versioned |
|
|
79
|
+
| `file` | `_vd_version.json` beside the DAG file: `{"codeVersion": "<git sha>"}`, written by the deploy step or the customer's CI |
|
|
80
|
+
| `variable` | the Airflow Variable `vd_<domainKey>_code_version` |
|
|
81
|
+
| `hash` | `sha256:` of the DAG file and everything beside it (the files the deploy writes are excluded), so a run is never unversioned. If a file cannot be read, `names-sha256:` of the file names stands in; if the directory cannot be listed, the constant `unreadable` |
|
|
82
|
+
|
|
83
|
+
A `hash` is a fingerprint to compare for equality, not a commit to look up.
|
|
84
|
+
|
|
85
|
+
## Correlation values
|
|
86
|
+
|
|
87
|
+
Every workload task's process gets `VD_ORCH_ITEM` (the DAG id as committed), `VD_ORCH_RUN_ID`, `VD_ORCH_TASK_ID`, `VD_ORCH_TRY`, `VD_ORCH_INTERVAL_START`, `VD_ORCH_INTERVAL_END` and `VD_ORCH_CODE_VERSION`, each mirrored as `DBT_ENV_CUSTOM_ENV_<name>` so dbt copies it into `run_results.json` `metadata.env`.
|
|
88
|
+
|
|
89
|
+
For dlt, the values reach the audit tables only with `vibedata-dlt-core>=0.18.0` in the environment: from that release `finalize` writes `orch_run_id`, `orch_task_id`, `orch_try` and the interval into `audit_runs`. An older dlt-core ignores them, and a dlt load then has no link to its run.
|
|
90
|
+
|
|
91
|
+
## The run record
|
|
92
|
+
|
|
93
|
+
The final task (`vd_record_run`, `trigger_rule="all_done"`) writes one row per run to `vd_orchestration_runs` and one row per task to `vd_orchestration_task_runs`, in the Domain's audit schema, through the Airflow provider hook for the Data Platform. The package carries no database driver.
|
|
94
|
+
|
|
95
|
+
| `dataPlatformKind` | Hook | Provider | Statement dialect |
|
|
96
|
+
| --- | --- | --- | --- |
|
|
97
|
+
| `redshift` | `RedshiftSQLHook` | `apache-airflow-providers-amazon` | `"` quoting, `VARCHAR(65535)`, backslash literals |
|
|
98
|
+
| `databricks` | `DatabricksSqlHook` | `apache-airflow-providers-databricks` | backtick quoting, `STRING`, backslash literals |
|
|
99
|
+
| `bigquery` | `BigQueryHook` (standard SQL) | `apache-airflow-providers-google` | backtick quoting, `STRING` / `INT64`, backslash-escaped literals; a project may be hyphenated |
|
|
100
|
+
| `fabric_warehouse` | `OdbcHook` | `apache-airflow-providers-odbc` | `"` quoting, `VARCHAR(8000)` / `DATETIME2(6)`, T-SQL literals, no `CREATE TABLE IF NOT EXISTS` |
|
|
101
|
+
| `snowflake` | `SnowflakeHook` | `apache-airflow-providers-snowflake` | unquoted validated names (folded to upper case), `VARCHAR` / `TIMESTAMP_NTZ`, backslash literals |
|
|
102
|
+
|
|
103
|
+
Platform notes:
|
|
104
|
+
|
|
105
|
+
- **Fabric Warehouse goes through the ODBC provider.** A Warehouse accepts TDS connections with Microsoft Entra authentication only: SQL authentication is not supported. `apache-airflow-providers-microsoft-mssql` opens its session with `pymssql`, which cannot authenticate to Entra, while the ODBC provider hands the connection's `Authentication=ActiveDirectoryServicePrincipal` (or any other Entra mode) to ODBC Driver 18, the driver dbt-fabric already needs on the worker. The hook is opened on the target's Warehouse (`database`) and given the driver explicitly: the provider ignores a `driver` in a connection's extra unless `[providers.odbc] allow_driver_in_extra` is set, and without one it opens no session, so the connection's `driver` is passed through, else `ODBC Driver 18 for SQL Server`. The package declares no driver; `pyodbc`, the driver manager and ODBC Driver 18 are the worker's. Fabric varchar is UTF-8 capped at 8000 bytes, which holds because the summary column is ASCII-only JSON. T-SQL has no `CREATE TABLE IF NOT EXISTS`, so the writer reads the catalog first and creates a table only when it is absent, and believes a failed create only if the table is still absent afterwards.
|
|
106
|
+
- **BigQuery's** hook defaults to legacy SQL, which has no DML and no `INFORMATION_SCHEMA`, so it is opened with `use_legacy_sql=False`. Its own `get_records` demands a location the record has no use for, so statements and reads both go through `run` and its PEP 249 cursor, one query job each, with the location BigQuery infers from the datasets the statement names. The target is `project.dataset` (`dataset` alone uses the connection's project); in a sandbox the namespace file's `dataset` and `project` stand where other platforms have `schema` and `database`.
|
|
107
|
+
- **Snowflake** folds an unquoted name to upper case and keeps a quoted one as written. A quoted lower-case `"vd_orchestration_runs"` would be invisible to every ordinary query, so the writer validates each part and leaves it unquoted, which is how every other Snowflake object is spelled. Statements are never split on `;`, because a summary can hold one inside a literal.
|
|
108
|
+
- **None of the three SQL surfaces was run against a live service in this release's tests.** The writer's statements run end to end on sqlite and the three hooks are exercised in CI's `airflow` job, but each platform's own parser, and the column-catalog queries, are checked by the platform matrix, not here.
|
|
109
|
+
|
|
110
|
+
- The run row: `item`, `dag_id`, `run_id`, `run_type`, `environment`, `intent_key`, `logical_date`, `interval_start`, `interval_end`, `code_version`, `code_version_source`, `status`, `triggered_by`, `airflow_user`, `trigger_assets`, `run_after`, `started_at`, `recorded_at`. The Task SDK gives a task no queue time, so none is recorded.
|
|
111
|
+
- A task row: `dag_id`, `run_id`, `item`, `task_id`, `try_number`, `state`, `child_kind`, `child_id`, `child_link`, `summary`. It is the task's **latest try** when the record is written: `try_number` and the summary come from the try that pushed last, and earlier tries of a retried task have no row. A task that pushed no summary has `try_number` 0, and a task whose state Airflow did not report has a NULL `state`.
|
|
112
|
+
- A dbt task row carries `child_kind` `invocation_id` and the id. A dlt task row carries no child id: the task cannot see the `load_id` the pipeline's process writes, so `child_id` is NULL and `child_link` names the `audit_runs` columns (`orch_run_id`, `orch_task_id`, `orch_try`) that find the load from this run's ids. That join exists only with `vibedata-dlt-core>=0.18.0`.
|
|
113
|
+
- Keys: a run is `(dag_id, run_id)`, because a scheduled `run_id` is derived from the time alone and two DAGs scheduled together share it; a task row is `(dag_id, run_id, task_id, try_number)`.
|
|
114
|
+
- `triggered_by` is the `user_id` of the `vd_trigger` object in the run's conf, which Studio writes (`{user_id, intent_id, request_id}`); a run with no `vd_trigger`, or one without a usable `user_id`, records NULL. 0.1 read `vd_triggered_by`; it is no longer read, because nothing writes it. The run row has no column for `intent_id` or `request_id` (its `intent_key` is the sandbox namespace's key, not Studio's Intent id), and adding one would change `RECORD_SCHEMA_VERSION`, so neither is recorded. On MWAA the Airflow user is per IAM role, so `airflow_user` names the role. The conf value is asserted by the trigger caller and is not authenticated by this package.
|
|
115
|
+
- Rows are immutable: each is inserted only if its key is absent (the warehouses enforce no uniqueness, so the key is held by the insert, not by a constraint). A table whose columns this version does not recognise is refused with `RecordSchemaError`, never altered. The shape is `RECORD_SCHEMA_VERSION`.
|
|
116
|
+
- The audit target in a sandbox is `target.auditSchema`, `target.schema` or `target.dataset` (BigQuery) from the namespace file, in its `target.catalog` (Databricks), `target.database` (Redshift, Snowflake, Fabric Warehouse) or `target.project` (BigQuery) when it names one. In production it is the Airflow Variable `vd_<domainKey>_audit_schema`, written `schema` or `catalog.schema` (`database.schema` on Redshift, Snowflake and Fabric Warehouse, `project.dataset` on BigQuery). Every part is validated and quoted. With a catalog, Databricks tables are `catalog.schema.table`, the column check reads `<catalog>.information_schema`, and the hook is opened on that catalog and schema (a Snowflake or Fabric Warehouse hook on that database); on Redshift the hook's session is opened on the named database, because Redshift refuses a write to a database other than the session's. Without one, the connection's own catalog or database is used.
|
|
117
|
+
- A record that cannot be written is a failed task, in production as in a sandbox: `vd_record_run` retries twice, one minute apart, and then fails, so the run is not green without its record. That includes a production `vd_<domainKey>_audit_schema` Variable that is unset or cannot be read: the Variable is read by `vd_record_run`, not when the DAG is parsed, so the workloads run and the record task fails. A run that fails before the record task, or whose record task fails, is found through the orchestrator's API, not in these tables.
|
|
118
|
+
- A summary is stored as JSON of at most 8,000 characters. One that is longer loses trailing failed node names (`failed_nodes_truncated`) and stays valid JSON.
|
|
119
|
+
- XCom carries ids and compact summaries only; never data, a cursor or a watermark.
|
|
120
|
+
|
|
121
|
+
## The secret access check
|
|
122
|
+
|
|
123
|
+
The worker reads a Domain's source secrets itself, as its own execution identity (the MWAA execution role, the Composer service account, the generic environment's identity), straight from the cloud secret manager and outside Studio's Credential Broker. Studio cannot act as that identity, so the proof is a read the worker makes before any dbt or dlt task runs. `vd.dag` adds a `vd_secret_check` task upstream of every workload task, and of `vd.publish_readiness`:
|
|
124
|
+
|
|
125
|
+
- **A sandbox on a Secret Store the worker reads has it whether or not it declares any secret**, because it also proves the worker can read the Domain's Secret Store at all (a sandbox on `none`, `local_toml`, a platform-native store or `studio_key_vault` gets none unless it declares secrets, and then the DAG is guarded). **Production has it only when `vd.dag(..., secrets=[...])` declares secrets**, so an existing production DAG gains no task.
|
|
126
|
+
- **`secrets` lists dotted dlt keys**, the names a pipeline reads (`sources.shopify.credentials.api_key`). The agent writes them from its dlt sources; `orch validate` is the static counterpart. Declared secrets on a Secret Store the worker does not read (`none`, `local_toml`, the platform-native stores, `studio_key_vault`) guard the DAG.
|
|
127
|
+
- **Each declared secret is read by name, and so is the store itself.** AWS Secrets Manager and Google Secret Manager: the customer-created sentinel (`<prefix>.studio/sentinel`, `<prefix>studio-sentinel`); a missing sentinel is a failure, because the sentinel read is how the grant is proved. Azure Key Vault: one `get` of a random name, where *not found* proves the grant and *forbidden* denies it, since a get-only grant cannot list.
|
|
128
|
+
- **The names the store holds are Studio's.** AWS: the name prefix from the ARN, then the dotted key as `/`-separated segments. Google: the injective codec (`_` to `_u`, `.` to `__`, `/` to `_s`) under the prefix. Azure: the key lower-cased, `.` as `--`, `_` as `-`.
|
|
129
|
+
- **Where the location comes from.** Sandbox: `secretStoreLocation` in `_vd_namespace.json`, so nothing a DAG author or a run's conf can edit decides which store a sandbox reads. Production: the Airflow Variable `vd_<domainKey>_secret_store`. The form is the kind's: AWS an ARN prefix ending in `/` (`arn:aws:secretsmanager:<region>:<account>:secret:<namePrefix>/`), Google `projects/<projectId>` or `projects/<projectId>/secrets/<namePrefix>`, Azure the vault URL.
|
|
130
|
+
- **The identity is the worker's own and the read is direct**: boto3's default credential chain, Google Application Default Credentials, `DefaultAzureCredential`, through the cloud's SDK, never an Airflow connection or the Airflow secrets backend. Airflow's Key Vault backend reports a refused read as *not found*, which would turn a denied grant into a pass. The package declares none of these SDKs. `boto3` (AWS) arrives with `apache-airflow-providers-amazon`, which an MWAA image carries, and `google-cloud-secret-manager` (Google) arrives with `apache-airflow-providers-google`, which the orchestration runtime set installs. Nothing in the runtime set installs the Azure SDK: for `azure_key_vault` the operator installs `azure-identity` and `azure-keyvault-secrets` (the orchestration constraints files already pin both), or `apache-airflow-providers-microsoft-azure`. A reader that cannot be built, because its SDK is absent or its credential setup fails, fails the check naming every declared secret and the store, with the original error.
|
|
131
|
+
- **It never prints a value.** A reader drops the value inside its own function and returns nothing, so no value reaches a log line, an exception or an XCom. A failure names each unreadable secret with the provider's own code and message: `the worker cannot read 2 Domain secret(s): sources.a.token (denied: AccessDeniedException: ...); ...`. Every name is tried, so one failure does not hide the next.
|
|
132
|
+
- It is a task, not a retry: `retries=0`, because a missing grant does not fix itself. A failed check leaves the workload tasks `upstream_failed`, and the run record still writes, with status `failed`.
|
|
133
|
+
|
|
134
|
+
## The post-install probe
|
|
135
|
+
|
|
136
|
+
MWAA reports a failed `requirements.txt` install as a successful environment update, so "Available" says nothing about what imports. The probe reads the installed distributions on the worker and fails when a required package is missing or, with a constraints file, off its pin.
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from vibedata_airflow import vd
|
|
140
|
+
|
|
141
|
+
probe = vd.probe_dag(
|
|
142
|
+
constraints_path="/usr/local/airflow/dags/orchestration-constraints.txt"
|
|
143
|
+
) # trigger after each update
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
python -m vibedata_airflow.probe --constraints orchestration-constraints.txt --platform databricks
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The required set is `vibedata-airflow`, `vibedata-dlt-core`, `dbt-core`, `dlt` and `apache-airflow-providers-git`, plus the Data Platform's own packages:
|
|
151
|
+
|
|
152
|
+
| Data Platform | Also required |
|
|
153
|
+
| --- | --- |
|
|
154
|
+
| `databricks` | `dbt-databricks`, `databricks-sql-connector`, `databricks-sdk`, `apache-airflow-providers-databricks` |
|
|
155
|
+
| `redshift` | `dbt-redshift`, `psycopg2-binary`, `apache-airflow-providers-amazon` |
|
|
156
|
+
| `bigquery` | `apache-airflow-providers-google` |
|
|
157
|
+
| `fabric_warehouse` | `apache-airflow-providers-odbc` |
|
|
158
|
+
| `snowflake` | `apache-airflow-providers-snowflake` |
|
|
159
|
+
|
|
160
|
+
For `databricks` and `redshift` these are the dbt adapter, the drivers dlt's own extra declares (`dlt[databricks]`, `dlt[redshift]`) and the provider whose hook writes the run record. For `bigquery`, `fabric_warehouse` and `snowflake` only the provider is required: their dbt adapters are not in the orchestration runtime set, so requiring them would fail every environment built from it. `dbt-redshift` connects through `redshift-connector`, so it does not bring dlt's `psycopg2-binary` with it. An environment that installs the source build `psycopg2` instead passes `required=`.
|
|
161
|
+
|
|
162
|
+
`vd.probe_task()` and `vd.probe_dag()` take the platform from `platform_kind=`, else from `dataPlatformKind` in the `vd_domain.json` beside the calling file; the shell command takes `--platform`. With no platform named and no Domain file, only the core set is required, so name the platform wherever the file is absent. `required=` replaces the whole set and `--require` adds to it. A package the constraints name but is not required is checked when installed and reported when absent.
|
|
163
|
+
|
|
164
|
+
## Install
|
|
165
|
+
|
|
166
|
+
Install into the Airflow environment under `orchestration-constraints.txt`, so dbt, dlt and the adapters match the pins the Agent Server uses. That file is published from this repository's `constraints/` directory, which VD-8641 adds; it is not part of this package and does not exist before that change. The package itself declares only `packaging`, and expects Airflow, dbt, dlt and the providers from the host.
|
|
167
|
+
|
|
168
|
+
The unit tests run without Airflow. `tests/test_real_airflow.py` parses the DAG with real Airflow 3, `tests/test_real_airflow_run.py` runs the task bodies under `dag.test()`, and `tests/test_real_airflow_hooks.py` aims the Redshift, Snowflake, ODBC (Fabric Warehouse) and BigQuery hooks at a target; each skips where Airflow or its provider is absent, and CI's `airflow` job installs them and runs them. The Databricks hook, the cloud secret SDKs and every warehouse's SQL are not run against a live service in CI.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vibedata-airflow"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "VibeData helper for Airflow 3 DAGs that run dbt and dlt on the worker: a fail-closed DAG wrapper, dbt and dlt tasks, asset readiness, a run record tied to the code version, and a post-install runtime probe."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Vibedata", email = "eng@acceleratedata.ai" }]
|
|
13
|
+
|
|
14
|
+
# Pure Python. Airflow is the host environment's (a peer, never installed by this
|
|
15
|
+
# package): every Airflow import is deferred to the call that needs it, so the
|
|
16
|
+
# package imports, and its probe runs, in an environment where Airflow is absent.
|
|
17
|
+
# `packaging` reads the constraints file the probe checks the runtime set against.
|
|
18
|
+
dependencies = ["packaging>=24"]
|
|
19
|
+
|
|
20
|
+
[project.optional-dependencies]
|
|
21
|
+
# Airflow is never an extra: it is the host environment's, pinned by the vendor (MWAA, Composer) or
|
|
22
|
+
# by the Airflow constraints file a developer installs it with. Locking it here would pin the whole
|
|
23
|
+
# Airflow dependency tree into the workspace lock for every Python the matrix runs.
|
|
24
|
+
dev = ["pytest>=8.0", "pytest-mock>=3.12"]
|
|
25
|
+
|
|
26
|
+
[tool.hatch.build.targets.wheel]
|
|
27
|
+
packages = ["src/vibedata_airflow"]
|
|
28
|
+
|
|
29
|
+
[tool.pytest.ini_options]
|
|
30
|
+
testpaths = ["tests"]
|
|
31
|
+
pythonpath = ["src"]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""vibedata-airflow: one helper for the dbt and dlt DAGs a Domain's Airflow runs.
|
|
2
|
+
|
|
3
|
+
Usage: ``from vibedata_airflow import vd``. Airflow is imported only when a DAG is built.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from . import vd
|
|
7
|
+
from .probe import ProbeError, ProbeReport, check_runtime_set
|
|
8
|
+
from .record import RECORD_SCHEMA_VERSION
|
|
9
|
+
|
|
10
|
+
__version__ = "0.2.0"
|
|
11
|
+
__all__ = [
|
|
12
|
+
"RECORD_SCHEMA_VERSION",
|
|
13
|
+
"ProbeError",
|
|
14
|
+
"ProbeReport",
|
|
15
|
+
"__version__",
|
|
16
|
+
"check_runtime_set",
|
|
17
|
+
"vd",
|
|
18
|
+
]
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""The only module that reaches into Airflow and its providers, always lazily.
|
|
2
|
+
|
|
3
|
+
Every other module takes what it needs as arguments, so the package imports and its
|
|
4
|
+
logic runs without Airflow installed. Airflow 3's Task SDK (``airflow.sdk``) is the
|
|
5
|
+
supported surface.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections.abc import Callable, Sequence
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
FABRIC_ODBC_DRIVER = "ODBC Driver 18 for SQL Server"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AirflowMissingError(ImportError):
|
|
18
|
+
"""Airflow 3 (``airflow.sdk``) is not importable in this environment."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def sdk() -> Any:
|
|
22
|
+
try:
|
|
23
|
+
import airflow.sdk as airflow_sdk
|
|
24
|
+
except ImportError as error: # pragma: no cover - exercised only without Airflow
|
|
25
|
+
raise AirflowMissingError(
|
|
26
|
+
"vibedata-airflow needs Airflow 3 (airflow.sdk); install apache-airflow>=3.0 or run on a worker"
|
|
27
|
+
) from error
|
|
28
|
+
return airflow_sdk
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def get_connection(conn_id: str) -> Any:
|
|
32
|
+
return sdk().Connection.get(conn_id)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_variable(name: str) -> str | None:
|
|
36
|
+
value = sdk().Variable.get(name, default=None)
|
|
37
|
+
return None if value is None else str(value)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _hook(platform_kind: str, conn_id: str, target: Any) -> Any:
|
|
41
|
+
if platform_kind == "databricks":
|
|
42
|
+
from airflow.providers.databricks.hooks.databricks_sql import DatabricksSqlHook
|
|
43
|
+
|
|
44
|
+
return DatabricksSqlHook(
|
|
45
|
+
databricks_conn_id=conn_id, catalog=target.catalog, schema=target.schema
|
|
46
|
+
)
|
|
47
|
+
if platform_kind == "redshift":
|
|
48
|
+
from airflow.providers.amazon.aws.hooks.redshift_sql import RedshiftSQLHook
|
|
49
|
+
|
|
50
|
+
hook = RedshiftSQLHook(redshift_conn_id=conn_id)
|
|
51
|
+
if target.catalog:
|
|
52
|
+
# A Redshift connection's "schema" field is its database, and the hook opens its
|
|
53
|
+
# session from that field alone (the constructor's schema override reaches only
|
|
54
|
+
# the SQLAlchemy URL). Redshift refuses a write to another database, so the
|
|
55
|
+
# hook's own copy of the connection is pointed at the target's.
|
|
56
|
+
hook.conn.schema = target.catalog
|
|
57
|
+
return hook
|
|
58
|
+
if platform_kind == "snowflake":
|
|
59
|
+
from airflow.providers.snowflake.hooks.snowflake import SnowflakeHook
|
|
60
|
+
|
|
61
|
+
# The hook opens its session on this database and schema, whatever the connection's.
|
|
62
|
+
return SnowflakeHook(
|
|
63
|
+
snowflake_conn_id=conn_id, database=target.catalog, schema=target.schema
|
|
64
|
+
)
|
|
65
|
+
if platform_kind == "fabric_warehouse":
|
|
66
|
+
from airflow.providers.odbc.hooks.odbc import OdbcHook
|
|
67
|
+
|
|
68
|
+
# Fabric Warehouse is reached over TDS with Microsoft Entra authentication only; the
|
|
69
|
+
# ODBC hook passes the connection's ``Authentication=ActiveDirectory...`` through to
|
|
70
|
+
# ODBC Driver 18. ``database`` names the Warehouse, overriding the connection's. The
|
|
71
|
+
# hook ignores a ``driver`` in the connection's extra unless the environment sets
|
|
72
|
+
# ``[providers.odbc] allow_driver_in_extra``, and without one it opens no session,
|
|
73
|
+
# so the driver is passed to it: the connection's, else the one Fabric documents.
|
|
74
|
+
extra = OdbcHook.get_connection(conn_id).extra_dejson or {}
|
|
75
|
+
return OdbcHook(
|
|
76
|
+
odbc_conn_id=conn_id,
|
|
77
|
+
database=target.catalog,
|
|
78
|
+
driver=extra.get("driver") or FABRIC_ODBC_DRIVER,
|
|
79
|
+
)
|
|
80
|
+
if platform_kind == "bigquery":
|
|
81
|
+
from airflow.providers.google.cloud.hooks.bigquery import BigQueryHook
|
|
82
|
+
|
|
83
|
+
# The hook defaults to legacy SQL, which has neither DML nor INFORMATION_SCHEMA. No
|
|
84
|
+
# location is set: BigQuery infers a query job's location from the datasets it
|
|
85
|
+
# names, and ``get_records`` (which demands one) is never called on this hook.
|
|
86
|
+
return BigQueryHook(gcp_conn_id=conn_id, use_legacy_sql=False)
|
|
87
|
+
raise ValueError(f"no run-record hook for data platform {platform_kind!r}")
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def sql_callables(
|
|
91
|
+
platform_kind: str, conn_id: str, target: Any
|
|
92
|
+
) -> tuple[Callable[[str], Any], Callable[[str], Sequence[Sequence[Any]]]]:
|
|
93
|
+
"""``(run, fetch)`` backed by the provider hook the Data Platform's mapping names, aimed at ``target``."""
|
|
94
|
+
hook = _hook(platform_kind, conn_id, target)
|
|
95
|
+
|
|
96
|
+
if platform_kind == "bigquery":
|
|
97
|
+
# DbApiHook.run through BigQuery's PEP 249 cursor: a job per statement. The hook has no
|
|
98
|
+
# autocommit, and its own get_records insists on a location.
|
|
99
|
+
from airflow.providers.common.sql.hooks.handlers import fetch_all_handler
|
|
100
|
+
|
|
101
|
+
def run(sql: str) -> Any:
|
|
102
|
+
return hook.run(sql)
|
|
103
|
+
|
|
104
|
+
def fetch(sql: str) -> Sequence[Sequence[Any]]:
|
|
105
|
+
return hook.run(sql, handler=fetch_all_handler) or []
|
|
106
|
+
|
|
107
|
+
return run, fetch
|
|
108
|
+
|
|
109
|
+
# A literal can hold ';': hand each statement to the driver whole, never split it.
|
|
110
|
+
extra: dict[str, Any] = (
|
|
111
|
+
{"split_statements": False} if platform_kind == "snowflake" else {}
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
def run(sql: str) -> Any:
|
|
115
|
+
return hook.run(sql, autocommit=True, **extra)
|
|
116
|
+
|
|
117
|
+
if platform_kind == "snowflake":
|
|
118
|
+
from airflow.providers.common.sql.hooks.handlers import fetch_all_handler
|
|
119
|
+
|
|
120
|
+
# get_records goes through run() with its default split_statements=True.
|
|
121
|
+
def fetch(sql: str) -> Sequence[Sequence[Any]]:
|
|
122
|
+
return hook.run(sql, handler=fetch_all_handler, **extra) or []
|
|
123
|
+
|
|
124
|
+
return run, fetch
|
|
125
|
+
|
|
126
|
+
def fetch(sql: str) -> Sequence[Sequence[Any]]:
|
|
127
|
+
return hook.get_records(sql)
|
|
128
|
+
|
|
129
|
+
return run, fetch
|