-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KUBE-554: add healthcheck endpoint (#12)
- Loading branch information
Showing
7 changed files
with
102 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package healthz | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type Server struct { | ||
log *logrus.Logger | ||
} | ||
|
||
func NewServer(log *logrus.Logger) *Server { | ||
return &Server{ | ||
log: log, | ||
} | ||
} | ||
|
||
func (hc *Server) Run(addr string) error { | ||
mux := http.NewServeMux() | ||
|
||
mux.HandleFunc("/readyz", hc.readyCheck) | ||
mux.HandleFunc("/livez", hc.liveCheck) | ||
|
||
return http.ListenAndServe(addr, mux) | ||
} | ||
|
||
func (hc *Server) readyCheck(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("content-type", "application/json") | ||
|
||
// TODO: Implement proper readiness checks. | ||
|
||
response := map[string]string{ | ||
"status": "ok", | ||
} | ||
|
||
body, err := json.Marshal(response) | ||
if err != nil { | ||
hc.log.WithError(err).Errorf("Failed to marshal readiness check response") | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
w.WriteHeader(http.StatusOK) | ||
|
||
if _, err := w.Write(body); err != nil { | ||
hc.log.WithError(err).Errorf("Failed to write response body") | ||
} | ||
} | ||
|
||
func (hc *Server) liveCheck(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("content-type", "application/json") | ||
|
||
// TODO: Implement proper liveness checks. | ||
|
||
response := map[string]string{ | ||
"status": "ok", | ||
} | ||
|
||
body, err := json.Marshal(response) | ||
if err != nil { | ||
hc.log.WithError(err).Errorf("Failed to marshal readiness check response") | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
w.WriteHeader(http.StatusOK) | ||
|
||
if _, err := w.Write(body); err != nil { | ||
hc.log.WithError(err).Errorf("Failed to write response body") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters