Skip to content

Commit ada7a5a

Browse files
authored
Merge pull request #11 from vmariiechko/feature/monitoring-sql-warehouse-asset
Add monitoring-sql-warehouse asset
2 parents b6b4d1f + bad6882 commit ada7a5a

9 files changed

Lines changed: 455 additions & 0 deletions

File tree

ASSETS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Run the command from the root of your bundle project. The CLI will prompt for an
1919
|---|---|---|---|
2020
| `sdp-checkpoint-recovery` | Reset checkpoint selection on a Lakeflow Spark Declarative Pipeline after a source table has been dropped and recreated. | Stable | [README](assets/sdp-checkpoint-recovery/README.md) |
2121
| `dbx-ro-query` | Dependency-free Python wrapper around `databricks experimental aitools tools query` that gives LLM agents a guarded read-only SQL window into a Databricks workspace. Ships a `SKILL.md` for agent integration. | Stable | [README](assets/dbx-ro-query/README.md) |
22+
| `monitoring-sql-warehouse` | Small, dedicated serverless SQL warehouse (2X-Small, `auto_stop_mins: 1`) for scheduled Databricks Alerts and monitoring queries. Keeps cost proportional to actual query time instead of idle warm-up. | Stable | [README](assets/monitoring-sql-warehouse/README.md) |
2223

2324
## What an asset is not
2425

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
77

88
## [Unreleased]
99

10+
## [1.8.0] - 2026-05-30
11+
12+
### Added
13+
- **Asset `monitoring-sql-warehouse`**: Declarative Automation Bundle resource defining a small, dedicated serverless SQL warehouse tuned for bursty workloads (scheduled Databricks Alerts, monitoring queries, ad-hoc health checks).
14+
- Defaults to `cluster_size: 2X-Small`, `warehouse_type: PRO`, `enable_serverless_compute: true`, and `auto_stop_mins: 1` (the serverless minimum verified end-to-end via DABs deploy; sub-minute values silently revert to the platform default).
15+
- Channel pinned to `CHANNEL_NAME_CURRENT` so Databricks SQL Preview-channel rollouts cannot change query behavior under monitoring workloads. Cost-attribution tags `workload=monitoring-alerts` and `created_by=dabs-asset/monitoring-sql-warehouse` ship by default for traceability in usage reports.
16+
- Five prompts (`target_dir`, `warehouse_resource_key`, `warehouse_name`, `cluster_size`, `auto_stop_mins`) with safe defaults; the resource file lands at `<target_dir>/<warehouse_resource_key>.sql_warehouse.yml` and is picked up by the conventional `resources/*.yml` include glob without any `databricks.yml` change.
17+
- In-bundle usage doc at `docs/monitoring-sql-warehouse/README.md` covers the auto-stop nuance, cross-resource ID reference pattern, and `databricks warehouses edit --auto-stop-mins` / REST API paths for editing warehouses created outside DABs.
18+
1019
## [1.7.1] - 2026-05-13
1120

1221
### Fixed
@@ -176,6 +185,7 @@ Initial public release.
176185
- L2 tests: YAML syntax, environment targets, content validation
177186
- CI/CD tests: pipeline generation, auth patterns, branch references
178187

188+
[1.8.0]: https://github.com/vmariiechko/databricks-bundle-template/releases/tag/v1.8.0
179189
[1.7.0]: https://github.com/vmariiechko/databricks-bundle-template/releases/tag/v1.7.0
180190
[1.6.0]: https://github.com/vmariiechko/databricks-bundle-template/releases/tag/v1.6.0
181191
[1.5.0]: https://github.com/vmariiechko/databricks-bundle-template/releases/tag/v1.5.0

