app/vmagent: log fatal errors instead of panics when improper command-line flags are passed to vmagent

This commit is contained in:
Aliaksandr Valialkin 2020-05-30 14:22:38 +03:00
parent f41a01332a
commit a646131a33

View File

@ -69,7 +69,7 @@ func newClient(argIdx int, remoteWriteURL, urlLabelValue string, fq *persistentq
token := bearerToken.GetOptionalArg(argIdx) token := bearerToken.GetOptionalArg(argIdx)
if len(token) > 0 { if len(token) > 0 {
if authHeader != "" { if authHeader != "" {
logger.Panicf("FATAL: `-remoteWrite.bearerToken`=%q cannot be set when `-remoteWrite.basicAuth.*` flags are set", token) logger.Fatalf("`-remoteWrite.bearerToken`=%q cannot be set when `-remoteWrite.basicAuth.*` flags are set", token)
} }
authHeader = "Bearer " + token authHeader = "Bearer " + token
} }
@ -85,11 +85,11 @@ func newClient(argIdx int, remoteWriteURL, urlLabelValue string, fq *persistentq
switch scheme { switch scheme {
case "http", "https": case "http", "https":
default: default:
logger.Panicf("FATAL: unsupported scheme in -remoteWrite.url=%q: %q. It must be http or https", remoteWriteURL, scheme) logger.Fatalf("unsupported scheme in -remoteWrite.url=%q: %q. It must be http or https", remoteWriteURL, scheme)
} }
host := string(u.Host()) host := string(u.Host())
if len(host) == 0 { if len(host) == 0 {
logger.Panicf("FATAL: invalid -remoteWrite.url=%q: host cannot be empty. Make sure the url looks like `http://host:port/path`", remoteWriteURL) logger.Fatalf("invalid -remoteWrite.url=%q: host cannot be empty. Make sure the url looks like `http://host:port/path`", remoteWriteURL)
} }
requestURI := string(u.RequestURI()) requestURI := string(u.RequestURI())
isTLS := scheme == "https" isTLS := scheme == "https"