From 3954f37920e4acb4fdec0c0d118c0e0a6a645491 Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Wed, 23 Aug 2023 14:35:44 +0200 Subject: Include whether wait was aborted in error --- client/go/internal/cli/cmd/status_test.go | 10 +++++----- client/go/internal/vespa/target.go | 15 +++++++++------ client/go/internal/vespa/target_cloud.go | 8 ++++---- client/go/internal/vespa/target_custom.go | 4 ++-- 4 files changed, 20 insertions(+), 17 deletions(-) (limited to 'client') diff --git a/client/go/internal/cli/cmd/status_test.go b/client/go/internal/cli/cmd/status_test.go index 36f51ff5073..4ed13a7ef22 100644 --- a/client/go/internal/cli/cmd/status_test.go +++ b/client/go/internal/cli/cmd/status_test.go @@ -96,13 +96,13 @@ func TestStatusLocalDeployment(t *testing.T) { resp.Body = []byte(`{"currentGeneration": 42, "converged": false}`) client.NextResponse(resp) assert.NotNil(t, cli.Run("status", "deployment")) - assert.Equal(t, "Error: deployment not converged on latest generation after waiting 0s: wait timed out\n", stderr.String()) + assert.Equal(t, "Error: deployment not converged on latest generation: wait timed out\n", stderr.String()) // Explicit generation stderr.Reset() client.NextResponse(resp) assert.NotNil(t, cli.Run("status", "deployment", "41")) - assert.Equal(t, "Error: deployment not converged on generation 41 after waiting 0s: wait timed out\n", stderr.String()) + assert.Equal(t, "Error: deployment not converged on generation 41: wait timed out\n", stderr.String()) } func TestStatusCloudDeployment(t *testing.T) { @@ -131,14 +131,14 @@ func TestStatusCloudDeployment(t *testing.T) { assert.Equal(t, "Deployment run 1337 has completed\nSee https://console.vespa-cloud.com/tenant/t1/application/a1/dev/instance/i1/job/dev-us-north-1/run/1337 for more details\n", stdout.String()) - // Explicit run + // Explicit run with waiting client.NextResponse(mock.HTTPResponse{ URI: "/application/v4/tenant/t1/application/a1/instance/i1/job/dev-us-north-1/run/42?after=-1", Status: 200, Body: []byte(`{"active": false, "status": "failure"}`), }) - assert.NotNil(t, cli.Run("status", "deployment", "42")) - assert.Equal(t, "Error: deployment run 42 incomplete after waiting 0s: run 42 ended with unsuccessful status: failure\n", stderr.String()) + assert.NotNil(t, cli.Run("status", "deployment", "42", "-w", "10")) + assert.Equal(t, "Waiting up to 10s for deployment to converge...\nError: deployment run 42 incomplete after waiting up to 10s: aborting wait: run 42 ended with unsuccessful status: failure\n", stderr.String()) } func isLocalTarget(args []string) bool { diff --git a/client/go/internal/vespa/target.go b/client/go/internal/vespa/target.go index 3c65369f986..f96723dc433 100644 --- a/client/go/internal/vespa/target.go +++ b/client/go/internal/vespa/target.go @@ -137,15 +137,11 @@ func (s *Service) Wait(timeout time.Duration) error { okFunc := func(status int, response []byte) (bool, error) { return isOK(status) } status, err := wait(s, okFunc, func() *http.Request { return req }, timeout, s.retryInterval) if err != nil { - waitDesc := "" - if timeout > 0 { - waitDesc = " (after waiting " + timeout.String() + ") " - } statusDesc := "" if status > 0 { statusDesc = fmt.Sprintf(": status %d", status) } - return fmt.Errorf("unhealthy %s%s%s at %s: %w", s.Description(), waitDesc, statusDesc, url, err) + return fmt.Errorf("unhealthy %s%s%s at %s: %w", s.Description(), waitDescription(timeout), statusDesc, url, err) } return nil } @@ -182,6 +178,13 @@ func FindService(name string, services []*Service) (*Service, error) { return nil, fmt.Errorf("no service specified: %s", found) } +func waitDescription(d time.Duration) string { + if d > 0 { + return " after waiting up to " + d.String() + } + return "" +} + func isOK(status int) (bool, error) { class := status / 100 switch class { @@ -226,7 +229,7 @@ func wait(service *Service, okFn responseFunc, reqFn requestFunc, timeout, retry response.Body.Close() ok, err := okFn(status, body) if err != nil { - return status, err + return status, fmt.Errorf("aborting wait: %w", err) } if ok { return status, nil diff --git a/client/go/internal/vespa/target_cloud.go b/client/go/internal/vespa/target_cloud.go index bc4934ea6fd..2063e15e3a2 100644 --- a/client/go/internal/vespa/target_cloud.go +++ b/client/go/internal/vespa/target_cloud.go @@ -314,10 +314,10 @@ func (t *cloudTarget) AwaitDeployment(runID int64, timeout time.Duration) (int64 } _, err = t.deployServiceWait(jobSuccessFunc, requestFunc, timeout) if err != nil { - return 0, fmt.Errorf("deployment run %d incomplete after waiting %s: %w", runID, timeout, err) + return 0, fmt.Errorf("deployment run %d incomplete%s: %w", runID, waitDescription(timeout), err) } if !success { - return 0, fmt.Errorf("deployment run %d incomplete after waiting %s", runID, timeout) + return 0, fmt.Errorf("deployment run %d incomplete%s", runID, waitDescription(timeout)) } return runID, nil } @@ -374,10 +374,10 @@ func (t *cloudTarget) discoverEndpoints(timeout time.Duration) (map[string]strin return true, nil } if _, err := t.deployServiceWait(endpointFunc, func() *http.Request { return req }, timeout); err != nil { - return nil, fmt.Errorf("no endpoints found after waiting %s: %w", timeout, err) + return nil, fmt.Errorf("no endpoints found%s: %w", waitDescription(timeout), err) } if len(urlsByCluster) == 0 { - return nil, fmt.Errorf("no endpoints found after waiting %s", timeout) + return nil, fmt.Errorf("no endpoints found%s", waitDescription(timeout)) } return urlsByCluster, nil } diff --git a/client/go/internal/vespa/target_custom.go b/client/go/internal/vespa/target_custom.go index b0ca4f8492c..b120dd73d9d 100644 --- a/client/go/internal/vespa/target_custom.go +++ b/client/go/internal/vespa/target_custom.go @@ -167,10 +167,10 @@ func (t *customTarget) serviceStatus(wantedGeneration int64, timeout time.Durati return converged, nil } if _, err := wait(deployService, convergedFunc, func() *http.Request { return req }, timeout, t.retryInterval); err != nil { - return serviceStatus{}, fmt.Errorf("deployment not converged%s after waiting %s: %w", generationDescription(wantedGeneration), timeout, err) + return serviceStatus{}, fmt.Errorf("deployment not converged%s%s: %w", generationDescription(wantedGeneration), waitDescription(timeout), err) } if !converged { - return serviceStatus{}, fmt.Errorf("deployment not converged%s after waiting %s", generationDescription(wantedGeneration), timeout) + return serviceStatus{}, fmt.Errorf("deployment not converged%s%s", generationDescription(wantedGeneration), waitDescription(timeout)) } return status, nil } -- cgit v1.2.3