From 0893d3cbbebc6f7c5fa1d65e4b17e7d900ae60d4 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Tue, 24 Sep 2024 20:25:59 +0200 Subject: [PATCH] fix(health): do not require auth for /healthz and /readyz (#3656) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(health): do not require auth for /healthz and /readyz Fixes: #3655 Signed-off-by: Ettore Di Giacinto * Comment so I don’t forget Adding a reminder here... --------- Signed-off-by: Ettore Di Giacinto Co-authored-by: Dave --- core/http/app.go | 3 +++ core/http/routes/health.go | 13 +++++++++++++ core/http/routes/localai.go | 8 -------- 3 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 core/http/routes/health.go diff --git a/core/http/app.go b/core/http/app.go index 23e97f18..2cf0ad17 100644 --- a/core/http/app.go +++ b/core/http/app.go @@ -121,6 +121,9 @@ func App(cl *config.BackendConfigLoader, ml *model.ModelLoader, appConfig *confi }) } + // Health Checks should always be exempt from auth, so register these first + routes.HealthRoutes(app) + kaConfig, err := middleware.GetKeyAuthConfig(appConfig) if err != nil || kaConfig == nil { return nil, fmt.Errorf("failed to create key auth config: %w", err) diff --git a/core/http/routes/health.go b/core/http/routes/health.go new file mode 100644 index 00000000..f5a08e9b --- /dev/null +++ b/core/http/routes/health.go @@ -0,0 +1,13 @@ +package routes + +import "github.com/gofiber/fiber/v2" + +func HealthRoutes(app *fiber.App) { + // Service health checks + ok := func(c *fiber.Ctx) error { + return c.SendStatus(200) + } + + app.Get("/healthz", ok) + app.Get("/readyz", ok) +} diff --git a/core/http/routes/localai.go b/core/http/routes/localai.go index 247596c0..2f65e779 100644 --- a/core/http/routes/localai.go +++ b/core/http/routes/localai.go @@ -42,14 +42,6 @@ func RegisterLocalAIRoutes(app *fiber.App, app.Post("/stores/get", localai.StoresGetEndpoint(sl, appConfig)) app.Post("/stores/find", localai.StoresFindEndpoint(sl, appConfig)) - // Kubernetes health checks - ok := func(c *fiber.Ctx) error { - return c.SendStatus(200) - } - - app.Get("/healthz", ok) - app.Get("/readyz", ok) - app.Get("/metrics", localai.LocalAIMetricsEndpoint()) // Experimental Backend Statistics Module