From b6158e8956110b24e8b39072dd6d9c9d0fd649bb Mon Sep 17 00:00:00 2001 From: Julien Date: Thu, 3 Oct 2024 10:26:05 +0200 Subject: [PATCH] Notify web UI when starting up and shutting down Signed-off-by: Julien --- cmd/prometheus/main.go | 3 +++ web/api/notifications.go | 2 ++ 2 files changed, 5 insertions(+) diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index d8369770bc..8ad1db6378 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -503,6 +503,7 @@ func main() { notifs := api.NewNotifications(cfg.maxNotificationsSubscribers, prometheus.DefaultRegisterer) cfg.web.NotificationsSub = notifs.Sub cfg.web.NotificationsGetter = notifs.Get + notifs.AddNotification(api.StartingUp) if err := cfg.setFeatureListOptions(logger); err != nil { fmt.Fprintln(os.Stderr, fmt.Errorf("Error parsing feature list: %w", err)) @@ -989,6 +990,7 @@ func main() { func(err error) { close(cancel) webHandler.SetReady(web.Stopping) + notifs.AddNotification(api.ShuttingDown) }, ) } @@ -1174,6 +1176,7 @@ func main() { reloadReady.Close() webHandler.SetReady(web.Ready) + notifs.DeleteNotification(api.StartingUp) level.Info(logger).Log("msg", "Server is ready to receive web requests.") <-cancel return nil diff --git a/web/api/notifications.go b/web/api/notifications.go index 976f0b0768..a838fbd989 100644 --- a/web/api/notifications.go +++ b/web/api/notifications.go @@ -22,6 +22,8 @@ import ( const ( ConfigurationUnsuccessful = "Configuration reload has failed." + StartingUp = "Prometheus is starting and replaying the write-ahead log (WAL)." + ShuttingDown = "Prometheus is shutting down and gracefully stopping all operations." ) // Notification represents an individual notification message.