Skip to content

Commit 1db3840

Browse files
authored
Make TableName field part of quality monitor schema (#1903)
## Changes This field was special-cased in #1307 because it's not part of the JSON payload in the SDK struct. This approach, while pragmatic, meant it didn't show up in the JSON schema. While debugging an issue with quality monitors in #1900, I couldn't figure out why I was getting schema errors on this field, or how it was passed through to the TF representation. This commit removes the special case and makes it behave like everything else. ## Tests * Unit tests pass. * Confirmed that the updated schema failed validation before this change.
1 parent 1508d65 commit 1db3840

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

bundle/config/mutator/initialize_urls_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ func TestInitializeURLs(t *testing.T) {
6565
},
6666
QualityMonitors: map[string]*resources.QualityMonitor{
6767
"qualityMonitor1": {
68-
CreateMonitor: &catalog.CreateMonitor{
69-
TableName: "catalog.schema.qualityMonitor1",
70-
},
68+
TableName: "catalog.schema.qualityMonitor1",
69+
CreateMonitor: &catalog.CreateMonitor{},
7170
},
7271
},
7372
Schemas: map[string]*resources.Schema{

bundle/config/mutator/process_target_mode_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,23 @@ func mockBundle(mode config.Mode) *bundle.Bundle {
102102
"registeredmodel1": {CreateRegisteredModelRequest: &catalog.CreateRegisteredModelRequest{Name: "registeredmodel1"}},
103103
},
104104
QualityMonitors: map[string]*resources.QualityMonitor{
105-
"qualityMonitor1": {CreateMonitor: &catalog.CreateMonitor{TableName: "qualityMonitor1"}},
105+
"qualityMonitor1": {
106+
TableName: "qualityMonitor1",
107+
CreateMonitor: &catalog.CreateMonitor{
108+
OutputSchemaName: "catalog.schema",
109+
},
110+
},
106111
"qualityMonitor2": {
112+
TableName: "qualityMonitor2",
107113
CreateMonitor: &catalog.CreateMonitor{
108-
TableName: "qualityMonitor2",
109-
Schedule: &catalog.MonitorCronSchedule{},
114+
OutputSchemaName: "catalog.schema",
115+
Schedule: &catalog.MonitorCronSchedule{},
110116
},
111117
},
112118
"qualityMonitor3": {
119+
TableName: "qualityMonitor3",
113120
CreateMonitor: &catalog.CreateMonitor{
114-
TableName: "qualityMonitor3",
121+
OutputSchemaName: "catalog.schema",
115122
Schedule: &catalog.MonitorCronSchedule{
116123
PauseStatus: catalog.MonitorCronSchedulePauseStatusUnpaused,
117124
},

bundle/config/resources/quality_monitor.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ import (
1313
)
1414

1515
type QualityMonitor struct {
16-
// Represents the Input Arguments for Terraform and will get
17-
// converted to a HCL representation for CRUD
18-
*catalog.CreateMonitor
19-
20-
// This represents the id which is the full name of the monitor
21-
// (catalog_name.schema_name.table_name) that can be used
22-
// as a reference in other resources. This value is returned by terraform.
23-
ID string `json:"id,omitempty" bundle:"readonly"`
24-
16+
ID string `json:"id,omitempty" bundle:"readonly"`
2517
ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
2618
URL string `json:"url,omitempty" bundle:"internal"`
19+
20+
// The table name is a required field but not included as a JSON field in [catalog.CreateMonitor].
21+
TableName string `json:"table_name"`
22+
23+
// This struct defines the creation payload for a monitor.
24+
*catalog.CreateMonitor
2725
}
2826

2927
func (s *QualityMonitor) UnmarshalJSON(b []byte) error {

bundle/deploy/terraform/tfdyn/convert_quality_monitor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515

1616
func TestConvertQualityMonitor(t *testing.T) {
1717
var src = resources.QualityMonitor{
18+
TableName: "test_table_name",
1819
CreateMonitor: &catalog.CreateMonitor{
19-
TableName: "test_table_name",
2020
AssetsDir: "assets_dir",
2121
OutputSchemaName: "output_schema_name",
2222
InferenceLog: &catalog.MonitorInferenceLog{

bundle/internal/schema/testdata/pass/quality_monitor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ bundle:
44
resources:
55
quality_monitors:
66
myqualitymonitor:
7+
table_name: catalog.schema.quality_monitor
78
inference_log:
89
granularities:
910
- a

bundle/schema/jsonschema.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/dyn/convert/struct_info.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"sync"
77

88
"github.com/databricks/cli/libs/dyn"
9-
"github.com/databricks/cli/libs/textutil"
109
)
1110

1211
// structInfo holds the type information we need to efficiently
@@ -85,14 +84,6 @@ func buildStructInfo(typ reflect.Type) structInfo {
8584
}
8685

8786
name, _, _ := strings.Cut(sf.Tag.Get("json"), ",")
88-
if typ.Name() == "QualityMonitor" && name == "-" {
89-
urlName, _, _ := strings.Cut(sf.Tag.Get("url"), ",")
90-
if urlName == "" || urlName == "-" {
91-
name = textutil.CamelToSnakeCase(sf.Name)
92-
} else {
93-
name = urlName
94-
}
95-
}
9687
if name == "" || name == "-" {
9788
continue
9889
}

0 commit comments

Comments
 (0)