feat(platform): support redis sentinel for failover

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-21 23:37:48 +01:00
1 parent dbae2870bc
commit 2bd3d0a18e
5 files changed
+110 -13

No files matched your search

+22 -7
View File
@@ -16,14 +16,26 @@ const (
)
type Common struct {
Edition Edition `env:"UPTIME_EDITION" envDefault:"selfhosted"`
LogLevel slog.Level `env:"UPTIME_LOG_LEVEL" envDefault:"info"`
LogFormat string `env:"UPTIME_LOG_FORMAT" envDefault:"json"`
DatabaseURL string `env:"UPTIME_DATABASE_URL"`
RedisURL string `env:"UPTIME_REDIS_URL"`
Edition Edition `env:"UPTIME_EDITION" envDefault:"selfhosted"`
LogLevel slog.Level `env:"UPTIME_LOG_LEVEL" envDefault:"info"`
LogFormat string `env:"UPTIME_LOG_FORMAT" envDefault:"json"`
DatabaseURL string `env:"UPTIME_DATABASE_URL"`
RedisURL string `env:"UPTIME_REDIS_URL"`
RedisSentinel Sentinel
ShutdownTimeout time.Duration `env:"UPTIME_SHUTDOWN_TIMEOUT" envDefault:"20s"`
}
// Sentinel switches the redis client to failover mode. UPTIME_REDIS_URL then
// only contributes credentials, db and TLS for the master; its host is ignored.
type Sentinel struct {
Master string `env:"UPTIME_REDIS_SENTINEL_MASTER"`
Addrs []string `env:"UPTIME_REDIS_SENTINEL_ADDRS" envSeparator:","`
Username string `env:"UPTIME_REDIS_SENTINEL_USERNAME"`
Password string `env:"UPTIME_REDIS_SENTINEL_PASSWORD"`
}
func (s Sentinel) Enabled() bool { return s.Master != "" }
type API struct {
Common
Listen string `env:"UPTIME_API_LISTEN" envDefault:":8080"`
@@ -57,8 +69,11 @@ func (c Common) Validate() error {
if c.DatabaseURL == "" {
return fmt.Errorf("config: UPTIME_DATABASE_URL is required")
}
if c.RedisURL == "" {
return fmt.Errorf("config: UPTIME_REDIS_URL is required")
switch {
case c.RedisSentinel.Enabled() && len(c.RedisSentinel.Addrs) == 0:
return fmt.Errorf("config: UPTIME_REDIS_SENTINEL_ADDRS is required with UPTIME_REDIS_SENTINEL_MASTER")
case !c.RedisSentinel.Enabled() && c.RedisURL == "":
return fmt.Errorf("config: UPTIME_REDIS_URL or UPTIME_REDIS_SENTINEL_MASTER is required")
}
return nil
}