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

Snowflake Cost Anomaly Detector and FinOps Alerting

Automated FinOps workflow to audit Snowflake warehouse metering history, detect credit usage spikes over rolling baselines, and alert Slack.

Categories
BusinessData

Cloud data warehouses like Snowflake offer elastic scalability, but unmonitored compute can quickly trigger runaway costs. A single unpartitioned cross-join, accidental warehouse size upgrade, or runaway automated clustering job can result in thousands of dollars in surprise cloud bills.

This blueprint implements an automated FinOps guardrail for Snowflake data platforms. Every morning, it queries SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY, calculates yesterday's credit burn against a rolling 7-day historical baseline for every warehouse, flags percentage spikes exceeding your configured threshold, and immediately alerts your FinOps team on Slack with estimated dollar impacts.

How it works

  1. Scheduled FinOps Audit: The daily_finops_schedule trigger (io.kestra.plugin.core.trigger.Schedule) fires automatically at 07:00 UTC once the previous day's metering history is finalized in Snowflake.
  2. Metering Calculation: The calculate_baseline_and_spikes task (io.kestra.plugin.jdbc.snowflake.Query) uses a SQL Common Table Expression (CTE) to aggregate credit usage per warehouse and calculate percentage deviation against the historical rolling window. With fetchType: FETCH, rows are returned to the flow execution context.
  3. Anomaly Evaluation: The evaluate_spend_anomalies flowable task (io.kestra.plugin.core.flow.If) evaluates whether the highest-spiking warehouse exceeds alert_threshold_percent.
  4. Slack Alerting: If an anomaly is detected, notify_finops_alert (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) dispatches a high-priority alert card detailing the offending warehouse, yesterday's credits, historical baseline, and dollar estimates.
  5. Audit Metadata: The export_finops_audit task records execution audit details for compliance logs and data platform dashboards.

What you get

  • Automated, hands-free Snowflake credit spend surveillance.
  • Early warning on runaway queries before end-of-month invoice surprises.
  • Rolling baseline comparison that automatically adapts to seasonal business growth.
  • Zero human overhead for data warehouse cost governance.

Who it's for

  • Data Platform Engineers and FinOps teams managing multi-tenant Snowflake accounts.
  • Analytics Engineering leads responsible for compute budget governance.
  • SREs and engineering managers preventing cloud overspending.

Why orchestrate this with Kestra

Snowflake includes basic resource monitors, but they only support hard quota cutoffs that abruptly terminate running production queries. Kestra provides declarative, intelligent FinOps automation: it computes statistical rolling baselines, sends rich formatted Slack digests, maintains execution lineage, and can conditionally trigger downstream mitigation workflows without disrupting production workloads.

Inputs

Name Type Default Description
alert_threshold_percent FLOAT 50.0 Cost spike threshold percentage above rolling 7-day baseline to trigger a Slack alert.
baseline_days INT 7 Historical rolling evaluation window in days to compute daily average spend.
estimated_credit_price_usd FLOAT 3.00 Estimated dollar cost per Snowflake credit (standard Enterprise pricing).
slack_channel STRING #finops-alerts Destination Slack channel for anomaly alert dispatch.

Expected outputs

  • {{ outputs.calculate_baseline_and_spikes.rows }}: Array of warehouse usage records containing warehouse_name, credits_yesterday, baseline_credits, estimated_cost_usd, and spike_percentage.
  • {{ outputs.calculate_baseline_and_spikes.size }}: Total number of active warehouses analyzed.
  • {{ outputs.evaluate_spend_anomalies }}: Result of conditional branch checking if top warehouse spike exceeded threshold.
  • {{ outputs.export_finops_audit.value }}: Structured JSON manifest recording execution timestamp, top warehouse name, spike percentage, and anomaly flag.

Prerequisites

  • A Snowflake account with access to SNOWFLAKE.ACCOUNT_USAGE views (typically granted to ACCOUNTADMIN or via custom monitoring role).
  • A Slack Incoming Webhook URL targeting your alert channel.

Secrets

  • SNOWFLAKE_JDBC_URL: Snowflake JDBC connection string (e.g. jdbc:snowflake://<account_identifier>.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 the Snowflake and Slack secrets in your Kestra namespace.
  2. Import this flow YAML into your Kestra instance.
  3. Click Execute in the UI to perform an on-demand audit.
  4. Inspect the execution outputs to view credit consumption metrics across all active warehouses.

Common pitfalls & troubleshooting

  • Account Usage Latency: Snowflake ACCOUNT_USAGE views have an inherent data latency of approximately 45 to 120 minutes. Running the schedule at 07:00 UTC ensures full reconciliation of the prior calendar day's usage.
  • Warehouse Permissions: The service account requires IMPORTED PRIVILEGES on database SNOWFLAKE to read ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY.
  • JDBC URL Format: Ensure your account identifier in SNOWFLAKE_JDBC_URL uses hyphens rather than underscores if your account uses cloud locator syntax (e.g., xy12345.us-east-2.aws).

How to extend

  • Add io.kestra.plugin.notifications.mail.MailSend inside the then: block to notify finance department heads via email.
  • Lower warehouse sizing automatically during severe spikes using ALTER WAREHOUSE ... SET WAREHOUSE_SIZE = 'X-SMALL'.
  • Integrate with PagerDuty for critical tier-1 production warehouse escalations.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.