Skip to content

Commit

Permalink
update to 1.45 and rename to quality monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
aravind-segu committed May 25, 2024
1 parent d7ae5e9 commit c240c31
Show file tree
Hide file tree
Showing 30 changed files with 873 additions and 303 deletions.
12 changes: 6 additions & 6 deletions bundle/config/mutator/process_target_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func mockBundle(mode config.Mode) *bundle.Bundle {
RegisteredModels: map[string]*resources.RegisteredModel{
"registeredmodel1": {CreateRegisteredModelRequest: &catalog.CreateRegisteredModelRequest{Name: "registeredmodel1"}},
},
Monitors: map[string]*resources.Monitor{
"monitor1": {CreateMonitor: &catalog.CreateMonitor{TableName: "monitor1"}},
QualityMonitors: map[string]*resources.QualityMonitor{
"qualityMonitor1": {CreateMonitor: &catalog.CreateMonitor{TableName: "qualityMonitor1"}},
},
},
},
Expand Down Expand Up @@ -149,8 +149,8 @@ func TestProcessTargetModeDevelopment(t *testing.T) {
// Registered model 1
assert.Equal(t, "dev_lennart_registeredmodel1", b.Config.Resources.RegisteredModels["registeredmodel1"].Name)

//Monitor 1
assert.Equal(t, "monitor1", b.Config.Resources.Monitors["monitor1"].TableName)
//Quality Monitor 1
assert.Equal(t, "qualityMonitor1", b.Config.Resources.QualityMonitors["qualityMonitor1"].TableName)
}

