Do not wait for app compute to start on `bundle deploy` (#2144)

## Changes
This allows DABs to avoid waiting for the compute to start when app is
initially created as part of "bundle deploy" which significantly
improves deploy time.

Always set no_compute to true for apps

## Tests
Covered by `TestDeployBundleWithApp`, currently fails until TF provider
is upgraded to the version supporting `no_compute` option
This commit is contained in:
Andrew Nester 2025-01-28 18:17:37 +01:00 committed by GitHub
parent 099e9bed0f
commit 413ca5c134
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 13 additions and 37 deletions

View File

@ -1,29 +0,0 @@
package apps
import (
"context"
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/diag"
)
type slowDeployMessage struct{}
// TODO: needs to be removed when when no_compute option becomes available in TF provider and used in DABs
// See https://github.com/databricks/cli/pull/2144
func (v *slowDeployMessage) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics {
if len(b.Config.Resources.Apps) > 0 {
cmdio.LogString(ctx, "Note: Databricks apps included in this bundle may increase initial deployment time due to compute provisioning.")
}
return nil
}
func (v *slowDeployMessage) Name() string {
return "apps.SlowDeployMessage"
}
func SlowDeployMessage() bundle.Mutator {
return &slowDeployMessage{}
}

View File

@ -38,6 +38,12 @@ func (appConverter) Convert(ctx context.Context, key string, vin dyn.Value, out
return err return err
} }
// We always set no_compute to true as it allows DABs not to wait for app compute to be started when app is created.
vout, err = dyn.Set(vout, "no_compute", dyn.V(true))
if err != nil {
return err
}
// Add the converted resource to the output. // Add the converted resource to the output.
out.App[key] = vout.AsAny() out.App[key] = vout.AsAny()

View File

@ -63,6 +63,7 @@ func TestConvertApp(t *testing.T) {
assert.Equal(t, map[string]any{ assert.Equal(t, map[string]any{
"description": "app description", "description": "app description",
"name": "app_id", "name": "app_id",
"no_compute": true,
"resources": []any{ "resources": []any{
map[string]any{ map[string]any{
"name": "job1", "name": "job1",
@ -136,6 +137,7 @@ func TestConvertAppWithNoDescription(t *testing.T) {
assert.Equal(t, map[string]any{ assert.Equal(t, map[string]any{
"name": "app_id", "name": "app_id",
"description": "", // Due to Apps API always returning a description field, we set it in the output as well to avoid permanent TF drift "description": "", // Due to Apps API always returning a description field, we set it in the output as well to avoid permanent TF drift
"no_compute": true,
"resources": []any{ "resources": []any{
map[string]any{ map[string]any{
"name": "job1", "name": "job1",

View File

@ -130,7 +130,6 @@ func Deploy(outputHandler sync.OutputHandler) bundle.Mutator {
// mutators need informed consent if they are potentially destructive. // mutators need informed consent if they are potentially destructive.
deployCore := bundle.Defer( deployCore := bundle.Defer(
bundle.Seq( bundle.Seq(
apps.SlowDeployMessage(),
bundle.LogString("Deploying resources..."), bundle.LogString("Deploying resources..."),
terraform.Apply(), terraform.Apply(),
), ),

View File

@ -18,12 +18,6 @@ import (
func TestDeployBundleWithApp(t *testing.T) { func TestDeployBundleWithApp(t *testing.T) {
ctx, wt := acc.WorkspaceTest(t) ctx, wt := acc.WorkspaceTest(t)
// TODO: should only skip app run when app can be created with no_compute option.
if testing.Short() {
t.Log("Skip the app creation and run in short mode")
return
}
if testutil.GetCloud(t) == testutil.GCP { if testutil.GetCloud(t) == testutil.GCP {
t.Skip("Skipping test for GCP cloud because /api/2.0/apps is temporarily unavailable there.") t.Skip("Skipping test for GCP cloud because /api/2.0/apps is temporarily unavailable there.")
} }
@ -106,6 +100,11 @@ env:
- name: JOB_ID - name: JOB_ID
value: "%d"`, job.JobId)) value: "%d"`, job.JobId))
if testing.Short() {
t.Log("Skip the app run in short mode")
return
}
// Try to run the app // Try to run the app
_, out := runResourceWithStderr(t, ctx, root, "test_app") _, out := runResourceWithStderr(t, ctx, root, "test_app")
require.Contains(t, out, app.Url) require.Contains(t, out, app.Url)

View File

@ -1,5 +1,4 @@
Uploading bundle files to /Workspace/Users/$USERNAME/.bundle/$UNIQUE_PRJ/files... Uploading bundle files to /Workspace/Users/$USERNAME/.bundle/$UNIQUE_PRJ/files...
Note: Databricks apps included in this bundle may increase initial deployment time due to compute provisioning.
Deploying resources... Deploying resources...
Updating deployment state... Updating deployment state...
Deployment complete! Deployment complete!