From 395d48c3e76475b4287a927a9e7232d3e0fcc8db Mon Sep 17 00:00:00 2001 From: tbphp Date: Fri, 11 Jul 2025 13:47:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/app/app.go | 10 ++++------ internal/config/manager.go | 18 +----------------- internal/db/database.go | 1 - internal/services/key_cron_service.go | 2 +- internal/services/leader_service.go | 4 ++-- internal/services/log_cleanup.go | 2 +- internal/store/factory.go | 2 +- 7 files changed, 10 insertions(+), 29 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index 627ef8d..3b9fca0 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -124,7 +124,7 @@ func (a *App) Start() error { if err := a.keyPoolProvider.LoadKeysFromDB(); err != nil { return fmt.Errorf("failed to load keys into key pool: %w", err) } - logrus.Info("API keys loaded into Redis cache by leader.") + logrus.Debug("API keys loaded into Redis cache by leader.") } } else { logrus.Info("Follower Mode. Waiting for leader to complete initialization.") @@ -134,11 +134,11 @@ func (a *App) Start() error { a.settingsManager.Initialize(a.storage, a.groupManager, a.leaderService) } - a.groupManager.Initialize() - // 显示配置并启动所有后台服务 a.configManager.DisplayConfig() + a.groupManager.Initialize() + a.startRequestLogger() a.logCleanupService.Start() a.keyValidationPool.Start() @@ -159,8 +159,6 @@ func (a *App) Start() error { go func() { logrus.Info("GPT-Load proxy server started successfully") logrus.Infof("Server address: http://%s:%d", serverConfig.Host, serverConfig.Port) - logrus.Infof("Statistics: http://%s:%d/stats", serverConfig.Host, serverConfig.Port) - logrus.Infof("Health check: http://%s:%d/health", serverConfig.Host, serverConfig.Port) logrus.Info("") if err := a.httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed { logrus.Fatalf("Server startup failed: %v", err) @@ -184,10 +182,10 @@ func (a *App) Stop(ctx context.Context) { a.keyValidationPool.Stop() a.leaderService.Stop() a.logCleanupService.Stop() + a.groupManager.Stop() a.settingsManager.Stop() // Close resources - a.proxyServer.Close() a.storage.Close() // Wait for the logger to finish writing all logs diff --git a/internal/config/manager.go b/internal/config/manager.go index c381891..d4712a5 100644 --- a/internal/config/manager.go +++ b/internal/config/manager.go @@ -46,7 +46,6 @@ type Manager struct { // Config represents the application configuration type Config struct { Server types.ServerConfig `json:"server"` - OpenAI types.OpenAIConfig `json:"openai"` Auth types.AuthConfig `json:"auth"` CORS types.CORSConfig `json:"cors"` Performance types.PerformanceConfig `json:"performance"` @@ -87,14 +86,6 @@ func (m *Manager) ReloadConfig() error { IdleTimeout: defaultSettings.ServerIdleTimeout, GracefulShutdownTimeout: defaultSettings.ServerGracefulShutdownTimeout, }, - OpenAI: types.OpenAIConfig{ - // BaseURLs will be configured per group - BaseURLs: []string{}, - // Timeout configs now come from system settings - RequestTimeout: defaultSettings.RequestTimeout, - ResponseTimeout: defaultSettings.ResponseTimeout, - IdleConnTimeout: defaultSettings.IdleConnTimeout, - }, Auth: types.AuthConfig{ Key: os.Getenv("AUTH_KEY"), Enabled: os.Getenv("AUTH_KEY") != "", @@ -130,16 +121,9 @@ func (m *Manager) ReloadConfig() error { return err } - logrus.Info("Environment configuration reloaded successfully") - return nil } -// GetConfig returns the raw config struct -func (m *Manager) GetConfig() *Config { - return m.config -} - // GetAuthConfig returns authentication configuration func (m *Manager) GetAuthConfig() types.AuthConfig { return m.config.Auth @@ -217,7 +201,7 @@ func (m *Manager) DisplayConfig() { perfConfig := m.GetPerformanceConfig() logConfig := m.GetLogConfig() - logrus.Info("Current Configuration:") + logrus.Info("Current Server Configuration:") logrus.Infof(" Server: %s:%d", serverConfig.Host, serverConfig.Port) authStatus := "disabled" diff --git a/internal/db/database.go b/internal/db/database.go index 909d030..d92bef9 100644 --- a/internal/db/database.go +++ b/internal/db/database.go @@ -51,6 +51,5 @@ func NewDB(configManager types.ConfigManager) (*gorm.DB, error) { sqlDB.SetMaxOpenConns(100) sqlDB.SetConnMaxLifetime(time.Hour) - fmt.Println("Database connection initialized.") return DB, nil } diff --git a/internal/services/key_cron_service.go b/internal/services/key_cron_service.go index 3ba3c96..2f2e250 100644 --- a/internal/services/key_cron_service.go +++ b/internal/services/key_cron_service.go @@ -39,7 +39,7 @@ func NewKeyCronService( // Start begins the cron job execution. func (s *KeyCronService) Start() { - logrus.Info("Starting KeyCronService...") + logrus.Debug("Starting KeyCronService...") s.wg.Add(1) go s.runLoop() } diff --git a/internal/services/leader_service.go b/internal/services/leader_service.go index 0b0df5c..0094e19 100644 --- a/internal/services/leader_service.go +++ b/internal/services/leader_service.go @@ -170,7 +170,7 @@ func (s *LeaderService) maintainLeadershipLoop() { ticker := time.NewTicker(leaderRenewalInterval) defer ticker.Stop() - logrus.Info("Leadership maintenance loop started.") + logrus.Debug("Leadership maintenance loop started.") for { select { case <-ticker.C: @@ -200,7 +200,7 @@ func (s *LeaderService) tryToBeLeader() error { return fmt.Errorf("failed to acquire lock: %w", err) } if acquired { - logrus.WithField("nodeID", s.nodeID).Info("Successfully acquired leadership.") + logrus.WithField("nodeID", s.nodeID).Debug("Successfully acquired leadership.") s.isLeader.Store(true) } return nil diff --git a/internal/services/log_cleanup.go b/internal/services/log_cleanup.go index 0e9a754..4c137a1 100644 --- a/internal/services/log_cleanup.go +++ b/internal/services/log_cleanup.go @@ -30,7 +30,7 @@ func NewLogCleanupService(db *gorm.DB, settingsManager *config.SystemSettingsMan // Start 启动日志清理服务 func (s *LogCleanupService) Start() { go s.run() - logrus.Info("Log cleanup service started") + logrus.Debug("Log cleanup service started") } // Stop 停止日志清理服务 diff --git a/internal/store/factory.go b/internal/store/factory.go index 9980b56..f0a6f45 100644 --- a/internal/store/factory.go +++ b/internal/store/factory.go @@ -23,7 +23,7 @@ func NewStore(cfg types.ConfigManager) (Store, error) { return nil, fmt.Errorf("failed to connect to redis: %w", err) } - logrus.Info("Successfully connected to Redis.") + logrus.Debug("Successfully connected to Redis.") return NewRedisStore(client), nil }