Skip to content

Commit 222c3f3

Browse files
Cloud: Fix stack wake-up function
Closes #1725 In #1545, the stack readiness check was improved by calling the `/api/health` endpoint instead of just the stack URL While this does provide a better indication that the instance is up and running, the `/api/health` subpath does not trigger Grafana Cloud's stack wake-up With this PR, we'll call both the stack's base URL and its health endpoint
1 parent edd6cc8 commit 222c3f3

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

internal/resources/cloud/resource_cloud_stack.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,25 +445,37 @@ func waitForStackReadiness(ctx context.Context, timeout time.Duration, stackURL
445445
return diag.FromErr(joinErr)
446446
}
447447
err := retry.RetryContext(ctx, timeout, func() *retry.RetryError {
448-
req, err := http.NewRequestWithContext(ctx, http.MethodGet, healthURL, nil)
448+
// Query the instance URL directly. This makes the stack wake-up if it has been paused.
449+
// The health endpoint is helpful to check that the stack is ready, but it doesn't wake up the stack.
450+
stackReq, err := http.NewRequestWithContext(ctx, http.MethodGet, stackURL, nil)
449451
if err != nil {
450452
return retry.NonRetryableError(err)
451453
}
452-
resp, err := http.DefaultClient.Do(req)
454+
stackResp, err := http.DefaultClient.Do(stackReq)
453455
if err != nil {
454456
return retry.RetryableError(err)
455457
}
456-
defer resp.Body.Close()
457-
if resp.StatusCode != 200 {
458+
defer stackResp.Body.Close()
459+
460+
healthReq, err := http.NewRequestWithContext(ctx, http.MethodGet, healthURL, nil)
461+
if err != nil {
462+
return retry.NonRetryableError(err)
463+
}
464+
healthResp, err := http.DefaultClient.Do(healthReq)
465+
if err != nil {
466+
return retry.RetryableError(err)
467+
}
468+
defer healthResp.Body.Close()
469+
if healthResp.StatusCode != 200 {
458470
buf := new(bytes.Buffer)
459471
body := ""
460-
_, err = buf.ReadFrom(resp.Body)
472+
_, err = buf.ReadFrom(healthResp.Body)
461473
if err != nil {
462474
body = "unable to read response body, error: " + err.Error()
463475
} else {
464476
body = buf.String()
465477
}
466-
return retry.RetryableError(fmt.Errorf("stack was not ready in %s. Status code: %d, Body: %s", timeout, resp.StatusCode, body))
478+
return retry.RetryableError(fmt.Errorf("stack was not ready in %s. Status code: %d, Body: %s", timeout, healthResp.StatusCode, body))
467479
}
468480

469481
return nil

0 commit comments

Comments
 (0)