From ad6b3cd47db36d4a5d0990f74b5e6bafd9cee8ac Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 22 Jul 2022 13:35:58 +0300 Subject: [PATCH] lib/pushmetrics: properly handle errors when initializing pushmetrics --- app/victoria-metrics/main.go | 2 +- app/vmagent/main.go | 2 +- app/vmalert/main.go | 3 ++- app/vmauth/main.go | 3 ++- app/vmbackup/main.go | 2 +- app/vmrestore/main.go | 2 +- lib/pushmetrics/pushmetrics.go | 7 +++++-- 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/victoria-metrics/main.go b/app/victoria-metrics/main.go index 37161d2ee..16fc87405 100644 --- a/app/victoria-metrics/main.go +++ b/app/victoria-metrics/main.go @@ -36,9 +36,9 @@ func main() { flag.CommandLine.SetOutput(os.Stdout) flag.Usage = usage envflag.Parse() - pushmetrics.Init() buildinfo.Init() logger.Init() + pushmetrics.Init() if promscrape.IsDryRun() { *dryRun = true diff --git a/app/vmagent/main.go b/app/vmagent/main.go index d44d1b716..be34a3096 100644 --- a/app/vmagent/main.go +++ b/app/vmagent/main.go @@ -77,10 +77,10 @@ func main() { flag.CommandLine.SetOutput(os.Stdout) flag.Usage = usage envflag.Parse() - pushmetrics.Init() remotewrite.InitSecretFlags() buildinfo.Init() logger.Init() + pushmetrics.Init() if promscrape.IsDryRun() { if err := promscrape.CheckConfig(); err != nil { diff --git a/app/vmalert/main.go b/app/vmalert/main.go index 35bbac02f..ed05e1971 100644 --- a/app/vmalert/main.go +++ b/app/vmalert/main.go @@ -80,9 +80,10 @@ func main() { flag.CommandLine.SetOutput(os.Stdout) flag.Usage = usage envflag.Parse() - pushmetrics.Init() buildinfo.Init() logger.Init() + pushmetrics.Init() + err := templates.Load(*ruleTemplatesPath, true) if err != nil { logger.Fatalf("failed to parse %q: %s", *ruleTemplatesPath, err) diff --git a/app/vmauth/main.go b/app/vmauth/main.go index 684161800..c05ff441d 100644 --- a/app/vmauth/main.go +++ b/app/vmauth/main.go @@ -34,9 +34,10 @@ func main() { flag.CommandLine.SetOutput(os.Stdout) flag.Usage = usage envflag.Parse() - pushmetrics.Init() buildinfo.Init() logger.Init() + pushmetrics.Init() + logger.Infof("starting vmauth at %q...", *httpListenAddr) startTime := time.Now() initAuthConfig() diff --git a/app/vmbackup/main.go b/app/vmbackup/main.go index 7280b76a3..bda03ee64 100644 --- a/app/vmbackup/main.go +++ b/app/vmbackup/main.go @@ -42,9 +42,9 @@ func main() { flag.CommandLine.SetOutput(os.Stdout) flag.Usage = usage envflag.Parse() - pushmetrics.Init() buildinfo.Init() logger.Init() + pushmetrics.Init() if len(*snapshotCreateURL) > 0 { if len(*snapshotName) > 0 { diff --git a/app/vmrestore/main.go b/app/vmrestore/main.go index 295229648..a45989c9b 100644 --- a/app/vmrestore/main.go +++ b/app/vmrestore/main.go @@ -34,9 +34,9 @@ func main() { flag.CommandLine.SetOutput(os.Stdout) flag.Usage = usage envflag.Parse() - pushmetrics.Init() buildinfo.Init() logger.Init() + pushmetrics.Init() go httpserver.Serve(*httpListenAddr, nil) diff --git a/lib/pushmetrics/pushmetrics.go b/lib/pushmetrics/pushmetrics.go index 407d4e9d4..6150d843f 100644 --- a/lib/pushmetrics/pushmetrics.go +++ b/lib/pushmetrics/pushmetrics.go @@ -7,6 +7,7 @@ import ( "github.com/VictoriaMetrics/VictoriaMetrics/lib/appmetrics" "github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil" + "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" "github.com/VictoriaMetrics/metrics" ) @@ -23,10 +24,12 @@ func init() { flagutil.RegisterSecretFlag("pushmetrics.url") } -// Init must be called after flag.Parse. +// Init must be called after logger.Init func Init() { extraLabels := strings.Join(*pushExtraLabels, ",") for _, pu := range *pushURL { - _ = metrics.InitPushExt(pu, *pushInterval, extraLabels, appmetrics.WritePrometheusMetrics) + if err := metrics.InitPushExt(pu, *pushInterval, extraLabels, appmetrics.WritePrometheusMetrics); err != nil { + logger.Fatalf("cannot initialize pushmetrics: %s", err) + } } }