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

Snowflake Query Tagging and FinOps Cost Allocation Governance Guard

Audit Snowflake query and attribution history for query tag compliance, quantify unallocated compute credit spend, and alert FinOps on Slack.

Categories
BusinessCloudData

Automated Snowflake FinOps watchdog auditing SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY and QUERY_ATTRIBUTION_HISTORY for query tag compliance. Identifies untagged warehouse workloads, attributes unallocated compute credits and estimated dollar cost, and alerts FinOps teams on Slack when non-compliance exceeds organizational thresholds.

What this blueprint does

In enterprise cloud data platforms, finance and engineering leadership rely on Snowflake Query Tags (QUERY_TAG) to map warehouse compute costs to business units, cost centers, microservices, and dbt models. When queries run without tags, compute charges fall into an unallocated "black hole," breaking FinOps chargeback models.

This blueprint automates continuous query tagging governance:

  1. Inspects all warehouse queries executed across your Snowflake account over a configurable lookback window (default 24 hours).
  2. Measures total queries versus untagged queries (QUERY_TAG IS NULL OR TRIM(QUERY_TAG) = '').
  3. Calculates the untagged query percentage and total unallocated compute hours.
  4. Identifies the top offending roles, users, and warehouses responsible for untagged activity.
  5. Evaluates whether the untagged rate exceeds the organization's compliance SLA threshold (default 5%).
  6. Dispatches an actionable alert to Slack with offending roles and recommended remediation scripts if breached.
  7. Emits a structured FinOps governance manifest for auditing and tracking compliance trends over time.

How it works

  1. Scheduled or On-Demand Trigger: Runs automatically every morning at 06:00 UTC via daily_tagging_audit or manually with custom lookback hours.
  2. Compliance Aggregation: The audit_query_tag_compliance task executes an optimized SQL aggregation against snowflake.account_usage.query_history, filtering for successful warehouse queries and calculating the untagged percentage.
  3. Offender Breakdown: The fetch_offending_roles_summary task isolates the top roles, users, and virtual warehouses driving the highest volume of untagged queries.
  4. SLA Evaluation: The evaluate_tagging_compliance conditional task compares the computed untagged percentage against inputs.max_untagged_percentage_threshold.
  5. Slack Alerting: If compliance is breached, notify_finops_slack sends a detailed Slack notification highlighting the offending role, user, warehouse, and remediation commands.
  6. Nominal Logging: If within threshold, log_nominal_tagging logs a confirmation message.
  7. Audit Manifest: The export_governance_manifest task records a JSON summary of the audit for ingestion into cloud governance dashboards.

What you get

  • Comprehensive visibility into untagged Snowflake compute spend.
  • Automated detection of teams, service accounts, or BI tools failing to set query tags.
  • Early warning before monthly billing cycles to enforce cost allocation discipline.
  • Zero human overhead for continuous enterprise FinOps policy enforcement.

Who it is for

  • FinOps Practitioners & Cloud Economists: Enforcing cloud financial governance and chargeback across Snowflake accounts.
  • Data Platform & Infrastructure Engineers: Maintaining observability and tagging standards across pipelines and BI connections.
  • Analytics Engineering Managers: Ensuring all dbt jobs, Airflow DAGs, and Kestra flows tag their sessions properly.

Why orchestrate this with Kestra

Snowflake resource monitors manage warehouse quotas but cannot enforce tagging policies or inspect session metadata. Kestra orchestrates the entire governance lifecycle declaratively: connecting securely through JDBC, inspecting account-wide usage views, branching on FinOps compliance thresholds, and notifying engineering stakeholders directly where they work.

Inputs

Name Type Default Description
lookback_hours INT 24 Number of hours of historical query activity to audit.
max_untagged_percentage_threshold FLOAT 5.0 Maximum acceptable percentage of untagged queries before triggering an alert.
credit_price_usd FLOAT 3.00 Estimated dollar cost per Snowflake compute credit.
max_offending_roles_to_list INT 5 Maximum number of offending roles and users to list in the breakdown.
slack_channel STRING #finops-governance Slack channel destination for FinOps query tag governance alerts.

Expected outputs

  • {{ outputs.audit_query_tag_compliance.row }}: Aggregated metrics including TOTAL_WAREHOUSE_QUERIES, UNTAGGED_QUERIES, UNTAGGED_PERCENTAGE, UNTAGGED_COMPUTE_CREDITS, ESTIMATED_UNTAGGED_COST_USD, and UNTAGGED_EXECUTION_HOURS.
  • {{ outputs.fetch_offending_roles_summary.rows }}: Array of top offending roles, users, and warehouses with individual UNTAGGED_QUERY_COUNT values.
  • {{ outputs.evaluate_tagging_compliance }}: Status of the conditional SLA evaluation.
  • {{ outputs.export_governance_manifest.value }}: Structured JSON telemetry manifest recording compliance state and timestamp.

Prerequisites

  • A Snowflake account with access to the SNOWFLAKE.ACCOUNT_USAGE schema.
  • A Snowflake service account with a role granted IMPORTED PRIVILEGES on the SNOWFLAKE database.
  • A Slack Incoming Webhook URL targeting your FinOps notification channel.

Secrets

  • SNOWFLAKE_JDBC_URL: Snowflake JDBC connection string (e.g. jdbc:snowflake://<account_locator>.snowflakecomputing.com?warehouse=COMPUTE_WH&db=SNOWFLAKE&schema=ACCOUNT_USAGE).
  • SNOWFLAKE_USER: Username of the service account authorized to query account usage.
  • SNOWFLAKE_PASSWORD: Password for the Snowflake service account.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook endpoint URL used for sending alert notifications.

Quick start

  1. Configure SNOWFLAKE_JDBC_URL, SNOWFLAKE_USER, SNOWFLAKE_PASSWORD, 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 immediate audit across the last 24 hours of Snowflake activity.
  4. Review execution outputs to inspect your account's query tagging compliance rate.

Common pitfalls and troubleshooting

  • Attribution and Usage Data Latency: While SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY updates within 45 minutes, QUERY_ATTRIBUTION_HISTORY lags by up to a few hours before compute credits are allocated. Running audits with a 24-hour lookback window ensures consistent and reconciled metrics rather than zero attribution for very recent queries.
  • Excluded Queries: Queries running without a virtual warehouse (such as metadata-only commands or failed syntax checks) are filtered out to focus exclusively on billable compute spend.
  • Structured JSON Tags: If your organization enforces specific JSON keys (e.g., cost_center), extend the WHERE clause to check TRY_PARSE_JSON(query_tag):cost_center IS NOT NULL.

How to extend

  • Add automated PagerDuty or Jira ticket creation for persistent repeat-offender roles.
  • Filter for specific production warehouses (e.g., ANALYTICS_WH, ETL_WH) to apply stricter tagging thresholds.
  • Enforce mandatory tagging at the warehouse level by integrating with automated user permission reviews.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.