New to Kestra?
Use blueprints to kickstart your first workflows.
Automated FinOps workflow to query Snowflake automatic clustering history, detect runaway background credit burn, and alert Slack.
In Snowflake, Automatic Clustering maintains optimal micro-partition sorting for multi-terabyte tables without manual vacuuming or defragmentation. However, because reclustering executes as a continuous serverless background service, poorly chosen cluster keys on frequently updated, ingested, or deleted tables cause Snowflake to endlessly rewrite micro-partitions.
This continuous churn can consume hundreds of compute credits every day without generating any user-visible query errors, quietly burning thousands of dollars of monthly cloud budget.
This blueprint establishes an automated FinOps guardrail for Snowflake background compute. Executing daily or on-demand, it inspects SNOWFLAKE.ACCOUNT_USAGE.AUTOMATIC_CLUSTERING_HISTORY, aggregates credits consumed per table, and flags tables exceeding your credit threshold. When runaway clustering is detected, it dispatches an actionable Slack alert with dollar cost estimates, reclustered gigabytes, and immediate SUSPEND RECLUSTER remediation commands.
daily_clustering_audit trigger (io.kestra.plugin.core.trigger.Schedule) executes daily at 08:00 UTC or on-demand via the Kestra UI.audit_clustering_spend task (io.kestra.plugin.jdbc.snowflake.Query) queries snowflake.account_usage.automatic_clustering_history, grouping credits used and reclustered bytes by table.evaluate_clustering_spikes flowable task (io.kestra.plugin.core.flow.If) branches based on whether any table exceeded max_credits_per_table.notify_finops_slack (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) delivers a diagnostic card detailing the table name, credits burned, dollar costs, and remediation guidance.log_nominal_clustering records compliant status in execution logs.export_clustering_manifest task records telemetry outputs for cloud budget dashboards.Snowflake resource monitors only apply to virtual warehouses and cannot automatically cap serverless services like Automatic Clustering. Kestra provides declarative, serverless orchestration: it connects securely via JDBC, inspects serverless history daily, evaluates credit anomalies, and delivers rich alerts directly to your team on Slack.
| Name | Type | Default | Description |
|---|---|---|---|
lookback_days |
INT | 1 |
Number of days of historical automatic clustering activity to audit. |
max_credits_per_table |
FLOAT | 10.0 |
Daily credit threshold beyond which table automatic clustering triggers an alert. |
credit_price_usd |
FLOAT | 3.00 |
Estimated dollar cost per Snowflake compute credit. |
slack_channel |
STRING | #finops-alerts |
Slack channel destination for clustering cost alerts. |
{{ outputs.audit_clustering_spend.rows }}: Array of table records containing database_name, schema_name, table_name, total_credits_consumed, estimated_cost_usd, and reclustered_gigabytes.{{ outputs.audit_clustering_spend.size }}: Total count of tables breaching the daily clustering credit threshold.{{ outputs.evaluate_clustering_spikes }}: Result of conditional branch evaluation.{{ outputs.export_clustering_manifest.value }}: Structured JSON telemetry manifest recording execution timestamp and status.SNOWFLAKE.ACCOUNT_USAGE schema views.IMPORTED PRIVILEGES on the SNOWFLAKE database.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.SNOWFLAKE_JDBC_URL, SNOWFLAKE_USER, SNOWFLAKE_PASSWORD, and SLACK_WEBHOOK_URL in your Kestra namespace secrets.SNOWFLAKE.ACCOUNT_USAGE such as AUTOMATIC_CLUSTERING_HISTORY experience up to 45 to 120 minutes of data latency. Schedule the flow daily for fully reconciled metrics.to_date(timestamp).ALTER TABLE <table_name> SUSPEND RECLUSTER; while optimizing cluster keys.ALTER TABLE ... SUSPEND RECLUSTER; directly if spend exceeds a critical emergency threshold.SYSTEM$CLUSTERING_INFORMATION to compute average clustering depth and partition overlap metrics.