From f05f4275fc4e263d5d98c6c170c498cb0ab1c5e3 Mon Sep 17 00:00:00 2001 From: Dorin Geman Date: Thu, 17 Apr 2025 15:44:21 +0300 Subject: [PATCH] status: Also query /engines/status for additional info Signed-off-by: Dorin Geman --- commands/status.go | 11 +++++++++++ commands/status_test.go | 9 ++++++++- desktop/desktop.go | 19 +++++++++++++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/commands/status.go b/commands/status.go index ec2d0a78..335ab3da 100644 --- a/commands/status.go +++ b/commands/status.go @@ -1,6 +1,7 @@ package commands import ( + "encoding/json" "os" "github.com/docker/cli/cli-plugins/hooks" @@ -20,6 +21,16 @@ func newStatusCmd(desktopClient *desktop.Client) *cobra.Command { } if status.Running { cmd.Println("Docker Model Runner is running") + cmd.Println("\nStatus:") + var backendStatus map[string]string + if err := json.Unmarshal(status.Status, &backendStatus); err != nil { + cmd.PrintErrln(string(status.Status)) + } + for b, s := range backendStatus { + if s != "not running" { + cmd.Println(b+":", s) + } + } } else { cmd.Println("Docker Model Runner is not running") hooks.PrintNextSteps(cmd.OutOrStdout(), []string{enableViaCLI, enableViaGUI}) diff --git a/commands/status_test.go b/commands/status_test.go index c75768ae..f92f3fd6 100644 --- a/commands/status_test.go +++ b/commands/status_test.go @@ -78,10 +78,17 @@ func TestStatus(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { client := mockdesktop.NewMockDockerHttpClient(ctrl) + req, err := http.NewRequest(http.MethodGet, desktop.URL(inference.ModelsPrefix), nil) require.NoError(t, err) client.EXPECT().Do(req).Return(test.doResponse, test.doErr) + if test.doResponse != nil && test.doResponse.StatusCode == http.StatusOK { + req, err = http.NewRequest(http.MethodGet, desktop.URL(inference.InferencePrefix+"/status"), nil) + require.NoError(t, err) + client.EXPECT().Do(req).Return(&http.Response{Body: mockBody}, test.doErr) + } + originalOsExit := osExit exitCalled := false osExit = func(code int) { @@ -106,7 +113,7 @@ func TestStatus(t *testing.T) { require.EqualError(t, err, test.expectedErr.Error()) } else { require.NoError(t, err) - require.Equal(t, test.expectedOutput, buf.String()) + require.True(t, strings.HasPrefix(buf.String(), test.expectedOutput)) } }) } diff --git a/desktop/desktop.go b/desktop/desktop.go index b7fbc62f..966f2870 100644 --- a/desktop/desktop.go +++ b/desktop/desktop.go @@ -49,8 +49,9 @@ func New(dockerClient DockerHttpClient) *Client { } type Status struct { - Running bool `json:"running"` - Error error `json:"error"` + Running bool `json:"running"` + Status []byte `json:"status"` + Error error `json:"error"` } func (c *Client) Status() Status { @@ -70,8 +71,22 @@ func (c *Client) Status() Status { } defer resp.Body.Close() if resp.StatusCode == http.StatusOK { + var status []byte + statusResp, err := c.doRequest(http.MethodGet, inference.InferencePrefix+"/status", nil) + if err != nil { + status = []byte(fmt.Sprintf("error querying status: %v", err)) + } else { + defer statusResp.Body.Close() + statusBody, err := io.ReadAll(statusResp.Body) + if err != nil { + status = []byte(fmt.Sprintf("error reading status body: %v", err)) + } else { + status = statusBody + } + } return Status{ Running: true, + Status: status, } } return Status{