From 04d4a5ee5d7a235f44e3cd30ce67c4aa5ad85d9a Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Tue, 15 Mar 2022 16:23:34 -0400 Subject: [PATCH 1/3] Add CLI args for snapshot intervals Signed-off-by: sed-i <82407168+sed-i@users.noreply.github.com> --- cmd/alertmanager/main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/alertmanager/main.go b/cmd/alertmanager/main.go index a7fe71f53a..e95f2999fd 100644 --- a/cmd/alertmanager/main.go +++ b/cmd/alertmanager/main.go @@ -195,6 +195,9 @@ func run() int { retention = kingpin.Flag("data.retention", "How long to keep data for.").Default("120h").Duration() alertGCInterval = kingpin.Flag("alerts.gc-interval", "Interval between alert GC.").Default("30m").Duration() + silencesInterval = kingpin.Flag("silences.interval", "Interval between writing silences snapshot to disk.").Default("15m").Duration() + nflogsInterval = kingpin.Flag("nflogs.interval", "Interval between writing nflogs snapshot to disk.").Default("15m").Duration() + webConfig = webflag.AddFlags(kingpin.CommandLine) externalURL = kingpin.Flag("web.external-url", "The URL under which Alertmanager is externally reachable (for example, if Alertmanager is served via a reverse proxy). Used for generating relative and absolute links back to Alertmanager itself. If the URL has a path portion, it will be used to prefix all HTTP endpoints served by Alertmanager. If omitted, relevant URL components will be derived automatically.").String() routePrefix = kingpin.Flag("web.route-prefix", "Prefix for the internal routes of web endpoints. Defaults to path of --web.external-url.").String() @@ -273,7 +276,7 @@ func run() int { notificationLogOpts := []nflog.Option{ nflog.WithRetention(*retention), nflog.WithSnapshot(filepath.Join(*dataDir, "nflog")), - nflog.WithMaintenance(15*time.Minute, stopc, wg.Done, nil), + nflog.WithMaintenance(*nflogsInterval, stopc, wg.Done, nil), nflog.WithMetrics(prometheus.DefaultRegisterer), nflog.WithLogger(log.With(logger, "component", "nflog")), } @@ -310,7 +313,7 @@ func run() int { // Start providers before router potentially sends updates. wg.Add(1) go func() { - silences.Maintenance(15*time.Minute, filepath.Join(*dataDir, "silences"), stopc, nil) + silences.Maintenance(*silencesInterval, filepath.Join(*dataDir, "silences"), stopc, nil) wg.Done() }() From 7b698b5136c99c872a12325f58274844aa7ad46b Mon Sep 17 00:00:00 2001 From: Leon <82407168+sed-i@users.noreply.github.com> Date: Thu, 17 Mar 2022 13:53:34 +0000 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Simon Pasquier Signed-off-by: sed-i <82407168+sed-i@users.noreply.github.com> --- cmd/alertmanager/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/alertmanager/main.go b/cmd/alertmanager/main.go index e95f2999fd..fc9400ef78 100644 --- a/cmd/alertmanager/main.go +++ b/cmd/alertmanager/main.go @@ -195,8 +195,8 @@ func run() int { retention = kingpin.Flag("data.retention", "How long to keep data for.").Default("120h").Duration() alertGCInterval = kingpin.Flag("alerts.gc-interval", "Interval between alert GC.").Default("30m").Duration() - silencesInterval = kingpin.Flag("silences.interval", "Interval between writing silences snapshot to disk.").Default("15m").Duration() - nflogsInterval = kingpin.Flag("nflogs.interval", "Interval between writing nflogs snapshot to disk.").Default("15m").Duration() + silencesInterval = kingpin.Flag("silences.maintenance-interval", "Interval between garbage collection and snapshotting to disk of the silences.").Default("15m").Duration() + nflogsInterval = kingpin.Flag("nflogs.maintenance-interval", "Interval between garbage collection and snapshotting to disk of the notification logs.").Default("15m").Duration() webConfig = webflag.AddFlags(kingpin.CommandLine) externalURL = kingpin.Flag("web.external-url", "The URL under which Alertmanager is externally reachable (for example, if Alertmanager is served via a reverse proxy). Used for generating relative and absolute links back to Alertmanager itself. If the URL has a path portion, it will be used to prefix all HTTP endpoints served by Alertmanager. If omitted, relevant URL components will be derived automatically.").String() From 99f48e36b134aff424c04376c656febc35c29d13 Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Fri, 18 Mar 2022 09:45:57 -0400 Subject: [PATCH 3/3] use same flag for silences and nflogs intervals Signed-off-by: sed-i <82407168+sed-i@users.noreply.github.com> --- cmd/alertmanager/main.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cmd/alertmanager/main.go b/cmd/alertmanager/main.go index fc9400ef78..6920c46f97 100644 --- a/cmd/alertmanager/main.go +++ b/cmd/alertmanager/main.go @@ -190,13 +190,11 @@ func run() int { } var ( - configFile = kingpin.Flag("config.file", "Alertmanager configuration file name.").Default("alertmanager.yml").String() - dataDir = kingpin.Flag("storage.path", "Base path for data storage.").Default("data/").String() - retention = kingpin.Flag("data.retention", "How long to keep data for.").Default("120h").Duration() - alertGCInterval = kingpin.Flag("alerts.gc-interval", "Interval between alert GC.").Default("30m").Duration() - - silencesInterval = kingpin.Flag("silences.maintenance-interval", "Interval between garbage collection and snapshotting to disk of the silences.").Default("15m").Duration() - nflogsInterval = kingpin.Flag("nflogs.maintenance-interval", "Interval between garbage collection and snapshotting to disk of the notification logs.").Default("15m").Duration() + configFile = kingpin.Flag("config.file", "Alertmanager configuration file name.").Default("alertmanager.yml").String() + dataDir = kingpin.Flag("storage.path", "Base path for data storage.").Default("data/").String() + retention = kingpin.Flag("data.retention", "How long to keep data for.").Default("120h").Duration() + maintenanceInterval = kingpin.Flag("data.maintenance-interval", "Interval between garbage collection and snapshotting to disk of the silences and the notification logs.").Default("15m").Duration() + alertGCInterval = kingpin.Flag("alerts.gc-interval", "Interval between alert GC.").Default("30m").Duration() webConfig = webflag.AddFlags(kingpin.CommandLine) externalURL = kingpin.Flag("web.external-url", "The URL under which Alertmanager is externally reachable (for example, if Alertmanager is served via a reverse proxy). Used for generating relative and absolute links back to Alertmanager itself. If the URL has a path portion, it will be used to prefix all HTTP endpoints served by Alertmanager. If omitted, relevant URL components will be derived automatically.").String() @@ -276,7 +274,7 @@ func run() int { notificationLogOpts := []nflog.Option{ nflog.WithRetention(*retention), nflog.WithSnapshot(filepath.Join(*dataDir, "nflog")), - nflog.WithMaintenance(*nflogsInterval, stopc, wg.Done, nil), + nflog.WithMaintenance(*maintenanceInterval, stopc, wg.Done, nil), nflog.WithMetrics(prometheus.DefaultRegisterer), nflog.WithLogger(log.With(logger, "component", "nflog")), } @@ -313,7 +311,7 @@ func run() int { // Start providers before router potentially sends updates. wg.Add(1) go func() { - silences.Maintenance(*silencesInterval, filepath.Join(*dataDir, "silences"), stopc, nil) + silences.Maintenance(*maintenanceInterval, filepath.Join(*dataDir, "silences"), stopc, nil) wg.Done() }()