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: not ready when Prometheus is unavailable #4939

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

### Changed

- [#4939](https://github.com/thanos-io/thanos/pull/4939) Sidecar: set Sidecar to NOT READY when it cannot establish a connection with Prometheus
- [#4864](https://github.com/thanos-io/thanos/pull/4864) UI: Remove the old PromQL editor

## [v0.23.1](https://github.com/thanos-io/thanos/tree/release-0.23) - 2021.10.1
Expand Down
2 changes: 2 additions & 0 deletions cmd/thanos/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ func runSidecar(
if err := m.UpdateLabels(iterCtx); err != nil {
level.Warn(logger).Log("msg", "heartbeat failed", "err", err)
promUp.Set(0)
statusProber.NotReady(err)
} else {
promUp.Set(1)
statusProber.Ready()
}

return nil
Expand Down
35 changes: 35 additions & 0 deletions test/e2e/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package e2e_test
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"os"
Expand Down Expand Up @@ -103,6 +104,40 @@ func sortResults(res model.Vector) {
})
}

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

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

prom, sidecar, err := e2ethanos.NewPrometheusWithSidecar(e, "alone", defaultPromConfig("prom-alone", 0, "", ""), "", e2ethanos.DefaultPrometheusImage())
testutil.Ok(t, err)
testutil.Ok(t, e2e.StartAndWaitReady(prom, sidecar))
testutil.Ok(t, prom.Stop())

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

// Sidecar should not be ready - it cannot accept traffic if Prometheus is down.
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("got status code %d", resp.StatusCode)
return fmt.Errorf("sidecar should not be ready, got HTTP status code %d OK", resp.StatusCode)

Copy link
Contributor

Choose a reason for hiding this comment

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

Why OK?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because that's what usually goes after 200 in the HTTP response https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200? (:

Copy link
Contributor

Choose a reason for hiding this comment

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

Because that's what usually goes after 200 in the HTTP response https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/200? (:

yes, in case someone doesn't know what status code 200 signifies.

Copy link
Contributor

Choose a reason for hiding this comment

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

Printing the status code and OK the same time seems redundant.

Copy link
Member Author

Choose a reason for hiding this comment

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

So, can we merge this then @yeya24 ?

}
return nil
}))
}

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

Expand Down