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

Fix health check for older Prometheus versions #6

Merged
merged 1 commit into from
Aug 25, 2023
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
9 changes: 9 additions & 0 deletions cmd/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ func TestHealthCmd(t *testing.T) {
args: []string{"run", "../main.go", "health"},
expected: "[OK] - Prometheus Server is Healthy. | statuscode=200\n",
},
{
name: "health-ok-older-versions",
server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`Prometheus is Healthy.`))
})),
args: []string{"run", "../main.go", "health"},
expected: "[OK] - Prometheus is Healthy. | statuscode=200\n",
},
{
name: "ready-ok",
server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down
6 changes: 3 additions & 3 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ func (c *Client) GetStatus(ctx context.Context, endpoint string) (returncode int
respBody := strings.TrimSpace(string(b))

// What we expect from the Prometheus Server
statusOk := "Prometheus Server is Healthy."
statusOk := "is Healthy."
if endpoint == "ready" {
statusOk = "Prometheus Server is Ready."
statusOk = "is Ready."
}

if resp.StatusCode == http.StatusOK && respBody == statusOk {
if resp.StatusCode == http.StatusOK && strings.Contains(respBody, statusOk) {
return check.OK, resp.StatusCode, respBody, err
}

Expand Down