Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
fix(server.go): add OK output to /healthz when healthy (#16)
Browse files Browse the repository at this point in the history
Some loadbalancers (e.g. Google Cloud Load Balancer) don't accept a HTTP status code of 204 No
Content as healthy so we've decided to return 200 OK and the string OK instead.
  • Loading branch information
tongpu authored Apr 15, 2021
1 parent 358dffe commit 6a90c29
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ func index(template *template.Template, counterHandle counterHandler) http.Handl
func healthz() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if atomic.LoadInt32(&healthy) == 1 {
w.WriteHeader(http.StatusNoContent)
_, err := w.Write([]byte("OK"))
if err != nil {
log.Fatal(err)
}
return
}
w.WriteHeader(http.StatusServiceUnavailable)
Expand Down

0 comments on commit 6a90c29

Please sign in to comment.