Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sidecar: set to not ready when failing to fetch prometheus version #7291

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/thanos/sidecar.go
Expand Up @@ -189,6 +189,8 @@ func runSidecar(
"msg", "failed to fetch prometheus version. Is Prometheus running? Retrying",
"err", err,
)
promUp.Set(0)
statusProber.NotReady(err)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can update here or default readiness to false at the beginning of runSidecar()

return err
}

Expand Down
33 changes: 33 additions & 0 deletions test/e2e/query_test.go
Expand Up @@ -235,6 +235,39 @@ func TestSidecarNotReady(t *testing.T) {
}))
}

func TestSidecarNotReadyNoPrometheus(t *testing.T) {
t.Parallel()

e, err := e2e.NewDockerEnvironment("sidecar-noProm")
testutil.Ok(t, err)
t.Cleanup(e2ethanos.CleanScenario(t, e))

// Start sidecar without ever starting Prometheus.
_, sidecar := e2ethanos.NewPrometheusWithSidecar(e, "alone", e2ethanos.DefaultPromConfig("prom-alone", 0, "", "", e2ethanos.LocalPrometheusTarget), "", e2ethanos.DefaultPrometheusImage(), "")
testutil.Ok(t, sidecar.Start())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use e2e.StartAndWaitReady() here, relying on sidecar's health endpoint as readiness check to make sure we have a running sidecar before testing?


ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Sidecar should not be ready if there was never a ready Prometheus.
testutil.Ok(t, runutil.Retry(1*time.Second, ctx.Done(), func() (rerr error) {
req, err := http.NewRequestWithContext(ctx, "GET", "http://"+sidecar.Endpoint("http")+"/-/ready", nil)
if err != nil {
return err
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer runutil.CloseWithErrCapture(&rerr, resp.Body, "closing resp body")

if resp.StatusCode == 200 {
return fmt.Errorf("got status code %d", resp.StatusCode)
}
return nil
}))
}

func TestQuery(t *testing.T) {
t.Parallel()

Expand Down