Schedule icon
Query icon
If icon
SlackIncomingWebhook icon
Log icon
Return icon

BigQuery Table Partition and Cost Governance Audit

Automated FinOps workflow to query BigQuery INFORMATION_SCHEMA, detect large unpartitioned tables and missing partition filters, and alert Slack.

Categories
BusinessData

In Google BigQuery, analysis costs are directly tied to the number of bytes scanned by queries. Unpartitioned tables or tables that do not require partition filters represent a major financial vulnerability: an inexperienced user or runaway dashboard query can trigger full-table scans across multi-terabyte datasets, generating surprise cloud bills within minutes.

This blueprint establishes an automated Data Warehouse governance guardrail for Google BigQuery. Running on a weekly schedule or on-demand, it queries INFORMATION_SCHEMA.TABLE_STORAGE and INFORMATION_SCHEMA.TABLES across your specified dataset, flags tables larger than your threshold that lack date partitioning or mandatory partition filters, and delivers a prioritized remediation digest to your data team on Slack.

How it works

  1. Scheduled FinOps Audit: The weekly_governance_schedule trigger (io.kestra.plugin.core.trigger.Schedule) executes every Monday at 08:00 UTC, or runs on-demand via the Kestra UI.
  2. Storage and Metadata Audit: The audit_partition_metadata task (io.kestra.plugin.gcp.bigquery.Query) executes an analytical query against BigQuery INFORMATION_SCHEMA. It joins physical storage bytes with table partition flags to classify violations (UNPARTITIONED_LARGE_TABLE, MISSING_PARTITION_FILTER).
  3. Violation Gate: The evaluate_governance_violations flowable task (io.kestra.plugin.core.flow.If) evaluates whether the total count of offending tables exceeds max_allowed_unpartitioned_tables.
  4. Slack Governance Digest: If non-compliant tables are discovered, notify_governance_slack (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) broadcasts an alert detailing the dataset, violation count, and largest offender with remediation steps.
  5. Audit Trail: The export_audit_manifest task records execution audit details and compliance status for data platform tracking.

What you get

  • Automated discovery of expensive unpartitioned tables before they cause costly query scans.
  • Enforcement of the require_partition_filter best practice to prevent accidental full-table scans.
  • Direct Slack notifications detailing the largest offenders by gigabytes.
  • Zero human overhead for continuous BigQuery storage and schema governance.

Who it's for

  • Data Platform Engineers and BigQuery Administrators governing multi-tenant projects.
  • FinOps teams auditing cloud data warehouse compute and storage bills.
  • Analytics Engineering leads enforcing table design and query optimization contracts.

Why orchestrate this with Kestra

Manual table audits are rarely performed consistently, and native GCP alerts do not easily cross-reference table storage size with table partition schema flags. Kestra automates this end-to-end: it securely handles Google Cloud service account authentication, schedules regular audits, branches conditionally based on violation thresholds, and notifies the right team in Slack.

Inputs

Name Type Default Description
dataset_id STRING analytics_prod BigQuery dataset name to audit for partition and expiration compliance.
max_allowed_unpartitioned_tables INT 0 Violation tolerance threshold before triggering a Slack alert.
min_table_size_mb INT 500 Only flag unpartitioned tables larger than this size threshold (MB).
slack_channel STRING #data-governance Slack channel destination for governance compliance reports.

Expected outputs

  • {{ outputs.audit_partition_metadata.rows }}: Array of non-compliant table records containing table_schema, table_name, size_mb, size_gb, total_rows, is_partitioned, and violation_type.
  • {{ outputs.audit_partition_metadata.size }}: Total number of non-compliant tables discovered during the scan.
  • {{ outputs.evaluate_governance_violations }}: Result of conditional evaluation determining whether Slack notification was dispatched.
  • {{ outputs.export_audit_manifest.value }}: Structured JSON audit manifest containing execution timestamp, dataset ID, and compliance status (PASSED or ACTION_REQUIRED).

Prerequisites

  • A Google Cloud Platform (GCP) project with BigQuery enabled.
  • A GCP Service Account JSON with roles/bigquery.metadataViewer and roles/bigquery.jobUser permissions.
  • A Slack Incoming Webhook URL targeting your data governance channel.

Secrets

  • GCP_PROJECT_ID: Your Google Cloud Project ID (used to query dataset metadata).
  • GCP_SERVICE_ACCOUNT_JSON: Full JSON key file content of the GCP service account with BigQuery query and metadata permissions.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook endpoint URL used for sending alert notifications.

Quick start

  1. Configure GCP_PROJECT_ID, GCP_SERVICE_ACCOUNT_JSON, and SLACK_WEBHOOK_URL in your Kestra namespace secrets.
  2. Import this flow YAML into your Kestra instance.
  3. Click Execute in the UI to run an audit against your target dataset.
  4. Check the execution outputs to view table compliance metrics and size breakdowns.

Common pitfalls & troubleshooting

  • BigQuery IAM Permissions: Ensure the GCP Service Account is granted roles/bigquery.metadataViewer and roles/bigquery.jobUser. Without metadataViewer, querying INFORMATION_SCHEMA.TABLE_STORAGE will fail with an Access Denied error.
  • Regional Location: BigQuery INFORMATION_SCHEMA queries must target the exact region where your dataset resides. If your dataset is hosted in a non-US multi-region (e.g. europe-west1), ensure the query job execution location matches.
  • Empty Table Storage: Newly created tables might take several minutes to reflect in INFORMATION_SCHEMA.TABLE_STORAGE.

How to extend

  • Add io.kestra.plugin.notifications.mail.MailSend inside the then: block to email weekly compliance reports to engineering managers.
  • Add a io.kestra.plugin.github.issues.Create task to automatically file tracking tickets for unpartitioned tables exceeding 100 GB.
  • Loop over multiple datasets using io.kestra.plugin.core.flow.Loop to audit entire enterprise GCP projects.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.