feat: 优化代码
This commit is contained in:
@@ -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
|
||||
|
@@ -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"
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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()
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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 停止日志清理服务
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user