Skip to content

Commit 61d938f

Browse files
committed
[ws-manager] check ide-ready response
1 parent cad5aaa commit 61d938f

File tree

1 file changed

+25
-6
lines changed
  • components/ws-manager/pkg/manager

1 file changed

+25
-6
lines changed

components/ws-manager/pkg/manager/probe.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ package manager
77
import (
88
"context"
99
"crypto/tls"
10+
"io/ioutil"
1011
"net/http"
1112
"net/url"
1213
"time"
1314

1415
"github.com/gitpod-io/gitpod/common-go/log"
1516
"github.com/gitpod-io/gitpod/common-go/tracing"
17+
"k8s.io/apimachinery/pkg/util/json"
1618
)
1719

1820
// WorkspaceProbeResult marks the result of a workspace probe
@@ -38,7 +40,7 @@ type WorkspaceReadyProbe struct {
3840

3941
// NewWorkspaceReadyProbe creates a new workspace probe
4042
func NewWorkspaceReadyProbe(workspaceID string, workspaceURL url.URL) WorkspaceReadyProbe {
41-
workspaceURL.Path += "/_supervisor/v1/status/ide"
43+
workspaceURL.Path += "/_supervisor/v1/status/ide/wait"
4244
readyURL := workspaceURL.String()
4345

4446
return WorkspaceReadyProbe{
@@ -92,14 +94,31 @@ func (p *WorkspaceReadyProbe) Run(ctx context.Context) WorkspaceProbeResult {
9294
// we've timed out - do not log this as it would spam the logs for no good reason
9395
continue
9496
}
95-
resp.Body.Close()
9697

97-
if resp.StatusCode == http.StatusOK {
98-
break
98+
if resp.StatusCode != http.StatusOK {
99+
resp.Body.Close()
100+
log.WithField("url", p.readyURL).WithField("status", resp.StatusCode).Debug("workspace did not respond to ready probe with OK status")
101+
time.Sleep(p.RetryDelay)
102+
continue
99103
}
100104

101-
log.WithField("url", p.readyURL).WithField("status", resp.StatusCode).Debug("workspace did not respond to ready probe with OK status")
102-
time.Sleep(p.RetryDelay)
105+
rawBody, err := ioutil.ReadAll(resp.Body)
106+
resp.Body.Close()
107+
if err != nil {
108+
log.WithField("url", p.readyURL).WithField("status", resp.StatusCode).WithError(err).Debug("ready probe failed: cannot read body")
109+
continue
110+
}
111+
var probeResult struct {
112+
Ok bool `json:"ok"`
113+
}
114+
err = json.Unmarshal(rawBody, &probeResult)
115+
if err != nil {
116+
log.WithField("url", p.readyURL).WithField("status", resp.StatusCode).WithError(err).Debug("ready probe failed: unable to unmarshal json")
117+
continue
118+
}
119+
if probeResult.Ok {
120+
break
121+
}
103122
}
104123

105124
// workspace is actually ready

0 commit comments

Comments
 (0)