-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run pprof (by default disabled) on a separate port than metrics #1758
Conversation
cmd/nitro/nitro.go
Outdated
@@ -122,6 +122,30 @@ func main() { | |||
os.Exit(mainImpl()) | |||
} | |||
|
|||
// Runs metrics server at address:port specified by config if metrics flag is | |||
// enabled. Additionally if pprof at specified pprof port when it's enabled. | |||
func mustRunMetrics(cfg *NodeConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this function called mustRunMetrics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MustXYZ is a convention in Go [0]. When helper stops the program (usually called from main) convention is to name it with mustXYZ.
[0] https://google.github.io/styleguide/go/decisions#must-functions
cmd/nitro/nitro.go
Outdated
log.Error("--metrics must be enabled in order to use pprof with the metrics server") | ||
return 1 | ||
} | ||
mustRunMetrics(nodeConfig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After opening the blockchain I don't think we want to use log.Crit
as it won't do a clean shutdown (it skips defers). One simple fix would be to move this call to before the openInitializeChainDb call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, moved it up.
cmd/genericconf/server.go
Outdated
UpdateInterval time.Duration `koanf:"update-interval"` | ||
} | ||
|
||
var MetricsServerConfigDefault = MetricsServerConfig{ | ||
Addr: "127.0.0.1", | ||
Port: 6070, | ||
Pprof: false, | ||
Pprof: true, | ||
PprofPort: 6071, | ||
UpdateInterval: 3 * time.Second, | ||
} | ||
|
||
func MetricsServerAddOptions(prefix string, f *flag.FlagSet) { | ||
f.String(prefix+".addr", MetricsServerConfigDefault.Addr, "metrics server address") | ||
f.Int(prefix+".port", MetricsServerConfigDefault.Port, "metrics server port") | ||
f.Bool(prefix+".pprof", MetricsServerConfigDefault.Pprof, "enable profiling for Go") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure which of these we should do, but we should either:
- Add a comment here explaining that pprof will only be exposed if metrics are enabled
- Make pprof independent of metrics, and have it default to disabled.
I think the latter approach is a bit better because metrics and pprof seem like separate features to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went with the second option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Introduce a flag for pprof port (default 6071), and enable pprof by default.
Default handler for pprof will be: "http://127.0.0.1:6071/debug/pprof/" which exposes stacktrace as well at "http://127.0.0.1:6071/debug/pprof/goroutine".
Leaving pprof flag itself to have ability to disable it, at we may consider dropping that after a while.