Skip to content

Commit

Permalink
Merge pull request #6 from NETWAYS/fix/health-older-versions
Browse files Browse the repository at this point in the history
Fix health check for older Prometheus versions
  • Loading branch information
martialblog authored Aug 25, 2023
2 parents be72a5d + 94aefe6 commit 2812591
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit 2812591

Please sign in to comment.