From 0f583163f76c23c086ad72920fa7ebeb18451403 Mon Sep 17 00:00:00 2001 From: Benson Wong Date: Wed, 30 Jul 2025 10:37:10 -0700 Subject: [PATCH] add /health (#211) --- proxy/proxymanager.go | 3 +++ proxy/proxymanager_test.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/proxy/proxymanager.go b/proxy/proxymanager.go index 3751d50..b714633 100644 --- a/proxy/proxymanager.go +++ b/proxy/proxymanager.go @@ -191,6 +191,9 @@ func (pm *ProxyManager) setupGinEngine() { pm.ginEngine.GET("/unload", pm.unloadAllModelsHandler) pm.ginEngine.GET("/running", pm.listRunningProcessesHandler) + pm.ginEngine.GET("/health", func(c *gin.Context) { + c.String(http.StatusOK, "OK") + }) pm.ginEngine.GET("/favicon.ico", func(c *gin.Context) { if data, err := reactStaticFS.ReadFile("ui_dist/favicon.ico"); err == nil { diff --git a/proxy/proxymanager_test.go b/proxy/proxymanager_test.go index 81c489b..83c5bdc 100644 --- a/proxy/proxymanager_test.go +++ b/proxy/proxymanager_test.go @@ -755,3 +755,21 @@ func TestProxyManager_MiddlewareWritesMetrics_Streaming(t *testing.T) { assert.Greater(t, lastMetric.TokensPerSecond, 0.0, "tokens per second should be greater than 0") assert.Greater(t, lastMetric.DurationMs, 0, "duration should be greater than 0") } + +func TestProxyManager_HealthEndpoint(t *testing.T) { + config := AddDefaultGroupToConfig(Config{ + HealthCheckTimeout: 15, + Models: map[string]ModelConfig{ + "model1": getTestSimpleResponderConfig("model1"), + }, + LogLevel: "error", + }) + + proxy := New(config) + defer proxy.StopProcesses(StopWaitForInflightRequest) + req := httptest.NewRequest("GET", "/health", nil) + rec := httptest.NewRecorder() + proxy.ServeHTTP(rec, req) + assert.Equal(t, http.StatusOK, rec.Code) + assert.Equal(t, "OK", rec.Body.String()) +}