diff --git a/internal/handler/handler.go b/internal/handler/handler.go index 57a6ddc..be18b27 100644 --- a/internal/handler/handler.go +++ b/internal/handler/handler.go @@ -6,7 +6,6 @@ import ( "time" "gpt-load/internal/config" - "gpt-load/internal/models" "gpt-load/internal/services" "gpt-load/internal/types" @@ -93,20 +92,6 @@ func (s *Server) Login(c *gin.Context) { // Health handles health check requests func (s *Server) Health(c *gin.Context) { - var totalKeys, healthyKeys int64 - s.DB.Model(&models.APIKey{}).Count(&totalKeys) - s.DB.Model(&models.APIKey{}).Where("status = ?", models.KeyStatusActive).Count(&healthyKeys) - - status := "healthy" - httpStatus := http.StatusOK - - // Check if there are any healthy keys - if healthyKeys == 0 && totalKeys > 0 { - status = "unhealthy" - httpStatus = http.StatusServiceUnavailable - } - - // Calculate uptime (this should be tracked from server start time) uptime := "unknown" if startTime, exists := c.Get("serverStartTime"); exists { if st, ok := startTime.(time.Time); ok { @@ -114,11 +99,9 @@ func (s *Server) Health(c *gin.Context) { } } - c.JSON(httpStatus, gin.H{ - "status": status, - "timestamp": time.Now().UTC().Format(time.RFC3339), - "healthy_keys": healthyKeys, - "total_keys": totalKeys, - "uptime": uptime, + c.JSON(http.StatusOK, gin.H{ + "status": "healthy", + "timestamp": time.Now().UTC().Format(time.RFC3339), + "uptime": uptime, }) } diff --git a/internal/middleware/middleware.go b/internal/middleware/middleware.go index fdb5880..25d6e91 100644 --- a/internal/middleware/middleware.go +++ b/internal/middleware/middleware.go @@ -6,11 +6,11 @@ import ( "strings" "time" - "gpt-load/internal/response" - "gpt-load/internal/types" "gpt-load/internal/channel" - "gpt-load/internal/services" app_errors "gpt-load/internal/errors" + "gpt-load/internal/response" + "gpt-load/internal/services" + "gpt-load/internal/types" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" @@ -124,7 +124,7 @@ func Auth( return func(c *gin.Context) { path := c.Request.URL.Path - // Skip authentication for health/stats endpoints + // Skip authentication for health endpoints if isMonitoringEndpoint(path) { c.Next() return @@ -223,7 +223,7 @@ func ErrorHandler() gin.HandlerFunc { // isMonitoringEndpoint checks if the path is a monitoring endpoint func isMonitoringEndpoint(path string) bool { - monitoringPaths := []string{"/health", "/stats"} + monitoringPaths := []string{"/health"} for _, monitoringPath := range monitoringPaths { if path == monitoringPath { return true diff --git a/internal/router/router.go b/internal/router/router.go index 822fbae..b020e95 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -57,8 +57,9 @@ func NewRouter( router.Use(middleware.Logger(configManager.GetLogConfig())) router.Use(middleware.CORS(configManager.GetCORSConfig())) router.Use(middleware.RateLimiter(configManager.GetPerformanceConfig())) + startTime := time.Now() router.Use(func(c *gin.Context) { - c.Set("serverStartTime", time.Now()) + c.Set("serverStartTime", startTime) c.Next() }) @@ -74,7 +75,6 @@ func NewRouter( // registerSystemRoutes 注册系统级路由 func registerSystemRoutes(router *gin.Engine, serverHandler *handler.Server) { router.GET("/health", serverHandler.Health) - router.GET("/stats", serverHandler.Stats) } // registerAPIRoutes 注册API路由