lib/pushmetrics: properly handle errors when initializing pushmetrics

This commit is contained in:
Aliaksandr Valialkin 2022-07-22 13:35:58 +03:00
parent 4c2f9a1a2e
commit ad6b3cd47d
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
7 changed files with 13 additions and 8 deletions

View file

@ -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

View file

@ -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 {

View file

@ -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)

View file

@ -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()

View file

@ -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 {

View file

@ -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)

View file

@ -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)
}
}
}