M README.md => README.md +2 -0
@@ 106,6 106,8 @@ cache {
cleanup-interval 1h
# Redis cache settings
+ # URL to connect to redis (default: redis://localhost:6379)
+ redis-url redis://user:password@localhost:6789/3
}
```
M config.go => config.go +19 -3
@@ 56,9 56,13 @@ type labelConfig struct {
}
type cacheConfig struct {
- Type cacheType
+ // shared settings
+ Type cacheType
+ Duration time.Duration
+ // memory settings
CleanupInterval time.Duration
- Duration time.Duration
+ // redis settings
+ RedisURL string
}
type alertmanagerConfig struct {
@@ 86,8 90,11 @@ func readConfig(path string) (*config, error) {
config.alertMode = single
config.cache.Type = memory
- config.cache.CleanupInterval = time.Hour
config.cache.Duration = time.Hour * 24
+ // memory
+ config.cache.CleanupInterval = time.Hour
+ // redis
+ config.cache.RedisURL = "redis://localhost:6379"
d := cfg.Get("log-level")
if d != nil {
@@ 279,6 286,7 @@ func readConfig(path string) (*config, error) {
config.cache.Duration = duration
}
+ // memory
var cleanupIntervalString string
d = cacheDir.Children.Get("cleanup-interval")
if d != nil {
@@ 293,6 301,14 @@ func readConfig(path string) (*config, error) {
config.cache.CleanupInterval = interval
}
+
+ // redis
+ d = cacheDir.Children.Get("redis-url")
+ if d != nil {
+ if err := d.ParseParams(&config.cache.RedisURL); err != nil {
+ return nil, err
+ }
+ }
}
amDir := cfg.Get("alertmanager")
M config_test.go => config_test.go +3 -1
@@ 56,6 56,7 @@ alertmanager {
cache {
type redis
duration 48h
+ redis-url redis://user:password@localhost:6789/3
}
`
@@ 76,8 77,9 @@ cache {
},
cache: cacheConfig{
Type: redis,
- CleanupInterval: time.Hour,
Duration: 48 * time.Hour,
+ CleanupInterval: time.Hour,
+ RedisURL: "redis://user:password@localhost:6789/3",
},
am: alertmanagerConfig{
SilenceDuration: time.Hour * 24,
M main.go => main.go +1 -2
@@ 407,8 407,7 @@ func main() {
c = cache.NewMemoryCache(cfg.cache.Duration)
case redis:
var err error
- // TODO: Read URL from config
- c, err = cache.NewRedisCache("redis://localhost:6379", cfg.cache.Duration)
+ c, err = cache.NewRedisCache(cfg.cache.RedisURL, cfg.cache.Duration)
if err != nil {
logger.Fatalf("Failed to create redis cache: %v", err)
}