cmd/utils: print warning when --metrics.port set without --metrics.addr (#26248)

This commit is contained in:
Felix Lange 2022-11-24 11:37:58 +01:00 committed by GitHub
parent 193f350eb9
commit 8846c07d04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -926,14 +926,14 @@ var (
// to enable a public-OK metrics endpoint without having to worry about ALSO exposing // to enable a public-OK metrics endpoint without having to worry about ALSO exposing
// other profiling behavior or information. // other profiling behavior or information.
MetricsHTTPFlag = &cli.StringFlag{ MetricsHTTPFlag = &cli.StringFlag{
Name: "metrics.addr", Name: "metrics.addr",
Usage: "Enable stand-alone metrics HTTP server listening interface", Usage: `Enable stand-alone metrics HTTP server listening interface.`,
Value: metrics.DefaultConfig.HTTP,
Category: flags.MetricsCategory, Category: flags.MetricsCategory,
} }
MetricsPortFlag = &cli.IntFlag{ MetricsPortFlag = &cli.IntFlag{
Name: "metrics.port", Name: "metrics.port",
Usage: "Metrics HTTP server listening port", Usage: `Metrics HTTP server listening port.
Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.`,
Value: metrics.DefaultConfig.Port, Value: metrics.DefaultConfig.Port,
Category: flags.MetricsCategory, Category: flags.MetricsCategory,
} }
@ -2150,6 +2150,8 @@ func SetupMetrics(ctx *cli.Context) {
address := fmt.Sprintf("%s:%d", ctx.String(MetricsHTTPFlag.Name), ctx.Int(MetricsPortFlag.Name)) address := fmt.Sprintf("%s:%d", ctx.String(MetricsHTTPFlag.Name), ctx.Int(MetricsPortFlag.Name))
log.Info("Enabling stand-alone metrics HTTP endpoint", "address", address) log.Info("Enabling stand-alone metrics HTTP endpoint", "address", address)
exp.Setup(address) exp.Setup(address)
} else if ctx.IsSet(MetricsPortFlag.Name) {
log.Warn(fmt.Sprintf("--%s specified without --%s, metrics server will not start.", MetricsPortFlag.Name, MetricsHTTPFlag.Name))
} }
} }
} }