mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
/-/{healthy,ready}/ respond to HEAD (#11160)
Some frameworks issue HEAD requests to determine health. This resolves prometheus/prometheus#11159 Signed-off-by: Nicolas Dumazet <nicdumz.commits@gmail.com> Signed-off-by: Nicolas Dumazet <nicdumz.commits@gmail.com>
This commit is contained in:
parent
0b03ef73cf
commit
9594fa4dbd
|
@ -12,6 +12,7 @@ Prometheus provides a set of management APIs to facilitate automation and integr
|
|||
|
||||
```
|
||||
GET /-/healthy
|
||||
HEAD /-/healthy
|
||||
```
|
||||
|
||||
This endpoint always returns 200 and should be used to check Prometheus health.
|
||||
|
@ -21,6 +22,7 @@ This endpoint always returns 200 and should be used to check Prometheus health.
|
|||
|
||||
```
|
||||
GET /-/ready
|
||||
HEAD /-/ready
|
||||
```
|
||||
|
||||
This endpoint returns 200 when Prometheus is ready to serve traffic (i.e. respond to queries).
|
||||
|
|
|
@ -471,10 +471,16 @@ func New(logger log.Logger, o *Options) *Handler {
|
|||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, o.AppName+" is Healthy.\n")
|
||||
})
|
||||
router.Head("/-/healthy", func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
router.Get("/-/ready", readyf(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, o.AppName+" is Ready.\n")
|
||||
}))
|
||||
router.Head("/-/ready", readyf(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
|
||||
return h
|
||||
}
|
||||
|
|
|
@ -126,6 +126,11 @@ func TestReadyAndHealthy(t *testing.T) {
|
|||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
cleanupTestResponse(t, resp)
|
||||
|
||||
resp, err = http.Head(baseURL + "/-/healthy")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
cleanupTestResponse(t, resp)
|
||||
|
||||
for _, u := range []string{
|
||||
baseURL + "/-/ready",
|
||||
} {
|
||||
|
@ -133,6 +138,11 @@ func TestReadyAndHealthy(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusServiceUnavailable, resp.StatusCode)
|
||||
cleanupTestResponse(t, resp)
|
||||
|
||||
resp, err = http.Head(u)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusServiceUnavailable, resp.StatusCode)
|
||||
cleanupTestResponse(t, resp)
|
||||
}
|
||||
|
||||
resp, err = http.Post(baseURL+"/api/v1/admin/tsdb/snapshot", "", strings.NewReader(""))
|
||||
|
@ -156,6 +166,11 @@ func TestReadyAndHealthy(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
cleanupTestResponse(t, resp)
|
||||
|
||||
resp, err = http.Head(u)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
cleanupTestResponse(t, resp)
|
||||
}
|
||||
|
||||
resp, err = http.Post(baseURL+"/api/v1/admin/tsdb/snapshot", "", strings.NewReader(""))
|
||||
|
|
Loading…
Reference in a new issue