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
// other profiling behavior or information.
MetricsHTTPFlag = &cli.StringFlag{
Name: "metrics.addr",
Usage: "Enable stand-alone metrics HTTP server listening interface",
Value: metrics.DefaultConfig.HTTP,
Name: "metrics.addr",
Usage: `Enable stand-alone metrics HTTP server listening interface.`,
Category: flags.MetricsCategory,
}
MetricsPortFlag = &cli.IntFlag{
Name: "metrics.port",
Usage: "Metrics HTTP server listening port",
Name: "metrics.port",
Usage: `Metrics HTTP server listening port.
Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.`,
Value: metrics.DefaultConfig.Port,
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))
log.Info("Enabling stand-alone metrics HTTP endpoint", "address", 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))
}
}
}