Move notifications in utils

Signed-off-by: Julien <roidelapluie@o11y.eu>
This commit is contained in:
Julien 2024-10-04 10:11:56 +02:00
parent b6158e8956
commit 21e0f83b68
5 changed files with 17 additions and 17 deletions

View file

@ -76,9 +76,9 @@ import (
"github.com/prometheus/prometheus/tsdb/wlog" "github.com/prometheus/prometheus/tsdb/wlog"
"github.com/prometheus/prometheus/util/documentcli" "github.com/prometheus/prometheus/util/documentcli"
"github.com/prometheus/prometheus/util/logging" "github.com/prometheus/prometheus/util/logging"
"github.com/prometheus/prometheus/util/notifications"
prom_runtime "github.com/prometheus/prometheus/util/runtime" prom_runtime "github.com/prometheus/prometheus/util/runtime"
"github.com/prometheus/prometheus/web" "github.com/prometheus/prometheus/web"
"github.com/prometheus/prometheus/web/api"
) )
var ( var (
@ -500,10 +500,10 @@ func main() {
logger := promlog.New(&cfg.promlogConfig) 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.NotificationsSub = notifs.Sub
cfg.web.NotificationsGetter = notifs.Get cfg.web.NotificationsGetter = notifs.Get
notifs.AddNotification(api.StartingUp) notifs.AddNotification(notifications.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))
@ -990,7 +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) notifs.AddNotification(notifications.ShuttingDown)
}, },
) )
} }
@ -1091,10 +1091,10 @@ func main() {
callback := func(success bool) { callback := func(success bool) {
if success { if success {
notifs.DeleteNotification(api.ConfigurationUnsuccessful) notifs.DeleteNotification(notifications.ConfigurationUnsuccessful)
return return
} }
notifs.AddNotification(api.ConfigurationUnsuccessful) notifs.AddNotification(notifications.ConfigurationUnsuccessful)
} }
g.Add( g.Add(
@ -1176,7 +1176,7 @@ func main() {
reloadReady.Close() reloadReady.Close()
webHandler.SetReady(web.Ready) webHandler.SetReady(web.Ready)
notifs.DeleteNotification(api.StartingUp) notifs.DeleteNotification(notifications.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

@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package api package notifications
import ( import (
"sync" "sync"

View file

@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package api package notifications
import ( import (
"sync" "sync"

View file

@ -54,8 +54,8 @@ import (
"github.com/prometheus/prometheus/tsdb/index" "github.com/prometheus/prometheus/tsdb/index"
"github.com/prometheus/prometheus/util/annotations" "github.com/prometheus/prometheus/util/annotations"
"github.com/prometheus/prometheus/util/httputil" "github.com/prometheus/prometheus/util/httputil"
"github.com/prometheus/prometheus/util/notifications"
"github.com/prometheus/prometheus/util/stats" "github.com/prometheus/prometheus/util/stats"
"github.com/prometheus/prometheus/web/api"
) )
type status string type status string
@ -214,8 +214,8 @@ type API struct {
gatherer prometheus.Gatherer gatherer prometheus.Gatherer
isAgent bool isAgent bool
statsRenderer StatsRenderer statsRenderer StatsRenderer
notificationsGetter func() []api.Notification notificationsGetter func() []notifications.Notification
notificationsSub func() (<-chan api.Notification, func(), bool) notificationsSub func() (<-chan notifications.Notification, func(), bool)
remoteWriteHandler http.Handler remoteWriteHandler http.Handler
remoteReadHandler http.Handler remoteReadHandler http.Handler
@ -249,8 +249,8 @@ func NewAPI(
corsOrigin *regexp.Regexp, corsOrigin *regexp.Regexp,
runtimeInfo func() (RuntimeInfo, error), runtimeInfo func() (RuntimeInfo, error),
buildInfo *PrometheusVersion, buildInfo *PrometheusVersion,
notificationsGetter func() []api.Notification, notificationsGetter func() []notifications.Notification,
notificationsSub func() (<-chan api.Notification, func(), bool), notificationsSub func() (<-chan notifications.Notification, func(), bool),
gatherer prometheus.Gatherer, gatherer prometheus.Gatherer,
registerer prometheus.Registerer, registerer prometheus.Registerer,
statsRenderer StatsRenderer, statsRenderer StatsRenderer,

View file

@ -59,7 +59,7 @@ import (
"github.com/prometheus/prometheus/template" "github.com/prometheus/prometheus/template"
"github.com/prometheus/prometheus/util/httputil" "github.com/prometheus/prometheus/util/httputil"
"github.com/prometheus/prometheus/util/netconnlimit" "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" api_v1 "github.com/prometheus/prometheus/web/api/v1"
"github.com/prometheus/prometheus/web/ui" "github.com/prometheus/prometheus/web/ui"
) )
@ -267,8 +267,8 @@ type Options struct {
RuleManager *rules.Manager RuleManager *rules.Manager
Notifier *notifier.Manager Notifier *notifier.Manager
Version *PrometheusVersion Version *PrometheusVersion
NotificationsGetter func() []api.Notification NotificationsGetter func() []notifications.Notification
NotificationsSub func() (<-chan api.Notification, func(), bool) NotificationsSub func() (<-chan notifications.Notification, func(), bool)
Flags map[string]string Flags map[string]string
ListenAddresses []string ListenAddresses []string