RFC: persist audit results to a warehouse table

オープン
#6,295 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 4 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
32/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python, sql

調査の方向性

Start with SnapshotEvaluator.audit, Scheduler._audit_snapshot, run_merged_intervals, create_state_table, and the audit-results configuration and janitor entry points. The RFC proposes separate work for the completion callback, recorder buffering and flushing, wiring into plan, run, and sqlmesh audit, retention, documentation, and engine-adapter integration tests. A newcomer should not begin implementation until the open questions about strict versus warn-only failures, table naming and location, error recording, and schema reuse are resolved.

索引モデルが issue の本文から書いたものです。

説明

RFC: persist audit results to a warehouse table

This revisits #3064. It was closed because Tobiko Cloud covered it. Now that Cloud is discontinued, I'd like to contribute an open-source version. Below are a proposed design and PR breakdown. Please push back on anything before I start.

Goal

Opt in to one summary row per audit execution, written to a table in the warehouse. Teams can then build audit history and data-quality dashboards with plain SQL. Today the only option is a custom GenericNotificationTarget. It sees failures only, and it gets no interval, environment or run context.

Out of scope: storing failing rows, as dbt's store_failures does. Only the summary is stored: status, failing-row count, and the rendered query.

Config
audit_results:
  enabled: true                  # default false
  gateway: warehouse             # default: the selected gateway
  table: sqlmesh.audit_results   # default
  include_query: true            # store the rendered audit SQL
  retention: 4 weeks             # optional; enforced by the janitor
Table

There is one row per audit execution, for plans, runs and sqlmesh audit, in both prod and dev. Timestamps are epoch-ms BIGINT, as in the state tables. There is no primary key.

Column(s) Contents
id, recorded_ts, started_ts, duration_ms Row id and timing
job_type (plan / run / audit), job_id Which job ran the audit. job_id is the plan id, or the run id from the existing CorrelationId.
environment, gateway, is_dev Where it ran
node_name, node_type (model / standalone_audit), snapshot_identifier, snapshot_version What was audited. snapshot_identifier joins to _snapshots.
audit_name, audit_args (JSON), blocking Which audit. blocking is the resolved value, including force_non_blocking.
status (passed / failed / skipped / error), failed_row_count, error_message The outcome. error means the audit query itself raised.
query, query_dialect The rendered SQL, in the dialect of the gateway it ran on (truncated)
interval_start_ts, interval_end_ts, execution_ts Which data was audited
sqlmesh_version

Schema evolution: columns are additive only. On first use SQLMesh creates the table, or adds any missing columns. It uses create_state_table, which gives Athena an Iceberg table and drops the primary key on BigQuery.

Design
  • Capture:
    • A keyword-only on_audit_complete callback on SnapshotEvaluator.audit receives an outcome for every audit, including audits whose query raised, along with its duration.
    • Scheduler._audit_snapshot binds the context: job, environment and interval.
    • Rows are buffered before NodeAuditsErrors is raised.
    • The execution observer from #6051 is unchanged.
  • Write:
    • Rows are buffered thread-safely.
    • The buffer is flushed with one insert_append in the outer finally of run_merged_intervals, plus an early flush every ~1,000 rows. That gives one load per run rather than one per model, which matters for BigQuery's load-job quotas.
    • The write runs outside any model, state or WAP transaction.
  • Failure semantics (the main open question):
    • Persisting is strict: if it's enabled and the write fails, the job fails.
    • A pre-flight check creates or verifies the table before any model work, so a missing permission fails fast instead of after a long backfill.
    • A write failure never masks an error that is already being raised; it is attached as a note instead.
    • I'm happy to switch to warn-only, or to add fail_on_error (default true), if you'd prefer that observability never fails a run.
  • Retention: when retention is set, the janitor deletes old rows.
  • Known gaps (to be documented):
    • A hard kill loses the buffer.
    • Audits skipped because an upstream node failed are not recorded.
PR plan

Each PR is small and lands independently on main. Everything is inert until PR 5 wires it in, behind enabled: false.

  1. fix(audit): render audit errors in the executing gateway's dialect. This is an independent existing bug: errors currently use the default gateway's dialect.
  2. feat(audit): contract types and table schema.
  3. feat(config): the audit_results config section.
  4. feat(evaluator): per-audit completion hook. No behaviour change.
  5. feat(audit): AuditResultsRecorder (buffer, ensure table, flush).
  6. feat: wire it into plan, run and sqlmesh audit, plus docs.
  7. feat(janitor): retention.
  8. test: engine-adapter integration coverage.

Points I'd especially like your view on:

  • strict failure versus warn-only;
  • the table name and default location;
  • recording error status;
  • reusing create_state_table for a table that isn't state;
  • whether you'd rather fold PRs 2–5 into fewer PRs.
主要言語
Python
スター
3.3k
フォーク
471
平均マージ
6日 7時間
マージ済み PR(30日)
35

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

SQLMesh/sqlmesh のほかの issue

SQLMesh/sqlmesh の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。