From 94efcab300e448e9896ad3ee0090dd991cb96fb0 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Mon, 16 Nov 2026 06:56:16 +0000 Subject: [PATCH 1/2] serving-endpoints: show served entity deployment state while waiting `serving-endpoints create` and `update-config` only showed `current status: IN_PROGRESS` in a spinner for the whole deployment, and printed nothing when stderr is not a terminal. Show each served entity's deployment_state_message with the time waited, and print one stderr line per change when there is no TTY. Stdout is unchanged. Co-authored-by: Isaac Signed-off-by: Anshul Gupta --- .../cli/serving-endpoints-wait-progress.md | 1 + .../workspace/serving-endpoints/input.json | 13 ++ .../workspace/serving-endpoints/out.test.toml | 1 + .../workspace/serving-endpoints/output.txt | 34 +++ .../cmd/workspace/serving-endpoints/script | 13 ++ .../cmd/workspace/serving-endpoints/test.toml | 6 + .../workspace/serving-endpoints/update.json | 10 + cmd/workspace/serving-endpoints/overrides.go | 219 ++++++++++++++++++ .../serving-endpoints/overrides_test.go | 103 ++++++++ 9 files changed, 400 insertions(+) create mode 100644 .nextchanges/cli/serving-endpoints-wait-progress.md create mode 100644 acceptance/cmd/workspace/serving-endpoints/input.json create mode 100644 acceptance/cmd/workspace/serving-endpoints/out.test.toml create mode 100644 acceptance/cmd/workspace/serving-endpoints/output.txt create mode 100644 acceptance/cmd/workspace/serving-endpoints/script create mode 100644 acceptance/cmd/workspace/serving-endpoints/test.toml create mode 100644 acceptance/cmd/workspace/serving-endpoints/update.json create mode 100644 cmd/workspace/serving-endpoints/overrides.go create mode 100644 cmd/workspace/serving-endpoints/overrides_test.go diff --git a/.nextchanges/cli/serving-endpoints-wait-progress.md b/.nextchanges/cli/serving-endpoints-wait-progress.md new file mode 100644 index 00000000000..e30423f3f31 --- /dev/null +++ b/.nextchanges/cli/serving-endpoints-wait-progress.md @@ -0,0 +1 @@ +* `serving-endpoints create` and `update-config` now show each served entity's deployment state (for example `Provisioning`) and the time waited while they wait for the endpoint, instead of only `IN_PROGRESS`. When stderr is not a terminal, each state change is printed as a line on stderr instead of printing nothing. diff --git a/acceptance/cmd/workspace/serving-endpoints/input.json b/acceptance/cmd/workspace/serving-endpoints/input.json new file mode 100644 index 00000000000..91c6c713676 --- /dev/null +++ b/acceptance/cmd/workspace/serving-endpoints/input.json @@ -0,0 +1,13 @@ +{ + "name": "iris-clf", + "config": { + "served_entities": [ + { + "entity_name": "main.default.iris", + "entity_version": "1", + "workload_size": "Small", + "scale_to_zero_enabled": true + } + ] + } +} diff --git a/acceptance/cmd/workspace/serving-endpoints/out.test.toml b/acceptance/cmd/workspace/serving-endpoints/out.test.toml new file mode 100644 index 00000000000..18b1a88417e --- /dev/null +++ b/acceptance/cmd/workspace/serving-endpoints/out.test.toml @@ -0,0 +1 @@ +Cloud = false diff --git a/acceptance/cmd/workspace/serving-endpoints/output.txt b/acceptance/cmd/workspace/serving-endpoints/output.txt new file mode 100644 index 00000000000..7bb4c4f3c0e --- /dev/null +++ b/acceptance/cmd/workspace/serving-endpoints/output.txt @@ -0,0 +1,34 @@ + +=== Create waits and reports progress on stderr; stdout is the endpoint JSON + +>>> [CLI] serving-endpoints create --json @input.json +{ + "name": "iris-clf", + "state": { + "config_update": "NOT_UPDATING", + "ready": "NOT_READY" + } +} + +=== Create with --no-wait prints the create response and no progress + +>>> [CLI] serving-endpoints create --no-wait --json {"name": "iris-clf-2"} +{ + "name": "iris-clf-2" +} + +=== Update config waits and reports progress + +>>> [CLI] serving-endpoints update-config iris-clf --json @update.json +current status: IN_PROGRESS ([ELAPSED]) +{ + "name": "iris-clf", + "state": { + "config_update": "NOT_UPDATING", + "ready": "NOT_READY" + } +} + +=== Help mentions the wait and --no-wait + +>>> [CLI] serving-endpoints create --help diff --git a/acceptance/cmd/workspace/serving-endpoints/script b/acceptance/cmd/workspace/serving-endpoints/script new file mode 100644 index 00000000000..521248a9263 --- /dev/null +++ b/acceptance/cmd/workspace/serving-endpoints/script @@ -0,0 +1,13 @@ +title "Create waits and reports progress on stderr; stdout is the endpoint JSON" +trace $CLI serving-endpoints create --json @input.json > out.create.json +jq '{name, state}' out.create.json +rm out.create.json + +title "Create with --no-wait prints the create response and no progress" +trace $CLI serving-endpoints create --no-wait --json '{"name": "iris-clf-2"}' | jq '{name}' + +title "Update config waits and reports progress" +trace $CLI serving-endpoints update-config iris-clf --json @update.json | jq '{name, state}' + +title "Help mentions the wait and --no-wait" +trace $CLI serving-endpoints create --help | contains.py "Use --no-wait to return immediately" > /dev/null diff --git a/acceptance/cmd/workspace/serving-endpoints/test.toml b/acceptance/cmd/workspace/serving-endpoints/test.toml new file mode 100644 index 00000000000..640616a41c1 --- /dev/null +++ b/acceptance/cmd/workspace/serving-endpoints/test.toml @@ -0,0 +1,6 @@ +Cloud = false + +# Progress lines include the time waited so far. +[[Repls]] +Old = '\((\d+m)?\d+s\)' +New = '([ELAPSED])' diff --git a/acceptance/cmd/workspace/serving-endpoints/update.json b/acceptance/cmd/workspace/serving-endpoints/update.json new file mode 100644 index 00000000000..d6d34ed3f2c --- /dev/null +++ b/acceptance/cmd/workspace/serving-endpoints/update.json @@ -0,0 +1,10 @@ +{ + "served_entities": [ + { + "entity_name": "main.default.iris", + "entity_version": "2", + "workload_size": "Small", + "scale_to_zero_enabled": true + } + ] +} diff --git a/cmd/workspace/serving-endpoints/overrides.go b/cmd/workspace/serving-endpoints/overrides.go new file mode 100644 index 00000000000..47551f14507 --- /dev/null +++ b/cmd/workspace/serving-endpoints/overrides.go @@ -0,0 +1,219 @@ +package serving_endpoints + +import ( + "context" + "errors" + "fmt" + "strings" + "time" + + "github.com/databricks/cli/libs/cmdctx" + "github.com/databricks/cli/libs/cmdio" + "github.com/databricks/cli/libs/flags" + "github.com/databricks/databricks-sdk-go/service/serving" + "github.com/spf13/cobra" +) + +// waitProgress reports progress while create or update-config waits for the +// endpoint to finish updating. +// +// The generated wait only shows state.config_update, which stays IN_PROGRESS +// for the whole deployment. Each served entity carries a more useful +// deployment_state_message (for example "Container image creation in progress" +// or "Provisioning"), so we show that instead, with the time waited so far. +// +// A spinner prints nothing when stderr is not a terminal, which left agents and +// CI with no output for the full deployment. In that case we print one line to +// stderr each time the message changes. Stdout is unchanged either way. +type waitProgress struct { + start time.Time + spinner interface { + Update(string) + Close() + } + last string +} + +func newWaitProgress(ctx context.Context) *waitProgress { + p := &waitProgress{start: time.Now()} + if cmdio.GetInteractiveMode(ctx) != cmdio.InteractiveModeNone { + p.spinner = cmdio.NewSpinner(ctx) + } + return p +} + +func (p *waitProgress) report(ctx context.Context, i *serving.ServingEndpointDetailed) { + msg := endpointProgressMessage(i) + line := fmt.Sprintf("%s (%s)", msg, time.Since(p.start).Truncate(time.Second)) + if p.spinner != nil { + p.spinner.Update(line) + return + } + // Without a spinner, print a line only when the message changes, not on every + // poll. Skip the final poll: the update is done and the result follows on + // stdout, so commands that finish immediately print exactly what they used to. + if i.State != nil && i.State.ConfigUpdate == serving.EndpointStateConfigUpdateNotUpdating { + return + } + if msg != p.last { + p.last = msg + cmdio.LogProgress(ctx, line) + } +} + +func (p *waitProgress) close() { + if p.spinner != nil { + p.spinner.Close() + } +} + +// endpointProgressMessage describes where the endpoint is in its update. It +// prefers the per-entity state of the pending config, falls back to the active +// config, and falls back to the generated "current status" text when no entity +// reports a state. +func endpointProgressMessage(i *serving.ServingEndpointDetailed) string { + var parts []string + if i != nil { + var entities []serving.ServedEntityOutput + if i.PendingConfig != nil { + entities = i.PendingConfig.ServedEntities + } else if i.Config != nil { + entities = i.Config.ServedEntities + } + for _, e := range entities { + if e.State == nil { + continue + } + state := e.State.DeploymentStateMessage + if state == "" { + state = string(e.State.Deployment) + } + if state == "" { + continue + } + if e.Name != "" { + state = e.Name + ": " + state + } + parts = append(parts, state) + } + } + if len(parts) > 0 { + return strings.Join(parts, "; ") + } + var status serving.EndpointStateConfigUpdate + if i != nil && i.State != nil { + status = i.State.ConfigUpdate + } + return fmt.Sprintf("current status: %s", status) +} + +// unmarshalJSONFlag applies --json to req the same way the generated command +// does, including rendering non-fatal diagnostics such as unknown fields. +func unmarshalJSONFlag(cmd *cobra.Command, req any) error { + if !cmd.Flags().Changed("json") { + return nil + } + jsonFlag, ok := cmd.Flags().Lookup("json").Value.(*flags.JsonFlag) + if !ok { + return errors.New("unexpected type for --json flag") + } + diags := jsonFlag.Unmarshal(req) + if diags.HasError() { + return diags.Error() + } + if len(diags) > 0 { + return cmdio.RenderDiagnostics(cmd.Context(), diags) + } + return nil +} + +func waitFlags(cmd *cobra.Command) (skipWait bool, timeout time.Duration, err error) { + skipWait, err = cmd.Flags().GetBool("no-wait") + if err != nil { + return false, 0, err + } + timeout, err = cmd.Flags().GetDuration("timeout") + return skipWait, timeout, err +} + +const waitHelp = ` + + By default this command waits until the endpoint finishes updating (up to + --timeout, 20m by default), printing each served entity's deployment state + to stderr. Use --no-wait to return immediately, then check progress with + "databricks serving-endpoints get NAME".` + +func createOverride(createCmd *cobra.Command, createReq *serving.CreateServingEndpoint) { + createCmd.Long += waitHelp + createCmd.RunE = func(cmd *cobra.Command, args []string) error { + ctx := cmd.Context() + w := cmdctx.WorkspaceClient(ctx) + + if err := unmarshalJSONFlag(cmd, createReq); err != nil { + return err + } + if !cmd.Flags().Changed("json") { + createReq.Name = args[0] + } + skipWait, timeout, err := waitFlags(cmd) + if err != nil { + return err + } + + wait, err := w.ServingEndpoints.Create(ctx, *createReq) + if err != nil { + return err + } + if skipWait { + return cmdio.Render(ctx, wait.Response) + } + p := newWaitProgress(ctx) + info, err := wait.OnProgress(func(i *serving.ServingEndpointDetailed) { + p.report(ctx, i) + }).GetWithTimeout(timeout) + p.close() + if err != nil { + return err + } + return cmdio.Render(ctx, info) + } +} + +func updateConfigOverride(updateConfigCmd *cobra.Command, updateConfigReq *serving.EndpointCoreConfigInput) { + updateConfigCmd.Long += waitHelp + updateConfigCmd.RunE = func(cmd *cobra.Command, args []string) error { + ctx := cmd.Context() + w := cmdctx.WorkspaceClient(ctx) + + if err := unmarshalJSONFlag(cmd, updateConfigReq); err != nil { + return err + } + updateConfigReq.Name = args[0] + skipWait, timeout, err := waitFlags(cmd) + if err != nil { + return err + } + + wait, err := w.ServingEndpoints.UpdateConfig(ctx, *updateConfigReq) + if err != nil { + return err + } + if skipWait { + return cmdio.Render(ctx, wait.Response) + } + p := newWaitProgress(ctx) + info, err := wait.OnProgress(func(i *serving.ServingEndpointDetailed) { + p.report(ctx, i) + }).GetWithTimeout(timeout) + p.close() + if err != nil { + return err + } + return cmdio.Render(ctx, info) + } +} + +func init() { + createOverrides = append(createOverrides, createOverride) + updateConfigOverrides = append(updateConfigOverrides, updateConfigOverride) +} diff --git a/cmd/workspace/serving-endpoints/overrides_test.go b/cmd/workspace/serving-endpoints/overrides_test.go new file mode 100644 index 00000000000..b539418628a --- /dev/null +++ b/cmd/workspace/serving-endpoints/overrides_test.go @@ -0,0 +1,103 @@ +package serving_endpoints + +import ( + "bytes" + "testing" + + "github.com/databricks/cli/libs/cmdio" + "github.com/databricks/cli/libs/flags" + "github.com/databricks/databricks-sdk-go/service/serving" + "github.com/stretchr/testify/assert" +) + +func entity(name string, deployment serving.ServedModelStateDeployment, msg string) serving.ServedEntityOutput { + return serving.ServedEntityOutput{ + Name: name, + State: &serving.ServedModelState{Deployment: deployment, DeploymentStateMessage: msg}, + } +} + +func TestEndpointProgressMessage(t *testing.T) { + inProgress := &serving.EndpointState{ConfigUpdate: serving.EndpointStateConfigUpdateInProgress} + + tests := []struct { + name string + endpoint *serving.ServingEndpointDetailed + want string + }{ + { + name: "pending config entity message", + endpoint: &serving.ServingEndpointDetailed{ + State: inProgress, + PendingConfig: &serving.EndpointPendingConfig{ServedEntities: []serving.ServedEntityOutput{ + entity("iris-1", serving.ServedModelStateDeploymentDeploymentCreating, "Container image creation in progress"), + }}, + }, + want: "iris-1: Container image creation in progress", + }, + { + name: "multiple entities, deployment state when message is empty", + endpoint: &serving.ServingEndpointDetailed{ + State: inProgress, + PendingConfig: &serving.EndpointPendingConfig{ServedEntities: []serving.ServedEntityOutput{ + entity("a-1", serving.ServedModelStateDeploymentDeploymentCreating, "Provisioning"), + entity("b-2", serving.ServedModelStateDeploymentDeploymentReady, ""), + }}, + }, + want: "a-1: Provisioning; b-2: DEPLOYMENT_READY", + }, + { + name: "falls back to active config when nothing is pending", + endpoint: &serving.ServingEndpointDetailed{ + State: &serving.EndpointState{ConfigUpdate: serving.EndpointStateConfigUpdateNotUpdating}, + Config: &serving.EndpointCoreConfigOutput{ServedEntities: []serving.ServedEntityOutput{ + entity("iris-1", serving.ServedModelStateDeploymentDeploymentReady, "Served entity creation succeeded"), + }}, + }, + want: "iris-1: Served entity creation succeeded", + }, + { + name: "no entity state keeps the old message", + endpoint: &serving.ServingEndpointDetailed{ + State: inProgress, + PendingConfig: &serving.EndpointPendingConfig{ServedEntities: []serving.ServedEntityOutput{{Name: "iris-1"}}}, + }, + want: "current status: IN_PROGRESS", + }, + { + name: "no state at all", + endpoint: &serving.ServingEndpointDetailed{}, + want: "current status: ", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, tt.want, endpointProgressMessage(tt.endpoint)) + }) + } +} + +func TestWaitProgressPrintsChangesWithoutTTY(t *testing.T) { + // Buffers are not TTYs, so this is the agent/CI case where no spinner renders. + var stdout, stderr bytes.Buffer + ctx := cmdio.InContext(t.Context(), cmdio.NewIO(t.Context(), flags.OutputText, nil, &stdout, &stderr, "", "")) + + p := newWaitProgress(ctx) + for _, msg := range []string{"Container image creation pending", "Container image creation pending", "Provisioning"} { + p.report(ctx, &serving.ServingEndpointDetailed{ + PendingConfig: &serving.EndpointPendingConfig{ServedEntities: []serving.ServedEntityOutput{ + entity("iris-1", serving.ServedModelStateDeploymentDeploymentCreating, msg), + }}, + }) + } + p.report(ctx, &serving.ServingEndpointDetailed{ + State: &serving.EndpointState{ConfigUpdate: serving.EndpointStateConfigUpdateNotUpdating}, + Config: &serving.EndpointCoreConfigOutput{ServedEntities: []serving.ServedEntityOutput{ + entity("iris-1", serving.ServedModelStateDeploymentDeploymentReady, "Served entity creation succeeded"), + }}, + }) + p.close() + + assert.Equal(t, "iris-1: Container image creation pending (0s)\niris-1: Provisioning (0s)\n", stderr.String()) + assert.Empty(t, stdout.String()) +} From e4f05bf8bd04ffd017b435719ca56840d36c1f43 Mon Sep 17 00:00:00 2001 From: Anshul Gupta Date: Mon, 16 Nov 2026 06:57:01 +0000 Subject: [PATCH 2/2] Point changelog fragment at #7659 Co-authored-by: Isaac Signed-off-by: Anshul Gupta --- .nextchanges/cli/serving-endpoints-wait-progress.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/cli/serving-endpoints-wait-progress.md b/.nextchanges/cli/serving-endpoints-wait-progress.md index e30423f3f31..bb92e8d356a 100644 --- a/.nextchanges/cli/serving-endpoints-wait-progress.md +++ b/.nextchanges/cli/serving-endpoints-wait-progress.md @@ -1 +1 @@ -* `serving-endpoints create` and `update-config` now show each served entity's deployment state (for example `Provisioning`) and the time waited while they wait for the endpoint, instead of only `IN_PROGRESS`. When stderr is not a terminal, each state change is printed as a line on stderr instead of printing nothing. +* `serving-endpoints create` and `update-config` now show each served entity's deployment state (for example `Provisioning`) and the time waited while they wait for the endpoint, instead of only `IN_PROGRESS`. When stderr is not a terminal, each state change is printed as a line on stderr instead of printing nothing. ([#7659](https://github.com/databricks/cli/pull/7659))