client: include response body in output for successful HTTP checks (#18345)

This commit is contained in:
Matthew Salsamendi
2023-08-28 16:15:06 -07:00
committed by GitHub
parent f187afab9f
commit d0a93f12d1
3 changed files with 6 additions and 7 deletions

3
.changelog/18345.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:improvement
services: Include response body in output for successful HTTP checks when using Nomad native service discovery
```

View File

@@ -205,16 +205,12 @@ func (c *checker) checkHTTP(ctx context.Context, qc *QueryContext, q *Query) *st
switch {
case result.StatusCode == http.StatusOK:
qr.Status = structs.CheckSuccess
qr.Output = "nomad: http ok"
return qr
case result.StatusCode < http.StatusBadRequest:
qr.Status = structs.CheckSuccess
default:
qr.Status = structs.CheckFailure
}
// status code was not 200; read the response body and set that as the
// check result output content
qr.Output = limitRead(result.Body)
return qr

View File

@@ -143,7 +143,7 @@ func TestChecker_Do_HTTP(t *testing.T) {
structs.Healthiness,
structs.CheckSuccess,
http.StatusOK,
"nomad: http ok",
"200 ok",
),
}, {
name: "200 readiness",
@@ -153,7 +153,7 @@ func TestChecker_Do_HTTP(t *testing.T) {
structs.Readiness,
structs.CheckSuccess,
http.StatusOK,
"nomad: http ok",
"200 ok",
),
}, {
name: "500 healthiness",
@@ -203,7 +203,7 @@ func TestChecker_Do_HTTP(t *testing.T) {
structs.Healthiness,
structs.CheckSuccess,
http.StatusOK,
"nomad: http ok",
"200 ok",
),
}}