Skip to content
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

Merged
merged 7 commits into from
Jul 17, 2023

Conversation

anodar
Copy link
Contributor

@anodar anodar commented Jul 13, 2023

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.

@cla-bot cla-bot bot added the s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA. label Jul 13, 2023
@@ -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) {
Copy link
Collaborator

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?

Copy link
Contributor Author

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

log.Error("--metrics must be enabled in order to use pprof with the metrics server")
return 1
}
mustRunMetrics(nodeConfig)
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

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")
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@anodar anodar requested a review from PlasmaPower July 13, 2023 18:14
@anodar anodar enabled auto-merge July 14, 2023 10:32
Copy link
Member

@Tristan-Wilson Tristan-Wilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@anodar anodar merged commit 82ec72f into master Jul 17, 2023
7 checks passed
@PlasmaPower PlasmaPower deleted the pprof-metrics branch July 24, 2023 20:25
@joshuacolvin0 joshuacolvin0 changed the title Run pprof (by default enabled) on a separate port than metrics Run pprof (by default disabled) on a separate port than metrics Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants