Skip to content

Commit

Permalink
Merge pull request prometheus#15082 from roidelapluie/notifystart
Browse files Browse the repository at this point in the history
Notify web UI when starting up and shutting down
  • Loading branch information
roidelapluie authored Oct 4, 2024
2 parents d98c374 + 21e0f83 commit 023146e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
11 changes: 7 additions & 4 deletions cmd/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ import (
"github.com/prometheus/prometheus/tsdb/wlog"
"github.com/prometheus/prometheus/util/documentcli"
"github.com/prometheus/prometheus/util/logging"
"github.com/prometheus/prometheus/util/notifications"
prom_runtime "github.com/prometheus/prometheus/util/runtime"
"github.com/prometheus/prometheus/web"
"github.com/prometheus/prometheus/web/api"
)

var (
Expand Down Expand Up @@ -500,9 +500,10 @@ func main() {

logger := promlog.New(&cfg.promlogConfig)

notifs := api.NewNotifications(cfg.maxNotificationsSubscribers, prometheus.DefaultRegisterer)
notifs := notifications.NewNotifications(cfg.maxNotificationsSubscribers, prometheus.DefaultRegisterer)
cfg.web.NotificationsSub = notifs.Sub
cfg.web.NotificationsGetter = notifs.Get
notifs.AddNotification(notifications.StartingUp)

if err := cfg.setFeatureListOptions(logger); err != nil {
fmt.Fprintln(os.Stderr, fmt.Errorf("Error parsing feature list: %w", err))
Expand Down Expand Up @@ -989,6 +990,7 @@ func main() {
func(err error) {
close(cancel)
webHandler.SetReady(web.Stopping)
notifs.AddNotification(notifications.ShuttingDown)
},
)
}
Expand Down Expand Up @@ -1089,10 +1091,10 @@ func main() {

callback := func(success bool) {
if success {
notifs.DeleteNotification(api.ConfigurationUnsuccessful)
notifs.DeleteNotification(notifications.ConfigurationUnsuccessful)
return
}
notifs.AddNotification(api.ConfigurationUnsuccessful)
notifs.AddNotification(notifications.ConfigurationUnsuccessful)
}

g.Add(
Expand Down Expand Up @@ -1174,6 +1176,7 @@ func main() {
reloadReady.Close()

webHandler.SetReady(web.Ready)
notifs.DeleteNotification(notifications.StartingUp)
level.Info(logger).Log("msg", "Server is ready to receive web requests.")
<-cancel
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package api
package notifications

import (
"sync"
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package api
package notifications

import (
"sync"
Expand Down
10 changes: 5 additions & 5 deletions web/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ import (
"github.com/prometheus/prometheus/tsdb/index"
"github.com/prometheus/prometheus/util/annotations"
"github.com/prometheus/prometheus/util/httputil"
"github.com/prometheus/prometheus/util/notifications"
"github.com/prometheus/prometheus/util/stats"
"github.com/prometheus/prometheus/web/api"
)

type status string
Expand Down Expand Up @@ -214,8 +214,8 @@ type API struct {
gatherer prometheus.Gatherer
isAgent bool
statsRenderer StatsRenderer
notificationsGetter func() []api.Notification
notificationsSub func() (<-chan api.Notification, func(), bool)
notificationsGetter func() []notifications.Notification
notificationsSub func() (<-chan notifications.Notification, func(), bool)

remoteWriteHandler http.Handler
remoteReadHandler http.Handler
Expand Down Expand Up @@ -249,8 +249,8 @@ func NewAPI(
corsOrigin *regexp.Regexp,
runtimeInfo func() (RuntimeInfo, error),
buildInfo *PrometheusVersion,
notificationsGetter func() []api.Notification,
notificationsSub func() (<-chan api.Notification, func(), bool),
notificationsGetter func() []notifications.Notification,
notificationsSub func() (<-chan notifications.Notification, func(), bool),
gatherer prometheus.Gatherer,
registerer prometheus.Registerer,
statsRenderer StatsRenderer,
Expand Down
6 changes: 3 additions & 3 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import (
"github.com/prometheus/prometheus/template"
"github.com/prometheus/prometheus/util/httputil"
"github.com/prometheus/prometheus/util/netconnlimit"
"github.com/prometheus/prometheus/web/api"
"github.com/prometheus/prometheus/util/notifications"
api_v1 "github.com/prometheus/prometheus/web/api/v1"
"github.com/prometheus/prometheus/web/ui"
)
Expand Down Expand Up @@ -267,8 +267,8 @@ type Options struct {
RuleManager *rules.Manager
Notifier *notifier.Manager
Version *PrometheusVersion
NotificationsGetter func() []api.Notification
NotificationsSub func() (<-chan api.Notification, func(), bool)
NotificationsGetter func() []notifications.Notification
NotificationsSub func() (<-chan notifications.Notification, func(), bool)
Flags map[string]string

ListenAddresses []string
Expand Down

0 comments on commit 023146e

Please sign in to comment.