Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/bundles/app-update-mask-compute-size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Stop sending `compute_size` in the app update mask when the bundle does not declare it, so a deploy no longer resets a manually resized app to the default size. ([#7461](https://github.com/databricks/cli/pull/7461))
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged
"description": "MY_APP_DESCRIPTION_2",
"name": "[UNIQUE_NAME]"
},
"update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations"
"update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations"
}
}

Expand All @@ -117,7 +117,7 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged
"description": "MY_APP_DESCRIPTION_3",
"name": "[UNIQUE_NAME]"
},
"update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations"
"update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations"
}
}
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("Hello world!")
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
bundle:
name: test-bundle

resources:
apps:
mykey:
name: myappname
description: my_app_description
compute_size: LARGE
source_code_path: ./app
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"method": "POST",
"path": "/api/2.0/apps",
"q": {
"no_compute": "true"
},
"body": {
"compute_size": "LARGE",
"description": "my_app_description",
"name": "myappname"
}
}
{
"method": "POST",
"path": "/api/2.0/apps/myappname/update",
"body": {
"app": {
"compute_size": "LARGE",
"description": "MY_APP_DESCRIPTION",
"name": "myappname"
},
"update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations"
}
}
{
"method": "POST",
"path": "/api/2.0/apps/myappname/update",
"body": {
"app": {
"description": "MY_APP_DESCRIPTION_2",
"name": "myappname"
},
"update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DMS = ["", "true"]
36 changes: 36 additions & 0 deletions acceptance/bundle/resources/apps/update-compute-size/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

=== Deploy with compute_size declared
>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
Created apps.mykey
Files: 2 uploaded, 0 deleted
Resources: 1 created, 0 changed, 0 deleted, 0 unchanged

>>> print_requests

=== Update description while compute_size is still declared
>>> update_file.py databricks.yml my_app_description MY_APP_DESCRIPTION

>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
Updated apps.mykey
Files: 2 uploaded, 0 deleted
Resources: 0 created, 1 changed, 0 deleted, 0 unchanged

>>> print_requests

=== Remove compute_size and update description
>>> update_file.py databricks.yml MY_APP_DESCRIPTION MY_APP_DESCRIPTION_2

>>> [CLI] bundle plan
update apps.mykey

Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged

>>> [CLI] bundle deploy
Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files...
Updated apps.mykey
Files: 2 uploaded, 0 deleted
Resources: 0 created, 1 changed, 0 deleted, 0 unchanged

>>> print_requests
21 changes: 21 additions & 0 deletions acceptance/bundle/resources/apps/update-compute-size/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
print_requests() {
# url is output-only field that terraform adds but that is ignored by the backend
print_requests.py //apps '^//api/2.0/bundle' --del-body url
}

title "Deploy with compute_size declared"
trace $CLI bundle deploy
trace print_requests > out.requests.json

title "Update description while compute_size is still declared"
trace update_file.py databricks.yml my_app_description MY_APP_DESCRIPTION
trace $CLI bundle deploy
trace print_requests >> out.requests.json

title "Remove compute_size and update description"
grep -v compute_size databricks.yml > databricks.yml.new
mv databricks.yml.new databricks.yml
trace update_file.py databricks.yml MY_APP_DESCRIPTION MY_APP_DESCRIPTION_2
trace $CLI bundle plan
trace $CLI bundle deploy
trace print_requests >> out.requests.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"description": "MY_APP_DESCRIPTION",
"name": "myappname"
},
"update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_size,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations"
"update_mask": "description,budget_policy_id,usage_policy_id,resources,user_api_scopes,compute_min_instances,compute_max_instances,git_repository,telemetry_export_destinations"
}
}
{
Expand Down
16 changes: 14 additions & 2 deletions bundle/direct/dresources/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,19 @@ var UpdateMaskFields = []string{
"telemetry_export_destinations",
}

var updateMask = strings.Join(UpdateMaskFields, ",")
// appUpdateMask returns the update mask for an app update request. compute_size is a
// backend default (see configs/apps.yml), so when the bundle does not declare it the field
// is left out of the mask. Naming it while the body omits it asks the backend to reset the
// size to its default on every deploy, even when the app was resized out of band.
func appUpdateMask(app *apps.App) string {
fields := UpdateMaskFields
if app.ComputeSize == "" {
fields = slices.DeleteFunc(slices.Clone(UpdateMaskFields), func(f string) bool {
return f == "compute_size"
})
}
return strings.Join(fields, ",")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we derive the update mask entirely?

cc @denik

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fully: deriving the mask from the request body would stop clearing fields removed from config (all UpdateMaskFields are omitempty, so "in mask, absent from body" is what clears them today), and deriving it from the plan is what #4963 did before #5051 reverted it because the plan can name fields the Update API rejects, so the viable middle ground is the plan-driven mask filtered by the static allowlist, which I'd rather do as a follow-up on top of this and #6399 since it touches the same list.


func (r *ResourceApp) DoUpdate(ctx context.Context, id string, config *AppState, entry *PlanEntry) (*AppRemote, error) {
// Deploy-only fields (source_code_path, config, git_source, lifecycle) are excluded
Expand All @@ -186,7 +198,7 @@ func (r *ResourceApp) DoUpdate(ctx context.Context, id string, config *AppState,
request := apps.AsyncUpdateAppRequest{
App: &app,
AppName: id,
UpdateMask: updateMask,
UpdateMask: appUpdateMask(&app),
}
updateWaiter, err := r.client.Apps.CreateUpdate(ctx, request)
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions bundle/direct/dresources/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,25 @@ func TestAppDoUpdate_UpdateMaskHasAllFields(t *testing.T) {
}
}

func TestAppUpdateMask_ComputeSizeFollowsBody(t *testing.T) {
tests := []struct {
name string
computeSize apps.ComputeSize
wantCompute bool
}{
{name: "declared", computeSize: apps.ComputeSizeLarge, wantCompute: true},
{name: "undeclared", computeSize: "", wantCompute: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mask := strings.Split(appUpdateMask(&apps.App{ComputeSize: tt.computeSize}), ",")
assert.Equal(t, tt.wantCompute, slices.Contains(mask, "compute_size"))
assert.Contains(t, mask, "description")
assert.Contains(t, mask, "compute_min_instances")
})
}
}

// TestAppRequestBody_StripsSourceCodePathFromForceSendFields verifies that
// appRequestBody removes SourceCodePath from ForceSendFields even when the plan
// JSON round-trip has forced it in — reproduces the v1.14.0 regression where
Expand Down
Loading