Notify web UI when starting up and shutting down

Signed-off-by: Julien <roidelapluie@o11y.eu>
This commit is contained in:
Julien 2024-10-03 10:26:05 +02:00
parent 199d2fb492
commit b6158e8956
2 changed files with 5 additions and 0 deletions

View file

@ -503,6 +503,7 @@ func main() {
notifs := api.NewNotifications(cfg.maxNotificationsSubscribers, prometheus.DefaultRegisterer) notifs := api.NewNotifications(cfg.maxNotificationsSubscribers, prometheus.DefaultRegisterer)
cfg.web.NotificationsSub = notifs.Sub cfg.web.NotificationsSub = notifs.Sub
cfg.web.NotificationsGetter = notifs.Get cfg.web.NotificationsGetter = notifs.Get
notifs.AddNotification(api.StartingUp)
if err := cfg.setFeatureListOptions(logger); err != nil { if err := cfg.setFeatureListOptions(logger); err != nil {
fmt.Fprintln(os.Stderr, fmt.Errorf("Error parsing feature list: %w", err)) fmt.Fprintln(os.Stderr, fmt.Errorf("Error parsing feature list: %w", err))
@ -989,6 +990,7 @@ func main() {
func(err error) { func(err error) {
close(cancel) close(cancel)
webHandler.SetReady(web.Stopping) webHandler.SetReady(web.Stopping)
notifs.AddNotification(api.ShuttingDown)
}, },
) )
} }
@ -1174,6 +1176,7 @@ func main() {
reloadReady.Close() reloadReady.Close()
webHandler.SetReady(web.Ready) webHandler.SetReady(web.Ready)
notifs.DeleteNotification(api.StartingUp)
level.Info(logger).Log("msg", "Server is ready to receive web requests.") level.Info(logger).Log("msg", "Server is ready to receive web requests.")
<-cancel <-cancel
return nil return nil

View file

@ -22,6 +22,8 @@ import (
const ( const (
ConfigurationUnsuccessful = "Configuration reload has failed." 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. // Notification represents an individual notification message.