-
Notifications
You must be signed in to change notification settings - Fork 446
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
Changes from 1 commit
3eb0340
c001949
741a9c8
77ad191
38f9b32
836c52d
42d7842
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 |
||
if !cfg.Metrics { | ||
if cfg.MetricsServer.Pprof { | ||
log.Warn("Metrics must be enabled in order to use pprof with the metrics server") | ||
} | ||
log.Debug("Metrics are disabled") | ||
return | ||
} | ||
if cfg.MetricsServer.Addr == "" { | ||
log.Crit("Metrics are enabled but server address is not specified") | ||
} | ||
go metrics.CollectProcessMetrics(cfg.MetricsServer.UpdateInterval) | ||
|
||
if cfg.MetricsServer.Pprof { | ||
if cfg.MetricsServer.Port == cfg.MetricsServer.PprofPort { | ||
log.Crit("Cannot use same port for metrics and pprof servers", "port", cfg.MetricsServer.Port) | ||
} | ||
genericconf.StartPprof(fmt.Sprintf("%v:%v", cfg.MetricsServer.Addr, cfg.MetricsServer.PprofPort)) | ||
} | ||
exp.Setup(fmt.Sprintf("%v:%v", cfg.MetricsServer.Addr, cfg.MetricsServer.Port)) | ||
} | ||
|
||
// Returns the exit code | ||
func mainImpl() int { | ||
ctx, cancelFunc := context.WithCancel(context.Background()) | ||
|
@@ -379,22 +403,7 @@ func mainImpl() int { | |
return 1 | ||
} | ||
|
||
if nodeConfig.Metrics { | ||
go metrics.CollectProcessMetrics(nodeConfig.MetricsServer.UpdateInterval) | ||
|
||
if nodeConfig.MetricsServer.Addr != "" { | ||
address := fmt.Sprintf("%v:%v", nodeConfig.MetricsServer.Addr, nodeConfig.MetricsServer.Port) | ||
if nodeConfig.MetricsServer.Pprof { | ||
genericconf.StartPprof(address) | ||
} else { | ||
exp.Setup(address) | ||
} | ||
} | ||
} else if nodeConfig.MetricsServer.Pprof { | ||
flag.Usage() | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. After opening the blockchain I don't think we want to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, moved it up. |
||
|
||
fatalErrChan := make(chan error, 10) | ||
|
||
|
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:
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.