func TestProcessTargetModeDevelopmentTagNormalizationForAws(t *testing.T) {
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestProcessTargetModeDefault(t *testing.T) {
assert.False(t, b.Config.Resources.Pipelines["pipeline1"].PipelineSpec.Development)
assert.Equal(t, "servingendpoint1", b.Config.Resources.ModelServingEndpoints["servingendpoint1"].Name)
assert.Equal(t, "registeredmodel1", b.Config.Resources.RegisteredModels["registeredmodel1"].Name)
assert.Equal(t, "monitor1", b.Config.Resources.Monitors["monitor1"].TableName)
assert.Equal(t, "qualityMonitor1", b.Config.Resources.QualityMonitors["qualityMonitor1"].TableName)
}

func TestProcessTargetModeProduction(t *testing.T) {
Expand Down Expand Up @@ -247,7 +247,7 @@ func TestProcessTargetModeProduction(t *testing.T) {
assert.False(t, b.Config.Resources.Pipelines["pipeline1"].PipelineSpec.Development)
assert.Equal(t, "servingendpoint1", b.Config.Resources.ModelServingEndpoints["servingendpoint1"].Name)
assert.Equal(t, "registeredmodel1", b.Config.Resources.RegisteredModels["registeredmodel1"].Name)
assert.Equal(t, "monitor1", b.Config.Resources.Monitors["monitor1"].TableName)
assert.Equal(t, "qualityMonitor1", b.Config.Resources.QualityMonitors["qualityMonitor1"].TableName)
}

func TestProcessTargetModeProductionOkForPrincipal(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions bundle/config/mutator/run_as.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ func validateRunAs(b *bundle.Bundle) error {
}

// Monitors do not support run_as in the API.
if len(b.Config.Resources.Monitors) > 0 {
if len(b.Config.Resources.QualityMonitors) > 0 {
return errUnsupportedResourceTypeForRunAs{
resourceType: "monitors",
resourceLocation: b.Config.GetLocation("resources.monitors"),
resourceType: "quality_monitors",
resourceLocation: b.Config.GetLocation("resources.quality_monitors"),
currentUser: b.Config.Workspace.CurrentUser.UserName,
runAsUser: identity,
}
Expand Down
3 changes: 2 additions & 1 deletion bundle/config/mutator/run_as_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func allResourceTypes(t *testing.T) []string {
"jobs",
"model_serving_endpoints",
"models",
"monitors",
"pipelines",
"quality_monitors",
"registered_models",
},
resourceTypes,
Expand Down Expand Up @@ -173,6 +173,7 @@ func TestRunAsErrorForUnsupportedResources(t *testing.T) {
r := &config.Root{}
err = convert.ToTyped(r, nv)
require.NoError(t, err)

// Assert this invalid bundle configuration fails validation.
b := &bundle.Bundle{
Config: *r,
Expand Down
18 changes: 12 additions & 6 deletions bundle/config/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Resources struct {
Experiments map[string]*resources.MlflowExperiment `json:"experiments,omitempty"`
ModelServingEndpoints map[string]*resources.ModelServingEndpoint `json:"model_serving_endpoints,omitempty"`
RegisteredModels map[string]*resources.RegisteredModel `json:"registered_models,omitempty"`
Monitors map[string]*resources.Monitor `json:"monitors,omitempty"`
QualityMonitors map[string]*resources.QualityMonitor `json:"quality_monitors,omitempty"`
}

type UniqueResourceIdTracker struct {
Expand Down Expand Up @@ -124,18 +124,18 @@ func (r *Resources) VerifyUniqueResourceIdentifiers() (*UniqueResourceIdTracker,
tracker.Type[k] = "registered_model"
tracker.ConfigPath[k] = r.RegisteredModels[k].ConfigFilePath
}
for k := range r.Monitors {
for k := range r.QualityMonitors {
if _, ok := tracker.Type[k]; ok {
return tracker, fmt.Errorf("multiple resources named %s (%s at %s, %s at %s)",
k,
tracker.Type[k],
tracker.ConfigPath[k],
"monitor",
r.Monitors[k].ConfigFilePath,
"quality_monitor",
r.QualityMonitors[k].ConfigFilePath,
)
}
tracker.Type[k] = "monitor"
tracker.ConfigPath[k] = r.Monitors[k].ConfigFilePath
tracker.Type[k] = "quality_monitor"
tracker.ConfigPath[k] = r.QualityMonitors[k].ConfigFilePath
}
return tracker, nil
}
Expand Down Expand Up @@ -166,6 +166,9 @@ func (r *Resources) allResources() []resource {
for k, e := range r.RegisteredModels {
all = append(all, resource{resource_type: "registered model", resource: e, key: k})
}
for k, e := range r.QualityMonitors {
all = append(all, resource{resource_type: "quality monitor", resource: e, key: k})
}
return all
}

Expand Down Expand Up @@ -203,6 +206,9 @@ func (r *Resources) ConfigureConfigFilePath() {
for _, e := range r.RegisteredModels {
e.ConfigureConfigFilePath()
}
for _, e := range r.QualityMonitors {
e.ConfigureConfigFilePath()
}
}

type ConfigResource interface {
Expand Down
23 changes: 0 additions & 23 deletions bundle/config/resources/monitor.go

This file was deleted.

60 changes: 60 additions & 0 deletions bundle/config/resources/quality_monitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package resources

import (
"context"
"fmt"

"github.com/databricks/cli/bundle/config/paths"
"github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/marshal"
"github.com/databricks/databricks-sdk-go/service/catalog"
)

type QualityMonitor struct {
// Represents the Input Arguments for Terraform and will get
// converted to a HCL representation for CRUD
*catalog.CreateMonitor

// This represents the id which is the full name of the monitor
// (catalog_name.schema_name.table_name) that can be used
// as a reference in other resources. This value is returned by terraform.
ID string `json:"id,omitempty" bundle:"readonly"`

// Path to config file where the resource is defined. All bundle resources
// include this for interpolation purposes.
paths.Paths

ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"`
}

func (s *QualityMonitor) UnmarshalJSON(b []byte) error {
return marshal.Unmarshal(b, s)
}

func (s QualityMonitor) MarshalJSON() ([]byte, error) {
return marshal.Marshal(s)
}

func (s *QualityMonitor) Exists(ctx context.Context, w *databricks.WorkspaceClient, id string) (bool, error) {
_, err := w.QualityMonitors.Get(ctx, catalog.GetQualityMonitorRequest{
TableName: id,
})
if err != nil {
log.Debugf(ctx, "registered model %s does not exist", id)
return false, err
}
return true, nil
}

func (s *QualityMonitor) TerraformResourceName() string {
return "databricks_quality_monitor"
}

func (s *QualityMonitor) Validate() error {
if s == nil || !s.DynamicValue.IsValid() {
return fmt.Errorf("registered model is not defined")
}

return nil
}
20 changes: 10 additions & 10 deletions bundle/deploy/terraform/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ func BundleToTerraform(config *config.Root) *schema.Root {
}
}

for k, src := range config.Resources.Monitors {
for k, src := range config.Resources.QualityMonitors {
noResources = false
var dst schema.ResourceLakehouseMonitor
var dst schema.ResourceQualityMonitor
conv(src, &dst)
tfroot.Resource.LakehouseMonitor[k] = &dst
tfroot.Resource.QualityMonitor[k] = &dst
}

// We explicitly set "resource" to nil to omit it from a JSON encoding.
Expand Down Expand Up @@ -372,16 +372,16 @@ func TerraformToBundle(state *resourcesState, config *config.Root) error {
}
cur.ID = instance.Attributes.ID
config.Resources.RegisteredModels[resource.Name] = cur
case "databricks_monitor":
if config.Resources.Monitors == nil {
config.Resources.Monitors = make(map[string]*resources.Monitor)
case "databricks_quality_monitor":
if config.Resources.QualityMonitors == nil {
config.Resources.QualityMonitors = make(map[string]*resources.QualityMonitor)
}
cur := config.Resources.Monitors[resource.Name]
cur := config.Resources.QualityMonitors[resource.Name]
if cur == nil {
cur = &resources.Monitor{ModifiedStatus: resources.ModifiedStatusDeleted}
cur = &resources.QualityMonitor{ModifiedStatus: resources.ModifiedStatusDeleted}
}
cur.ID = instance.Attributes.ID
config.Resources.Monitors[resource.Name] = cur
config.Resources.QualityMonitors[resource.Name] = cur
case "databricks_permissions":
case "databricks_grants":
// Ignore; no need to pull these back into the configuration.
Expand Down Expand Up @@ -421,7 +421,7 @@ func TerraformToBundle(state *resourcesState, config *config.Root) error {
src.ModifiedStatus = resources.ModifiedStatusCreated
}
}
for _, src := range config.Resources.Monitors {
for _, src := range config.Resources.QualityMonitors {
if src.ModifiedStatus == "" && src.ID == "" {
src.ModifiedStatus = resources.ModifiedStatusCreated
}
Expand Down
30 changes: 15 additions & 15 deletions bundle/deploy/terraform/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ func TestTerraformToBundleEmptyLocalResources(t *testing.T) {
},
},
{
Type: "databricks_monitor",
Type: "databricks_quality_monitor",
Mode: "managed",
Name: "test_monitor",
Instances: []stateResourceInstance{
Expand Down Expand Up @@ -660,8 +660,8 @@ func TestTerraformToBundleEmptyLocalResources(t *testing.T) {
assert.Equal(t, "1", config.Resources.RegisteredModels["test_registered_model"].ID)
assert.Equal(t, resources.ModifiedStatusDeleted, config.Resources.RegisteredModels["test_registered_model"].ModifiedStatus)

assert.Equal(t, "1", config.Resources.Monitors["test_monitor"].ID)
assert.Equal(t, resources.ModifiedStatusDeleted, config.Resources.Monitors["test_monitor"].ModifiedStatus)
assert.Equal(t, "1", config.Resources.QualityMonitors["test_monitor"].ID)
assert.Equal(t, resources.ModifiedStatusDeleted, config.Resources.QualityMonitors["test_monitor"].ModifiedStatus)
AssertFullResourceCoverage(t, &config)
}

Expand Down Expand Up @@ -710,7 +710,7 @@ func TestTerraformToBundleEmptyRemoteResources(t *testing.T) {
},
},
},
Monitors: map[string]*resources.Monitor{
QualityMonitors: map[string]*resources.QualityMonitor{
"test_monitor": {
CreateMonitor: &catalog.CreateMonitor{
TableName: "test_monitor",
Expand Down Expand Up @@ -743,8 +743,8 @@ func TestTerraformToBundleEmptyRemoteResources(t *testing.T) {
assert.Equal(t, "", config.Resources.RegisteredModels["test_registered_model"].ID)
assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.RegisteredModels["test_registered_model"].ModifiedStatus)

assert.Equal(t, "", config.Resources.Monitors["test_monitor"].ID)
assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.Monitors["test_monitor"].ModifiedStatus)
assert.Equal(t, "", config.Resources.QualityMonitors["test_monitor"].ID)
assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.QualityMonitors["test_monitor"].ModifiedStatus)

AssertFullResourceCoverage(t, &config)
}
Expand Down Expand Up @@ -824,7 +824,7 @@ func TestTerraformToBundleModifiedResources(t *testing.T) {
},
},
},
Monitors: map[string]*resources.Monitor{
QualityMonitors: map[string]*resources.QualityMonitor{
"test_monitor": {
CreateMonitor: &catalog.CreateMonitor{
TableName: "test_monitor",
Expand Down Expand Up @@ -937,15 +937,15 @@ func TestTerraformToBundleModifiedResources(t *testing.T) {
},
},
{
Type: "databricks_monitor",
Type: "databricks_quality_monitor",
Mode: "managed",
Name: "test_monitor",
Instances: []stateResourceInstance{
{Attributes: stateInstanceAttributes{ID: "test_monitor"}},
},
},
{
Type: "databricks_monitor",
Type: "databricks_quality_monitor",
Mode: "managed",
Name: "test_monitor_old",
Instances: []stateResourceInstance{
Expand Down Expand Up @@ -999,12 +999,12 @@ func TestTerraformToBundleModifiedResources(t *testing.T) {
assert.Equal(t, "", config.Resources.ModelServingEndpoints["test_model_serving_new"].ID)
assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.ModelServingEndpoints["test_model_serving_new"].ModifiedStatus)

assert.Equal(t, "test_monitor", config.Resources.Monitors["test_monitor"].ID)
assert.Equal(t, "", config.Resources.Monitors["test_monitor"].ModifiedStatus)
assert.Equal(t, "test_monitor_old", config.Resources.Monitors["test_monitor_old"].ID)
assert.Equal(t, resources.ModifiedStatusDeleted, config.Resources.Monitors["test_monitor_old"].ModifiedStatus)
assert.Equal(t, "", config.Resources.Monitors["test_monitor_new"].ID)
assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.Monitors["test_monitor_new"].ModifiedStatus)
assert.Equal(t, "test_monitor", config.Resources.QualityMonitors["test_monitor"].ID)
assert.Equal(t, "", config.Resources.QualityMonitors["test_monitor"].ModifiedStatus)
assert.Equal(t, "test_monitor_old", config.Resources.QualityMonitors["test_monitor_old"].ID)
assert.Equal(t, resources.ModifiedStatusDeleted, config.Resources.QualityMonitors["test_monitor_old"].ModifiedStatus)
assert.Equal(t, "", config.Resources.QualityMonitors["test_monitor_new"].ID)
assert.Equal(t, resources.ModifiedStatusCreated, config.Resources.QualityMonitors["test_monitor_new"].ModifiedStatus)
AssertFullResourceCoverage(t, &config)
}

Expand Down
4 changes: 2 additions & 2 deletions bundle/deploy/terraform/interpolate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func (m *interpolateMutator) Apply(ctx context.Context, b *bundle.Bundle) diag.D
path = dyn.NewPath(dyn.Key("databricks_model_serving")).Append(path[2:]...)
case dyn.Key("registered_models"):
path = dyn.NewPath(dyn.Key("databricks_registered_model")).Append(path[2:]...)
case dyn.Key("monitors"):
path = dyn.NewPath(dyn.Key("databricks_monitor")).Append(path[2:]...)
case dyn.Key("quality_monitors"):
path = dyn.NewPath(dyn.Key("databricks_quality_monitor")).Append(path[2:]...)
default:
// Trigger "key not found" for unknown resource types.
return dyn.GetByPath(root, path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ import (
"github.com/databricks/cli/libs/log"
)

func convertMonitorResource(ctx context.Context, vin dyn.Value) (dyn.Value, error) {
func convertQualityMonitorResource(ctx context.Context, vin dyn.Value) (dyn.Value, error) {
// Normalize the output value to the target schema.
vout, diags := convert.Normalize(schema.ResourceLakehouseMonitor{}, vin)
vout, diags := convert.Normalize(schema.ResourceQualityMonitor{}, vin)
for _, diag := range diags {
log.Debugf(ctx, "monitor normalization diagnostic: %s", diag.Summary)
}
return vout, nil
}

type monitorConverter struct{}
type qualityMonitorConverter struct{}

func (monitorConverter) Convert(ctx context.Context, key string, vin dyn.Value, out *schema.Resources) error {
vout, err := convertMonitorResource(ctx, vin)
func (qualityMonitorConverter) Convert(ctx context.Context, key string, vin dyn.Value, out *schema.Resources) error {
vout, err := convertQualityMonitorResource(ctx, vin)
if err != nil {
return err
}

// Add the converted resource to the output.
out.LakehouseMonitor[key] = vout.AsAny()
out.QualityMonitor[key] = vout.AsAny()

return nil
}

func init() {
registerConverter("monitors", monitorConverter{})
registerConverter("quality_monitors", qualityMonitorConverter{})
}
Loading

0 comments on commit c240c31

Please sign in to comment.