Skip to content

Commit 94aefe6

Browse files
committed
Fix health check for older Prometheus versions
- The output string changed in newer versions, so the fix is to check only for the substring
1 parent be72a5d commit 94aefe6

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

cmd/health_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ func TestHealthCmd(t *testing.T) {
4040
args: []string{"run", "../main.go", "health"},
4141
expected: "[OK] - Prometheus Server is Healthy. | statuscode=200\n",
4242
},
43+
{
44+
name: "health-ok-older-versions",
45+
server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
46+
w.WriteHeader(http.StatusOK)
47+
w.Write([]byte(`Prometheus is Healthy.`))
48+
})),
49+
args: []string{"run", "../main.go", "health"},
50+
expected: "[OK] - Prometheus is Healthy. | statuscode=200\n",
51+
},
4352
{
4453
name: "ready-ok",
4554
server: httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

internal/client/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ func (c *Client) GetStatus(ctx context.Context, endpoint string) (returncode int
7070
respBody := strings.TrimSpace(string(b))
7171

7272
// What we expect from the Prometheus Server
73-
statusOk := "Prometheus Server is Healthy."
73+
statusOk := "is Healthy."
7474
if endpoint == "ready" {
75-
statusOk = "Prometheus Server is Ready."
75+
statusOk = "is Ready."
7676
}
7777

78-
if resp.StatusCode == http.StatusOK && respBody == statusOk {
78+
if resp.StatusCode == http.StatusOK && strings.Contains(respBody, statusOk) {
7979
return check.OK, resp.StatusCode, respBody, err
8080
}
8181

0 commit comments

Comments
 (0)