|
|
@ -44,6 +44,7 @@ import (
|
|
|
|
promlogflag "github.com/prometheus/common/promlog/flag"
|
|
|
|
promlogflag "github.com/prometheus/common/promlog/flag"
|
|
|
|
"github.com/prometheus/prometheus/config"
|
|
|
|
"github.com/prometheus/prometheus/config"
|
|
|
|
"github.com/prometheus/prometheus/discovery"
|
|
|
|
"github.com/prometheus/prometheus/discovery"
|
|
|
|
|
|
|
|
sd_config "github.com/prometheus/prometheus/discovery/config"
|
|
|
|
"github.com/prometheus/prometheus/notifier"
|
|
|
|
"github.com/prometheus/prometheus/notifier"
|
|
|
|
"github.com/prometheus/prometheus/promql"
|
|
|
|
"github.com/prometheus/prometheus/promql"
|
|
|
|
"github.com/prometheus/prometheus/retrieval"
|
|
|
|
"github.com/prometheus/prometheus/retrieval"
|
|
|
@ -234,11 +235,12 @@ func main() {
|
|
|
|
ctxWeb, cancelWeb = context.WithCancel(context.Background())
|
|
|
|
ctxWeb, cancelWeb = context.WithCancel(context.Background())
|
|
|
|
ctxRule = context.Background()
|
|
|
|
ctxRule = context.Background()
|
|
|
|
|
|
|
|
|
|
|
|
notifier = notifier.New(&cfg.notifier, log.With(logger, "component", "notifier"))
|
|
|
|
notifier = notifier.New(&cfg.notifier, log.With(logger, "component", "notifier"))
|
|
|
|
discoveryManager = discovery.NewManager(log.With(logger, "component", "discovery manager"))
|
|
|
|
discoveryManagerScrape = discovery.NewManager(log.With(logger, "component", "discovery manager scrape"))
|
|
|
|
scrapeManager = retrieval.NewScrapeManager(log.With(logger, "component", "scrape manager"), fanoutStorage)
|
|
|
|
discoveryManagerNotify = discovery.NewManager(log.With(logger, "component", "discovery manager notify"))
|
|
|
|
queryEngine = promql.NewEngine(fanoutStorage, &cfg.queryEngine)
|
|
|
|
scrapeManager = retrieval.NewScrapeManager(log.With(logger, "component", "scrape manager"), fanoutStorage)
|
|
|
|
ruleManager = rules.NewManager(&rules.ManagerOptions{
|
|
|
|
queryEngine = promql.NewEngine(fanoutStorage, &cfg.queryEngine)
|
|
|
|
|
|
|
|
ruleManager = rules.NewManager(&rules.ManagerOptions{
|
|
|
|
Appendable: fanoutStorage,
|
|
|
|
Appendable: fanoutStorage,
|
|
|
|
QueryFunc: rules.EngineQueryFunc(queryEngine),
|
|
|
|
QueryFunc: rules.EngineQueryFunc(queryEngine),
|
|
|
|
NotifyFunc: sendAlerts(notifier, cfg.web.ExternalURL.String()),
|
|
|
|
NotifyFunc: sendAlerts(notifier, cfg.web.ExternalURL.String()),
|
|
|
@ -283,7 +285,21 @@ func main() {
|
|
|
|
remoteStorage.ApplyConfig,
|
|
|
|
remoteStorage.ApplyConfig,
|
|
|
|
webHandler.ApplyConfig,
|
|
|
|
webHandler.ApplyConfig,
|
|
|
|
notifier.ApplyConfig,
|
|
|
|
notifier.ApplyConfig,
|
|
|
|
discoveryManager.ApplyConfig,
|
|
|
|
func(cfg *config.Config) error {
|
|
|
|
|
|
|
|
c := make(map[string]sd_config.ServiceDiscoveryConfig)
|
|
|
|
|
|
|
|
for _, v := range cfg.ScrapeConfigs {
|
|
|
|
|
|
|
|
c[v.JobName] = v.ServiceDiscoveryConfig
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return discoveryManagerScrape.ApplyConfig(c)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
func(cfg *config.Config) error {
|
|
|
|
|
|
|
|
c := make(map[string]sd_config.ServiceDiscoveryConfig)
|
|
|
|
|
|
|
|
for _, v := range cfg.AlertingConfig.AlertmanagerConfigs {
|
|
|
|
|
|
|
|
// AlertmanagerConfigs doesn't hold an unique identifier so we use the config pointer as the identifier.
|
|
|
|
|
|
|
|
c[fmt.Sprintf("%p", v)] = v.ServiceDiscoveryConfig
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return discoveryManagerNotify.ApplyConfig(c)
|
|
|
|
|
|
|
|
},
|
|
|
|
scrapeManager.ApplyConfig,
|
|
|
|
scrapeManager.ApplyConfig,
|
|
|
|
func(cfg *config.Config) error {
|
|
|
|
func(cfg *config.Config) error {
|
|
|
|
// Get all rule files matching the configuration oaths.
|
|
|
|
// Get all rule files matching the configuration oaths.
|
|
|
@ -332,23 +348,37 @@ func main() {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ctxDiscovery, cancelDiscovery := context.WithCancel(context.Background())
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
|
|
|
g.Add(
|
|
|
|
|
|
|
|
func() error {
|
|
|
|
|
|
|
|
err := discoveryManagerScrape.Run(ctx)
|
|
|
|
|
|
|
|
level.Info(logger).Log("msg", "Scrape discovery manager stopped")
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
func(err error) {
|
|
|
|
|
|
|
|
level.Info(logger).Log("msg", "Stopping scrape discovery manager...")
|
|
|
|
|
|
|
|
cancel()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
g.Add(
|
|
|
|
g.Add(
|
|
|
|
func() error {
|
|
|
|
func() error {
|
|
|
|
err := discoveryManager.Run(ctxDiscovery)
|
|
|
|
err := discoveryManagerNotify.Run(ctx)
|
|
|
|
level.Info(logger).Log("msg", "Discovery manager stopped")
|
|
|
|
level.Info(logger).Log("msg", "Notify discovery manager stopped")
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
},
|
|
|
|
},
|
|
|
|
func(err error) {
|
|
|
|
func(err error) {
|
|
|
|
level.Info(logger).Log("msg", "Stopping discovery manager...")
|
|
|
|
level.Info(logger).Log("msg", "Stopping notify discovery manager...")
|
|
|
|
cancelDiscovery()
|
|
|
|
cancel()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
{
|
|
|
|
g.Add(
|
|
|
|
g.Add(
|
|
|
|
func() error {
|
|
|
|
func() error {
|
|
|
|
err := scrapeManager.Run(discoveryManager.SyncCh())
|
|
|
|
err := scrapeManager.Run(discoveryManagerScrape.SyncCh())
|
|
|
|
level.Info(logger).Log("msg", "Scrape manager stopped")
|
|
|
|
level.Info(logger).Log("msg", "Scrape manager stopped")
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -493,7 +523,7 @@ func main() {
|
|
|
|
// so keep this interrupt after the ruleManager.Stop().
|
|
|
|
// so keep this interrupt after the ruleManager.Stop().
|
|
|
|
g.Add(
|
|
|
|
g.Add(
|
|
|
|
func() error {
|
|
|
|
func() error {
|
|
|
|
notifier.Run()
|
|
|
|
notifier.Run(discoveryManagerNotify.SyncCh())
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
func(err error) {
|
|
|
|
func(err error) {
|
|
|
|