refactor: remove redis direct references from proxy/admin servers
This commit is contained in:
@ -39,7 +39,7 @@ func setupKubernetesIntegration(ctx context.Context, conf *config.Config) (*kube
|
||||
kubernetes.WithPrivateKeySecretNamespace(string(conf.Integrations.Kubernetes.PrivateKeySecretNamespace)),
|
||||
kubernetes.WithIssuer(string(conf.Admin.Auth.Issuer)),
|
||||
kubernetes.WithLocker(locker),
|
||||
kubernetes.WithLockTimeout(time.Duration(conf.Integrations.Kubernetes.LockTimeout)),
|
||||
kubernetes.WithLockTimeout(time.Duration(*conf.Integrations.Kubernetes.LockTimeout)),
|
||||
)
|
||||
|
||||
return integration, nil
|
||||
|
@ -35,44 +35,52 @@ func newRedisClient(conf config.RedisConfig) redis.UniversalClient {
|
||||
client := redis.NewUniversalClient(&redis.UniversalOptions{
|
||||
Addrs: conf.Adresses,
|
||||
MasterName: string(conf.Master),
|
||||
ReadTimeout: time.Duration(conf.ReadTimeout),
|
||||
WriteTimeout: time.Duration(conf.WriteTimeout),
|
||||
DialTimeout: time.Duration(conf.DialTimeout),
|
||||
ReadTimeout: time.Duration(*conf.ReadTimeout),
|
||||
WriteTimeout: time.Duration(*conf.WriteTimeout),
|
||||
DialTimeout: time.Duration(*conf.DialTimeout),
|
||||
RouteByLatency: bool(conf.RouteByLatency),
|
||||
ContextTimeoutEnabled: bool(conf.ContextTimeoutEnabled),
|
||||
MaxRetries: int(conf.MaxRetries),
|
||||
PoolSize: int(conf.PoolSize),
|
||||
PoolTimeout: time.Duration(conf.PoolTimeout),
|
||||
PoolTimeout: time.Duration(*conf.PoolTimeout),
|
||||
MinIdleConns: int(conf.MinIdleConns),
|
||||
MaxIdleConns: int(conf.MaxIdleConns),
|
||||
ConnMaxIdleTime: time.Duration(conf.ConnMaxIdleTime),
|
||||
ConnMaxLifetime: time.Duration(conf.ConnMaxLifetime),
|
||||
ConnMaxIdleTime: time.Duration(*conf.ConnMaxIdleTime),
|
||||
ConnMaxLifetime: time.Duration(*conf.ConnMaxLifetime),
|
||||
})
|
||||
|
||||
go func() {
|
||||
ctx := logger.With(context.Background(),
|
||||
logger.F("adresses", conf.Adresses),
|
||||
logger.F("master", conf.Master),
|
||||
)
|
||||
ctx := context.Background()
|
||||
|
||||
timer := time.NewTicker(time.Duration(conf.PingInterval))
|
||||
defer timer.Stop()
|
||||
pingInterval := time.Duration(*conf.PingInterval)
|
||||
|
||||
connected := true
|
||||
if pingInterval > 0 {
|
||||
go func() {
|
||||
ctx := logger.With(ctx,
|
||||
logger.F("adresses", conf.Adresses),
|
||||
logger.F("master", conf.Master),
|
||||
)
|
||||
|
||||
for range timer.C {
|
||||
if _, err := client.Ping(ctx).Result(); err != nil {
|
||||
logger.Error(ctx, "redis disconnected", logger.CapturedE(errors.WithStack(err)))
|
||||
connected = false
|
||||
continue
|
||||
timer := time.NewTicker(pingInterval)
|
||||
defer timer.Stop()
|
||||
|
||||
connected := true
|
||||
|
||||
for range timer.C {
|
||||
if _, err := client.Ping(ctx).Result(); err != nil {
|
||||
logger.Error(ctx, "redis disconnected", logger.CapturedE(errors.WithStack(err)))
|
||||
connected = false
|
||||
continue
|
||||
}
|
||||
|
||||
if !connected {
|
||||
logger.Info(ctx, "redis reconnected")
|
||||
connected = true
|
||||
}
|
||||
}
|
||||
|
||||
if !connected {
|
||||
logger.Info(ctx, "redis reconnected")
|
||||
connected = true
|
||||
}
|
||||
}
|
||||
}()
|
||||
}()
|
||||
} else {
|
||||
logger.Warn(ctx, "redis ping interval at 0, disabling")
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
|
Reference in New Issue
Block a user