diff --git a/pkg/services/frontend/frontend_service.go b/pkg/services/frontend/frontend_service.go index 3a7230f9d1b..32cea9cffc8 100644 --- a/pkg/services/frontend/frontend_service.go +++ b/pkg/services/frontend/frontend_service.go @@ -138,6 +138,16 @@ func (s *frontendService) registerRoutes(m *web.Mux) { // them so we can get logs for them s.routeGet(m, "/public/*", http.NotFound) + // Empty health check endpoint to allow k8s and other orchestrators to check if the server is alive + // Useful to have a separate route for this for logging and metrics purposes + s.routeGet(m, "/-/health", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + + if _, err := w.Write([]byte("OK")); err != nil { + s.log.Error("failed to write health check response", "error", err) + } + }) + // All other requests return index.html s.routeGet(m, "/*", s.index.HandleRequest) } diff --git a/pkg/services/frontend/frontend_service_test.go b/pkg/services/frontend/frontend_service_test.go index 05490ae63ab..dc39993a6a0 100644 --- a/pkg/services/frontend/frontend_service_test.go +++ b/pkg/services/frontend/frontend_service_test.go @@ -120,6 +120,16 @@ func TestFrontendService_Routes(t *testing.T) { assert.Contains(t, recorder.Body.String(), "\nshrimp_count 1\n") }) + + t.Run("should return health status correctly", func(t *testing.T) { + req := httptest.NewRequest("GET", "/-/health", nil) + recorder := httptest.NewRecorder() + + mux.ServeHTTP(recorder, req) + + assert.Equal(t, 200, recorder.Code) + assert.Equal(t, "OK", strings.TrimSpace(recorder.Body.String())) + }) } func TestFrontendService_Middleware(t *testing.T) {