cmd/utils: renames flags related to http-rpc server (#20935)
* rpc flags related to starting http server renamed to http * old rpc flags aliased and still functional * pprof flags fixed * renames gpo related flags * linted * renamed rpc flags for consistency and clarity * added warn logs * added more warn logs for all deprecated flags for consistency * moves legacy flags to separate file, hides older flags under show-deprecated-flags command * legacy prefix and moved some more legacy flags to legacy file * fixed circular import * added docs * fixed imports lint error * added notes about when flags were deprecated * cmd/utils: group flags by deprecation date + reorder by date, * modified deprecated comments for consistency, added warn log for --rpc * making sure deprecated flags are still functional * show-deprecated-flags command cleaned up * fixed lint errors * corrected merge conflict * IsSet --> GlobalIsSet * uncategorized flags, if not deprecated, displayed under misc Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
@ -60,39 +60,68 @@ var (
|
||||
Usage: "Enable the pprof HTTP server",
|
||||
}
|
||||
pprofPortFlag = cli.IntFlag{
|
||||
Name: "pprofport",
|
||||
Name: "pprof.port",
|
||||
Usage: "pprof HTTP server listening port",
|
||||
Value: 6060,
|
||||
}
|
||||
pprofAddrFlag = cli.StringFlag{
|
||||
Name: "pprofaddr",
|
||||
Name: "pprof.addr",
|
||||
Usage: "pprof HTTP server listening interface",
|
||||
Value: "127.0.0.1",
|
||||
}
|
||||
memprofilerateFlag = cli.IntFlag{
|
||||
Name: "memprofilerate",
|
||||
Name: "pprof.memprofilerate",
|
||||
Usage: "Turn on memory profiling with the given rate",
|
||||
Value: runtime.MemProfileRate,
|
||||
}
|
||||
blockprofilerateFlag = cli.IntFlag{
|
||||
Name: "blockprofilerate",
|
||||
Name: "pprof.blockprofilerate",
|
||||
Usage: "Turn on block profiling with the given rate",
|
||||
}
|
||||
cpuprofileFlag = cli.StringFlag{
|
||||
Name: "cpuprofile",
|
||||
Name: "pprof.cpuprofile",
|
||||
Usage: "Write CPU profile to the given file",
|
||||
}
|
||||
traceFlag = cli.StringFlag{
|
||||
Name: "trace",
|
||||
Usage: "Write execution trace to the given file",
|
||||
}
|
||||
// (Deprecated April 2020)
|
||||
legacyPprofPortFlag = cli.IntFlag{
|
||||
Name: "pprofport",
|
||||
Usage: "pprof HTTP server listening port (deprecated, use --pprof.port)",
|
||||
Value: 6060,
|
||||
}
|
||||
legacyPprofAddrFlag = cli.StringFlag{
|
||||
Name: "pprofaddr",
|
||||
Usage: "pprof HTTP server listening interface (deprecated, use --pprof.addr)",
|
||||
Value: "127.0.0.1",
|
||||
}
|
||||
legacyMemprofilerateFlag = cli.IntFlag{
|
||||
Name: "memprofilerate",
|
||||
Usage: "Turn on memory profiling with the given rate (deprecated, use --pprof.memprofilerate)",
|
||||
Value: runtime.MemProfileRate,
|
||||
}
|
||||
legacyBlockprofilerateFlag = cli.IntFlag{
|
||||
Name: "blockprofilerate",
|
||||
Usage: "Turn on block profiling with the given rate (deprecated, use --pprof.blockprofilerate)",
|
||||
}
|
||||
legacyCpuprofileFlag = cli.StringFlag{
|
||||
Name: "cpuprofile",
|
||||
Usage: "Write CPU profile to the given file (deprecated, use --pprof.cpuprofile)",
|
||||
}
|
||||
)
|
||||
|
||||
// Flags holds all command-line flags required for debugging.
|
||||
var Flags = []cli.Flag{
|
||||
verbosityFlag, vmoduleFlag, backtraceAtFlag, debugFlag,
|
||||
pprofFlag, pprofAddrFlag, pprofPortFlag,
|
||||
memprofilerateFlag, blockprofilerateFlag, cpuprofileFlag, traceFlag,
|
||||
pprofFlag, pprofAddrFlag, pprofPortFlag, memprofilerateFlag,
|
||||
blockprofilerateFlag, cpuprofileFlag, traceFlag,
|
||||
}
|
||||
|
||||
var DeprecatedFlags = []cli.Flag{
|
||||
legacyPprofPortFlag, legacyPprofAddrFlag, legacyMemprofilerateFlag,
|
||||
legacyBlockprofilerateFlag, legacyCpuprofileFlag,
|
||||
}
|
||||
|
||||
var (
|
||||
@ -121,22 +150,51 @@ func Setup(ctx *cli.Context) error {
|
||||
log.Root().SetHandler(glogger)
|
||||
|
||||
// profiling, tracing
|
||||
if ctx.GlobalIsSet(legacyMemprofilerateFlag.Name) {
|
||||
runtime.MemProfileRate = ctx.GlobalInt(legacyMemprofilerateFlag.Name)
|
||||
log.Warn("The flag --memprofilerate is deprecated and will be removed in the future, please use --pprof.memprofilerate")
|
||||
}
|
||||
runtime.MemProfileRate = ctx.GlobalInt(memprofilerateFlag.Name)
|
||||
|
||||
if ctx.GlobalIsSet(legacyBlockprofilerateFlag.Name) {
|
||||
Handler.SetBlockProfileRate(ctx.GlobalInt(legacyBlockprofilerateFlag.Name))
|
||||
log.Warn("The flag --blockprofilerate is deprecated and will be removed in the future, please use --pprof.blockprofilerate")
|
||||
}
|
||||
Handler.SetBlockProfileRate(ctx.GlobalInt(blockprofilerateFlag.Name))
|
||||
|
||||
if traceFile := ctx.GlobalString(traceFlag.Name); traceFile != "" {
|
||||
if err := Handler.StartGoTrace(traceFile); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if cpuFile := ctx.GlobalString(cpuprofileFlag.Name); cpuFile != "" {
|
||||
if err := Handler.StartCPUProfile(cpuFile); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if cpuFile := ctx.GlobalString(legacyCpuprofileFlag.Name); cpuFile != "" {
|
||||
log.Warn("The flag --cpuprofile is deprecated and will be removed in the future, please use --pprof.cpuprofile")
|
||||
if err := Handler.StartCPUProfile(cpuFile); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// pprof server
|
||||
if ctx.GlobalBool(pprofFlag.Name) {
|
||||
address := fmt.Sprintf("%s:%d", ctx.GlobalString(pprofAddrFlag.Name), ctx.GlobalInt(pprofPortFlag.Name))
|
||||
listenHost := ctx.GlobalString(pprofAddrFlag.Name)
|
||||
if ctx.GlobalIsSet(legacyPprofAddrFlag.Name) && !ctx.GlobalIsSet(pprofAddrFlag.Name) {
|
||||
listenHost = ctx.GlobalString(legacyPprofAddrFlag.Name)
|
||||
log.Warn("The flag --pprofaddr is deprecated and will be removed in the future, please use --pprof.addr")
|
||||
}
|
||||
|
||||
port := ctx.GlobalInt(pprofPortFlag.Name)
|
||||
if ctx.GlobalIsSet(legacyPprofPortFlag.Name) && !ctx.GlobalIsSet(pprofPortFlag.Name) {
|
||||
port = ctx.GlobalInt(legacyPprofPortFlag.Name)
|
||||
log.Warn("The flag --pprofport is deprecated and will be removed in the future, please use --pprof.port")
|
||||
}
|
||||
|
||||
address := fmt.Sprintf("%s:%d", listenHost, port)
|
||||
StartPProf(address)
|
||||
}
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user