ROADMAP.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Modular sub-templates installable via `databricks bundle init <repo-url> --templ
4747

4848
**Shipped:**
4949
- `sdp-checkpoint-recovery`: Reset checkpoint selection on a Lakeflow Spark Declarative Pipeline after a source table has been dropped and recreated
50+
- `dbx-ro-query`: Dependency-free Python wrapper around `databricks experimental aitools tools query` that gives LLM agents a guarded read-only SQL window into a Databricks workspace
51+
- `monitoring-sql-warehouse`: Dedicated serverless SQL warehouse tuned for bursty workloads (scheduled Alerts, monitoring queries) with `auto_stop_mins: 1`
5052

5153
**Possible future assets** (ideas for contributors, not commitments):
5254
- `etl-pipeline`: Medallion-layered Declarative Pipeline with Bronze/Silver layers and DLT expectations
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# monitoring-sql-warehouse
2+
3+
A small, dedicated serverless SQL warehouse tuned for bursty workloads: scheduled Databricks Alerts, monitoring queries, and ad-hoc health checks. Defaults to `2X-Small` with `auto_stop_mins: 1` so cost stays proportional to actual query time.
4+
5+
## Install
6+
7+
```bash
8+
databricks bundle init https://github.com/vmariiechko/databricks-bundle-template \
9+
--template-dir assets/monitoring-sql-warehouse
10+
```
11+
12+
You will be prompted for:
13+
14+
| Prompt | Default | Notes |
15+
|---|---|---|
16+
| `target_dir` | `resources` | Where the resource YAML lands. Default matches the `resources/*.yml` glob most bundles already include. |
17+
| `warehouse_resource_key` | `monitoring_sql_warehouse` | DABs key under `resources.sql_warehouses.<key>`. Also the resource filename. |
18+
| `warehouse_name` | `Monitoring SQL Warehouse` | Display name in the workspace SQL Warehouses list. |
19+
| `cluster_size` | `2X-Small` | One of: 2X-Small, X-Small, Small, Medium, Large, X-Large, 2X-Large, 3X-Large, 4X-Large. |
20+
| `auto_stop_mins` | `1` | Integer. `1` is the serverless minimum; `0` disables auto-stop; `10+` for Pro/Classic. |
21+
22+
Two files are installed:
23+
24+
- `<target_dir>/<warehouse_resource_key>.sql_warehouse.yml`: the DABs resource definition (serverless PRO, single cluster, channel pinned to `CHANNEL_NAME_CURRENT`, tagged `workload=monitoring-alerts` and `created_by=dabs-asset/monitoring-sql-warehouse`).
25+
- `docs/monitoring-sql-warehouse/README.md`: usage notes, the `auto_stop_mins: 1` serverless nuance, and CLI/API paths for editing existing warehouses outside DABs.
26+
27+
## Usage
28+
29+
After install, open `docs/monitoring-sql-warehouse/README.md` in your project for deploy steps, the cross-resource reference pattern (`${resources.sql_warehouses.<key>.id}`), and the auto-stop behavior reference table.
30+
31+
## What this asset is
32+
33+
A standalone sub-template in the [databricks-bundle-template](https://github.com/vmariiechko/databricks-bundle-template) asset library. It does not depend on the core template; it can be installed into any Databricks bundle. See [ASSETS.md](../../ASSETS.md) for the full catalog.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"welcome_message": "\nMonitoring SQL Warehouse: Asset Installer\n\nInstalls a single Declarative Automation Bundle resource file that\ndefines a small, dedicated serverless SQL warehouse tuned for bursty\nworkloads (scheduled Databricks Alerts, monitoring queries, ad-hoc\nhealth checks).\n\nWhy it exists: Alerts and monitoring queries are sub-second, but a\ngeneral-purpose warehouse on a long auto-stop window stays warm for\nminutes after each run. Idle time dominates the bill. A dedicated\n2X-Small serverless warehouse with auto_stop_mins=1 keeps the cost\nproportional to actual query time.\n\nThe asset is opinionated about serverless PRO: the 1-minute auto-stop\nis only valid on serverless. Pro/Classic stay at the 10-minute floor.\n\nLet's pick the install settings...\n",
3+
4+
"properties": {
5+
"target_dir": {
6+
"type": "string",
7+
"default": "resources",
8+
"description": "\nTarget directory for the warehouse resource file (relative to your bundle root).\nMost bundles already include `resources/*.yml` from databricks.yml, so the\ndefault `resources` lands the file where the bundle will auto-pick it up.\n\nIf your bundle uses a different convention (e.g., `resources/sql_warehouses/`),\nset that here. The directory will be created if it does not exist.\ntarget_dir",
9+
"order": 1,
10+
"pattern": "^[A-Za-z0-9_][A-Za-z0-9_./-]*$",
11+
"pattern_match_failure_message": "Target directory must start with a letter, number, or underscore and contain only letters, numbers, underscores, slashes, hyphens, or dots."
12+
},
13+
14+
"warehouse_resource_key": {
15+
"type": "string",
16+
"default": "monitoring_sql_warehouse",
17+
"description": "\n========================================\n\nDABs resource key for the warehouse.\n\nThis key appears in the bundle as `resources.sql_warehouses.<key>` and is\nalso the filename: `<target_dir>/<key>.sql_warehouse.yml`. Other bundle\nresources reference this warehouse by `${resources.sql_warehouses.<key>.id}`.\n\nDefault `monitoring_sql_warehouse` is safe for most projects. Pick another\nname only if your bundle already defines a warehouse with this key.\nMust be lowercase snake_case (letters, numbers, underscores).\nwarehouse_resource_key",
18+
"order": 2,
19+
"pattern": "^[a-z][a-z0-9_]*$",
20+
"pattern_match_failure_message": "Resource key must be lowercase, start with a letter, and contain only letters, numbers, and underscores."
21+
},
22+
23+
"warehouse_name": {
24+
"type": "string",
25+
"default": "Monitoring SQL Warehouse",
26+
"description": "\n========================================\n\nDisplay name shown in the Databricks workspace SQL Warehouses list.\n\nThis is what users see in the UI when picking a warehouse for an Alert\nor query. Free-form; spaces and mixed case are fine.\nwarehouse_name",
27+
"order": 3,
28+
"pattern": "^.+$",
29+
"pattern_match_failure_message": "Warehouse name cannot be empty."
30+
},
31+
32+
"cluster_size": {
33+
"type": "string",
34+
"default": "2X-Small",
35+
"description": "\n========================================\n\nCluster size for the warehouse.\n\nValid Databricks SQL warehouse sizes (smallest to largest):\n 2X-Small, X-Small, Small, Medium, Large, X-Large, 2X-Large, 3X-Large, 4X-Large, 5X-Large\n\nDefault `2X-Small` is the smallest and cheapest. It is sufficient for\nDatabricks Alerts and monitoring queries that complete in under a second.\nScale up only if your queries scan large tables.\ncluster_size",
36+
"order": 4,
37+
"pattern": "^(2X-Small|X-Small|Small|Medium|Large|X-Large|2X-Large|3X-Large|4X-Large|5X-Large)$",
38+
"pattern_match_failure_message": "Cluster size must be one of: 2X-Small, X-Small, Small, Medium, Large, X-Large, 2X-Large, 3X-Large, 4X-Large, 5X-Large."
39+
},
40+
41+
"auto_stop_mins": {
42+
"type": "string",
43+
"default": "1",
44+
"description": "\n========================================\n\nIdle minutes before the warehouse auto-stops (integer).\n\nDefault `1` is the serverless minimum verified via DABs deploy: the UI\nshows 'After 1 minute of inactivity'. Sub-minute values are NOT supported\n(the field is modeled as an integer).\n\nSpecial values:\n 0 = disable auto-stop entirely (warehouse runs until manually stopped)\n 1 = serverless minimum (recommended for Alerts / bursty workloads)\n 10+ = required floor for Pro/Classic warehouses; safe upper bound for serverless too\n\nKeep at 1 unless you have a reason to override.\nauto_stop_mins",
45+
"order": 5,
46+
"pattern": "^(0|[1-9][0-9]*)$",
47+
"pattern_match_failure_message": "auto_stop_mins must be a non-negative integer (0 to disable, 1 for serverless minimum, 10+ for Pro/Classic)."
48+
}
49+
},
50+
51+
"success_message": "\n========================================\n\nMonitoring SQL warehouse installed:\n - Resource: {{.target_dir}}/{{.warehouse_resource_key}}.sql_warehouse.yml\n - Usage doc: docs/monitoring-sql-warehouse/README.md\n\nNext steps:\n\n1. Confirm your `databricks.yml` includes the resource file. Most bundles\n already include `resources/*.yml` by default; verify:\n include:\n - resources/*.yml\n If you installed to a custom subdirectory, add the matching glob.\n\n2. Validate and deploy:\n databricks bundle validate -t <your-target>\n databricks bundle deploy -t <your-target>\n\n3. After deploy, the warehouse appears in the workspace SQL Warehouses list\n as '{{.warehouse_name}}'. Point your Alerts / monitoring queries at it.\n\n4. Reference the warehouse ID from other bundle resources via:\n ${resources.sql_warehouses.{{.warehouse_resource_key}}.id}\n\nUsage notes, the auto_stop_mins=1 nuance, and the CLI/API paths for\nexisting warehouses live in 'docs/monitoring-sql-warehouse/README.md'.\n",
52+
53+
"min_databricks_cli_version": "v0.296.0",
54+
"version": 1
55+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Monitoring SQL Warehouse
2+
3+
A small, dedicated serverless SQL warehouse for scheduled Databricks Alerts, monitoring queries, and ad-hoc health checks. Optimized for bursty, sub-second workloads where idle time would otherwise dominate the bill.
4+
5+
## When to use this
6+
7+
Use a dedicated warehouse like this when:
8+
9+
- You run scheduled Databricks Alerts (every minute, every five minutes, every hour) whose underlying SQL completes in well under a second.
10+
- The default warehouse those queries land on has a long auto-stop window (10 minutes is the platform default for Pro/Classic; serverless allows 1 minute).
11+
- You see the warehouse staying warm for the full auto-stop window after a single sub-second query, inflating monthly cost.
12+
13+
A separate `2X-Small` serverless warehouse with `auto_stop_mins: 1` keeps cost proportional to actual query time: the warehouse starts on the Alert run, executes in under a second, and stops one minute after the last query.
14+
15+
## What this asset installs
16+
17+
| Path | Purpose |
18+
|---|---|
19+
| `<target_dir>/<warehouse_resource_key>.sql_warehouse.yml` | The DABs SQL warehouse resource definition. |
20+
| `docs/monitoring-sql-warehouse/README.md` | This file. |
21+
22+
Default install paths:
23+
24+
- Resource: `resources/monitoring_sql_warehouse.sql_warehouse.yml`
25+
- Docs: `docs/monitoring-sql-warehouse/README.md`
26+
27+
## Bundle integration
28+
29+
Most generated bundles already include `resources/*.yml` from `databricks.yml`:
30+
31+
```yaml
32+
include:
33+
- resources/*.yml
34+
```
35+
36+
If your bundle uses that pattern and you accepted the default `target_dir`, the warehouse is picked up automatically. No `databricks.yml` change is needed.
37+
38+
If you installed to a custom subdirectory (e.g., `resources/sql_warehouses/`), add the matching glob to `databricks.yml`:
39+
40+
```yaml
41+
include:
42+
- resources/sql_warehouses/*.yml
43+
```
44+
45+
## Deploy
46+
47+
```bash
48+
databricks bundle validate -t <your-target>
49+
databricks bundle deploy -t <your-target>
50+
```
51+
52+
After deploy, the warehouse appears in the workspace SQL Warehouses list under the display name you chose at install time.
53+
54+
## Referencing the warehouse from other bundle resources
55+
56+
Other resources (Alerts, jobs, dashboards) can pin to this warehouse by ID:
57+
58+
```yaml
59+
${resources.sql_warehouses.<warehouse_resource_key>.id}
60+
```
61+
62+
For example, an Alert resource:
63+
64+
```yaml
65+
resources:
66+
alerts:
67+
my_alert:
68+
warehouse_id: ${resources.sql_warehouses.monitoring_sql_warehouse.id}
69+
# ... rest of the alert definition
70+
```
71+
72+
## The `auto_stop_mins: 1` nuance
73+
74+
The proven configuration was verified by deploying this asset to a real workspace (Databricks SQL channel v2026.10). The notes below capture behavior that contradicts or refines parts of the public API reference.
75+
76+
| Setting | Behavior |
77+
|---|---|
78+
| `auto_stop_mins: 0` | Disables auto-stop entirely. The warehouse runs until manually stopped. Does NOT mean "stop immediately." |
79+
| `auto_stop_mins: 1` | Valid and effective on serverless via DABs/API. The workspace UI shows "After 1 minute of inactivity." This is the recommended value for Alerts and monitoring workloads. |
80+
| `auto_stop_mins: 0.5` (or any sub-minute value) | Not supported. The field is modeled as an integer; the bundle CLI emits an integer-coercion warning and the workspace silently reverts to the platform default (120 minutes). |
81+
| `auto_stop_mins: 10+` | Per the public [Warehouses API reference][create-warehouse-api], the documented contract is `auto_stop_mins` must be `0` or `>= 10`. This floor applies to Pro/Classic warehouses. Safe upper bound for serverless too. |
82+
83+
The public [Warehouses API reference][create-warehouse-api] states that `auto_stop_mins` must be `0` or `>= 10`. That floor applies to Pro/Classic warehouses; the serverless path accepts `1` end-to-end via DABs and via the CLI (confirmed by deploying this resource and inspecting the workspace UI).
84+
85+
The manual UI editor for an existing warehouse may enforce a higher floor on serverless than 1 minute. If you see that, fall back to the DABs path or the `databricks warehouses edit` CLI path, both of which apply `1` on serverless.
86+
87+
[create-warehouse-api]: https://docs.databricks.com/api/workspace/warehouses/create
88+
[edit-warehouse-api]: https://docs.databricks.com/api/workspace/warehouses/edit
89+
90+
## Applying the same tuning to a warehouse created outside DABs
91+
92+
If you have an existing warehouse that you do not want to recreate as a DABs resource, you can edit it in place to the same auto-stop behavior.
93+
94+
### Via the Databricks CLI
95+
96+
```bash
97+
databricks warehouses edit <warehouse-id> --auto-stop-mins 1
98+
```
99+
100+
The full flag set is visible via `databricks warehouses edit --help`. For serverless, also ensure `--enable-serverless-compute` is on and `--warehouse-type PRO` is set.
101+
102+
### Via the REST API
103+
104+
Use the [Edit Warehouse endpoint][edit-warehouse-api] (`POST /api/2.0/sql/warehouses/{id}/edit`) with `auto_stop_mins: 1`. For serverless, include `enable_serverless_compute: true` and `warehouse_type: PRO` in the request body. The endpoint reference still documents the `0 or >= 10` contract; the serverless `1` value is accepted in practice and is what DABs and the CLI emit.
105+
106+
```bash
107+
curl -X POST \
108+
-H "Authorization: Bearer $DATABRICKS_TOKEN" \
109+
-H "Content-Type: application/json" \
110+
https://$DATABRICKS_HOST/api/2.0/sql/warehouses/<warehouse-id>/edit \
111+
-d '{
112+
"auto_stop_mins": 1,
113+
"enable_serverless_compute": true,
114+
"warehouse_type": "PRO"
115+
}'
116+
```
117+
118+
### Via the workspace UI
119+
120+
The "Edit warehouse" form may enforce a higher minimum than 1 minute for serverless. If the UI rejects `1`, use the CLI or DABs path.
121+
122+
## Cost intuition
123+
124+
A `2X-Small` serverless warehouse billed per second of running time, kept warm by a 1-minute auto-stop after each sub-second query, costs a small constant per scheduled run plus the query duration itself. Compared to a 10-minute auto-stop window on the same size warehouse, the per-run dwell time drops by an order of magnitude. Apply this to dozens of scheduled Alerts and the monthly delta is meaningful.
125+
126+
## References
127+
128+
1. [Databricks Docs: Configure SQL warehouse settings (auto-stop)](https://docs.databricks.com/aws/en/compute/sql-warehouse/warehouse-behavior)
129+
2. [Declarative Automation Bundles: `sql_warehouses` resource reference](https://docs.databricks.com/aws/en/dev-tools/bundles/resources.html#sql_warehouse)
130+
3. [Databricks API: Create Warehouse][create-warehouse-api] (`auto_stop_mins` contract)
131+
4. [Databricks API: Edit Warehouse][edit-warehouse-api] (in-place edits to an existing warehouse)
132+
5. [Databricks CLI: `databricks warehouses edit`](https://docs.databricks.com/aws/en/dev-tools/cli/reference/warehouses-commands.html#edit)
133+
6. [Databricks Alerts overview](https://docs.databricks.com/aws/en/sql/user/alerts/)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Monitoring SQL Warehouse
2+
#
3+
# Small, dedicated serverless SQL warehouse tuned for bursty workloads:
4+
# scheduled Databricks Alerts, monitoring queries, ad-hoc health checks.
5+
#
6+
# Why a dedicated warehouse: a general-purpose warehouse on a long
7+
# auto-stop window stays warm for minutes after a sub-second Alert
8+
# query, and idle time dominates the bill. A 2X-Small serverless
9+
# warehouse with auto_stop_mins=1 keeps cost proportional to actual
10+
# query time.
11+
#
12+
# Reference this warehouse from other bundle resources via:
13+
# ${resources.sql_warehouses.{{.warehouse_resource_key}}.id}
14+
#
15+
# See docs/monitoring-sql-warehouse/README.md for usage notes,
16+
# the auto_stop_mins=1 serverless nuance, and CLI/API alternatives
17+
# for warehouses created outside DABs.
18+
19+
resources:
20+
sql_warehouses:
21+
{{.warehouse_resource_key}}:
22+
name: {{.warehouse_name}}
23+
cluster_size: {{.cluster_size}}
24+
warehouse_type: PRO
25+
enable_serverless_compute: true
26+
auto_stop_mins: {{.auto_stop_mins}}
27+
min_num_clusters: 1
28+
max_num_clusters: 1
29+
# Pin to the stable Databricks SQL channel. Prevents Preview-channel
30+
# feature flags from changing query behavior under monitoring queries
31+
# that are assumed-stable. Override to CHANNEL_NAME_PREVIEW only if
32+
# you are intentionally validating an upcoming release.
33+
channel:
34+
name: CHANNEL_NAME_CURRENT
35+
tags:
36+
custom_tags:
37+
- key: workload
38+
value: monitoring-alerts
39+
- key: created_by
40+
value: dabs-asset/monitoring-sql-warehouse

0 commit comments

Comments
 (0)