Skip to content

Commit

Permalink
Pause quality monitors when "mode: development" is used (#1481)
Browse files Browse the repository at this point in the history
## Changes

Similar to scheduled jobs, quality monitors should be paused when in
development mode (in line with the [behavior for scheduled
jobs](https://docs.databricks.com/en/dev-tools/bundles/deployment-modes.html)).
@aravind-segu @arpitjasa-db please take a look and verify this behavior.

- [x] Followup: documentation changes. If we make this change we should
update
https://docs.databricks.com/dev-tools/bundles/deployment-modes.html.

## Tests
Unit tests
  • Loading branch information
lennartkats-db authored Jun 19, 2024
1 parent cb4ab50 commit deb3e36
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
10 changes: 10 additions & 0 deletions bundle/config/mutator/process_target_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/databricks/databricks-sdk-go/service/ml"
)
Expand Down Expand Up @@ -105,6 +106,15 @@ func transformDevelopmentMode(ctx context.Context, b *bundle.Bundle) diag.Diagno
// (registered models in Unity Catalog don't yet support tags)
}

for i := range r.QualityMonitors {
// Remove all schedules from monitors, since they don't support pausing/unpausing.
// Quality monitors might support the "pause" property in the future, so at the
// CLI level we do respect that property if it is set to "unpaused".
if r.QualityMonitors[i].Schedule != nil && r.QualityMonitors[i].Schedule.PauseStatus != catalog.MonitorCronSchedulePauseStatusUnpaused {
r.QualityMonitors[i].Schedule = nil
}
}

return nil
}

Expand Down
16 changes: 16 additions & 0 deletions bundle/config/mutator/process_target_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ func mockBundle(mode config.Mode) *bundle.Bundle {
},
QualityMonitors: map[string]*resources.QualityMonitor{
"qualityMonitor1": {CreateMonitor: &catalog.CreateMonitor{TableName: "qualityMonitor1"}},
"qualityMonitor2": {
CreateMonitor: &catalog.CreateMonitor{
TableName: "qualityMonitor2",
Schedule: &catalog.MonitorCronSchedule{},
},
},
"qualityMonitor3": {
CreateMonitor: &catalog.CreateMonitor{
TableName: "qualityMonitor3",
Schedule: &catalog.MonitorCronSchedule{
PauseStatus: catalog.MonitorCronSchedulePauseStatusUnpaused,
},
},
},
},
},
},
Expand Down Expand Up @@ -151,6 +165,8 @@ func TestProcessTargetModeDevelopment(t *testing.T) {

// Quality Monitor 1
assert.Equal(t, "qualityMonitor1", b.Config.Resources.QualityMonitors["qualityMonitor1"].TableName)
assert.Nil(t, b.Config.Resources.QualityMonitors["qualityMonitor2"].Schedule)
assert.Equal(t, catalog.MonitorCronSchedulePauseStatusUnpaused, b.Config.Resources.QualityMonitors["qualityMonitor3"].Schedule.PauseStatus)
}

func TestProcessTargetModeDevelopmentTagNormalizationForAws(t *testing.T) {
Expand Down
15 changes: 11 additions & 4 deletions bundle/tests/quality_monitor/databricks.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
bundle:
name: quality_monitors

resources:
quality_monitors:
my_monitor:
table_name: "main.test.thing1"
table_name: "main.test.dev"
assets_dir: "/Shared/provider-test/databricks_monitoring/main.test.thing1"
output_schema_name: "test"
output_schema_name: "main.dev"
inference_log:
granularities: ["1 day"]
timestamp_col: "timestamp"
prediction_col: "prediction"
model_id_col: "model_id"
problem_type: "PROBLEM_TYPE_REGRESSION"
schedule:
quartz_cron_expression: "0 0 12 * * ?" # every day at noon
timezone_id: UTC

targets:
development:
mode: development
default: true
resources:
quality_monitors:
my_monitor:
Expand All @@ -24,14 +31,14 @@ targets:
quality_monitors:
my_monitor:
table_name: "main.test.staging"
output_schema_name: "staging"
output_schema_name: "main.staging"

production:
resources:
quality_monitors:
my_monitor:
table_name: "main.test.prod"
output_schema_name: "prod"
output_schema_name: "main.prod"
inference_log:
granularities: ["1 hour"]
timestamp_col: "timestamp_prod"
Expand Down
6 changes: 3 additions & 3 deletions bundle/tests/quality_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestMonitorTableNames(t *testing.T) {
p := b.Config.Resources.QualityMonitors["my_monitor"]
assert.Equal(t, "main.test.dev", p.TableName)
assert.Equal(t, "/Shared/provider-test/databricks_monitoring/main.test.thing1", p.AssetsDir)
assert.Equal(t, "test", p.OutputSchemaName)
assert.Equal(t, "main.dev", p.OutputSchemaName)

assertExpectedMonitor(t, p)
}
Expand All @@ -36,7 +36,7 @@ func TestMonitorStaging(t *testing.T) {
p := b.Config.Resources.QualityMonitors["my_monitor"]
assert.Equal(t, "main.test.staging", p.TableName)
assert.Equal(t, "/Shared/provider-test/databricks_monitoring/main.test.thing1", p.AssetsDir)
assert.Equal(t, "staging", p.OutputSchemaName)
assert.Equal(t, "main.staging", p.OutputSchemaName)

assertExpectedMonitor(t, p)
}
Expand All @@ -48,7 +48,7 @@ func TestMonitorProduction(t *testing.T) {
p := b.Config.Resources.QualityMonitors["my_monitor"]
assert.Equal(t, "main.test.prod", p.TableName)
assert.Equal(t, "/Shared/provider-test/databricks_monitoring/main.test.thing1", p.AssetsDir)
assert.Equal(t, "prod", p.OutputSchemaName)
assert.Equal(t, "main.prod", p.OutputSchemaName)

inferenceLog := p.InferenceLog
assert.Equal(t, []string{"1 day", "1 hour"}, inferenceLog.Granularities)
Expand Down

0 comments on commit deb3e36

Please sign in to comment.