Add a liveness check to results
@@ -93,6 +93,9 @@ func (o *ResultsOptions) Run() error {
if err := o.handleAPI(router, "/api/"); err != nil {
return err
}
+ if err := o.handleLiveness(router, "/health"); err != nil {
+ return err
+ }
ctx, err := o.handleShutdown(router, "/shutdown")
if err != nil {
return err
@@ -163,6 +166,15 @@ func (o *ResultsOptions) handleAPI(serveMux *http.ServeMux, prefix string) error
return nil
}
+func (o *ResultsOptions) handleLiveness(serveMux *http.ServeMux, prefix string) error {
+ serveMux.HandleFunc(prefix, func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "text/plain; charset=utf-8")
+ w.Header().Set("X-Content-Type-Options", "nosniff")
+ fmt.Fprint(w, "ok")
+ })
+ return nil
+}
+
func (o *ResultsOptions) handleShutdown(serveMux *http.ServeMux, prefix string) (context.Context, error) {
ctx, shutdown := context.WithCancel(context.Background())
serveMux.HandleFunc(prefix, func(w http.ResponseWriter, r *http.Request) {
