Skip to content

Commit c2e15b7

Browse files
Fix: Support trigger_pause_status preset in alerts (databricks#4323)
## Changes Apply the `trigger_pause_status` preset to SQL Alerts, similar to how it's already applied to Jobs and Pipelines. ## Why Fixes databricks#4316. SQL Alerts were ignoring the `trigger_pause_status` preset configured at the target level, while Jobs correctly respected it. This caused alerts to remain unpaused even when `trigger_pause_status: PAUSED` was set. ## Tests Added unit tests covering: - Alert with schedule (no explicit pause_status) → gets paused by preset - Alert with schedule and explicit `UNPAUSED` → remains unpaused - Alert without schedule → pause_status remains empty Also, manually tested that this works as expected.
1 parent 2c96f11 commit c2e15b7

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
* Improve performance of `databricks fs cp` command by parallelizing file uploads when
1010
copying directories with the `--recursive` flag.
11+
* Fix: Support trigger_pause_status preset in alerts ([#4323](https://github.com/databricks/cli/pull/4323))
1112

1213
### Bundles
1314

bundle/config/mutator/resourcemutator/apply_presets.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,22 @@ func (m *applyPresets) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnos
239239

240240
// Apps: No presets
241241

242-
// Alerts: Prefix
242+
// Alerts: Prefix, TriggerPauseStatus
243243
for _, a := range r.Alerts {
244244
if a == nil {
245245
continue
246246
}
247247
a.DisplayName = prefix + a.DisplayName
248+
if t.TriggerPauseStatus != "" {
249+
paused := sql.SchedulePauseStatusPaused
250+
if t.TriggerPauseStatus == config.Unpaused {
251+
paused = sql.SchedulePauseStatusUnpaused
252+
}
253+
// Only set pause status if a schedule is defined and pause status is not already set
254+
if a.Schedule.QuartzCronSchedule != "" && a.Schedule.PauseStatus == "" {
255+
a.Schedule.PauseStatus = paused
256+
}
257+
}
248258
}
249259

250260
// SQL Warehouses: Prefix, Tags

bundle/config/mutator/resourcemutator/apply_target_mode_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,23 @@ func mockBundle(mode config.Mode) *bundle.Bundle {
191191
"alert1": {
192192
AlertV2: sql.AlertV2{
193193
DisplayName: "alert1",
194+
Schedule: sql.CronSchedule{
195+
QuartzCronSchedule: "0 0 12 * * ?",
196+
},
197+
},
198+
},
199+
"alert2": {
200+
AlertV2: sql.AlertV2{
201+
DisplayName: "alert2",
202+
Schedule: sql.CronSchedule{
203+
QuartzCronSchedule: "0 0 12 * * ?",
204+
PauseStatus: sql.SchedulePauseStatusUnpaused,
205+
},
206+
},
207+
},
208+
"alert3": {
209+
AlertV2: sql.AlertV2{
210+
DisplayName: "alert3",
194211
},
195212
},
196213
},
@@ -258,6 +275,18 @@ func TestProcessTargetModeDevelopment(t *testing.T) {
258275

259276
// Dashboards
260277
assert.Equal(t, "[dev lennart] dashboard1", b.Config.Resources.Dashboards["dashboard1"].DisplayName)
278+
279+
// Alert 1: has schedule without pause status set - should be paused
280+
assert.Equal(t, "[dev lennart] alert1", b.Config.Resources.Alerts["alert1"].DisplayName)
281+
assert.Equal(t, sql.SchedulePauseStatusPaused, b.Config.Resources.Alerts["alert1"].Schedule.PauseStatus)
282+
283+
// Alert 2: has schedule with pause status already set to unpaused - should remain unpaused
284+
assert.Equal(t, "[dev lennart] alert2", b.Config.Resources.Alerts["alert2"].DisplayName)
285+
assert.Equal(t, sql.SchedulePauseStatusUnpaused, b.Config.Resources.Alerts["alert2"].Schedule.PauseStatus)
286+
287+
// Alert 3: no schedule - pause status should remain empty
288+
assert.Equal(t, "[dev lennart] alert3", b.Config.Resources.Alerts["alert3"].DisplayName)
289+
assert.Empty(t, b.Config.Resources.Alerts["alert3"].Schedule.PauseStatus)
261290
}
262291

263292
func TestProcessTargetModeDevelopmentTagNormalizationForAws(t *testing.T) {

0 commit comments

Comments
 (0)