Query icon
Script icon
Process icon
Set icon
If icon
SlackIncomingWebhook icon
Fail icon
Log icon
Schedule icon

Snowflake Warehouse Local and Remote Spill Cost Sentinel

Detect Snowflake queries spilling to local and remote storage, calculate wasted credit burn, persist audits to KV, and alert Slack with rightsizing advice.

Categories
CloudData

When Snowflake virtual warehouse memory cannot hold intermediate calculation states during joins, aggregations, or sorting, the engine spills partitions first to local SSD storage and subsequently to remote cloud object storage. While local SSD spill causes modest latency, remote storage spill induces extreme network I/O stalls, multiplying query runtimes and consuming excess compute credits.

This blueprint provides an automated FinOps sentinel for Snowflake. It connects over native JDBC, inspects SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY for memory spill events over a configurable lookback window, isolates memory-starved warehouses from unoptimized join operations, computes financial credit waste, persists audit state to the Kestra key-value store, and delivers actionable Slack alerts with rightsizing and clustering recommendations.

How it works

  1. query_spilled_queries (io.kestra.plugin.jdbc.snowflake.Query): Executes a JDBC query against SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY to extract queries exceeding local or remote storage spill thresholds within the configured lookback window.
  2. analyze_spill_and_compute_waste (io.kestra.plugin.scripts.python.Script): Aggregates spill volumes by warehouse and query, estimates wasted credit burn based on warehouse cluster size and I/O stall duration, diagnoses root causes (undersized warehouse nodes versus unpruned joins), and writes markdown and JSON reports.
  3. persist_warehouse_spill_audit (io.kestra.plugin.core.kv.Set): Stores the structured audit summary in Kestra key-value storage under snowflake_warehouse_spill_latest for historical tracking and downstream dashboarding.
  4. evaluate_spill_and_notify (io.kestra.plugin.core.flow.If): Checks if spilling queries were detected.
    • then: Dispatches a detailed Slack alert card via send_slack_spill_recommendations (io.kestra.plugin.slack.notifications.SlackIncomingWebhook). If aggregate remote spill breaches severe_remote_spill_threshold_gb, halts execution with fail_on_severe_remote_spill (io.kestra.plugin.core.execution.Fail).
    • else: Logs a clean audit verification via log_healthy_spill_status (io.kestra.plugin.core.log.Log).
  5. alert_on_failure (errors block): Intercepts unhandled JDBC errors or authentication failures and posts an immediate incident alert to Slack.
  6. schedule_sentinel (io.kestra.plugin.core.trigger.Schedule): Executes the workflow every two hours. Shipped disabled by default.

What you get

  • Automated detection of memory-starved Snowflake virtual warehouses before query timeouts degrade business reporting.
  • Clear distinction between modest local SSD spill and severe remote cloud object storage spill.
  • Accurate financial waste calculations converting query elapsed time and warehouse size into estimated wasted credits and USD.
  • Actionable warehouse rightsizing advice (e.g. scaling from Medium to Large to double per-node RAM).
  • Targeted query optimization recommendations for Cartesian join explosions and missing table clustering keys.
  • Persistent audit records in Kestra KV store and downloadable markdown and JSON reports.

Who it's for

  • FinOps Practitioners monitoring cloud data warehouse credit burn and compute efficiency.
  • Data Platform Engineers and Snowflake Administrators managing shared virtual warehouses.
  • Analytics Engineers optimizing slow dbt transformation models and complex reporting queries.

Why orchestrate this with Kestra

Snowflake resource monitors only support crude credit quotas that abruptly suspend entire warehouses, interrupting production jobs. Kestra delivers diagnostic, non-invasive FinOps orchestration: it identifies specific query and warehouse bottlenecks, isolates root causes, computes financial impact, records state in KV, and dispatches rich remediation alerts without disrupting running workloads.

Prerequisites

  • Snowflake user with SELECT privileges on SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY.
  • Dedicated or shared virtual warehouse for executing diagnostic queries.
  • Slack incoming webhook endpoint for FinOps notifications.

Secrets

  • SNOWFLAKE_PASSWORD: Service account password for authenticating to Snowflake.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL for alerting channels.

Quick start

  1. Store SNOWFLAKE_PASSWORD and SLACK_WEBHOOK_URL in your Kestra namespace secrets.
  2. Import this blueprint and set snowflake_account to your Snowflake account identifier.
  3. Run the workflow manually to inspect query spill metrics across your warehouses.
  4. Enable the schedule_sentinel trigger for continuous bi-hourly cost governance.

How to extend

  • Add an automated ALTER WAREHOUSE <name> SET WAREHOUSE_SIZE = '<new_size>' step in Kestra to rightsize undersized warehouses after manager approval.
  • Forward the KV audit payload to Datadog or Prometheus via Kestra HTTP tasks to track spill trends over time.
  • Integrate with Jira or ServiceNow to automatically open performance tickets for data teams responsible for top spilling queries.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.