-
Notifications
You must be signed in to change notification settings - Fork 102
Conversation
pkg/utils/dyn_pprof_unix.go
Outdated
@@ -17,16 +17,16 @@ const startPProfSignal = syscall.SIGUSR1 | |||
var signalChan = make(chan os.Signal, 1) | |||
|
|||
// StartDynamicPProfListener starts the listener that will enable pprof when received `startPProfSignal`. | |||
func StartDynamicPProfListener() { | |||
func StartDynamicPProfListener(start func(addr string)) { |
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.
Prefer pass arguments explicitly instead of a closure.
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.
This function is an internal function, I think if we pass arguments here, we probably need to provide TLS config explicitly here, like StartDynamicPProfListener(cert, key string)
. At the implementation might would be like:
if cert == "" || key == "" {
StartPProfListener("0.0.0.0:0")
} else {
StartPProfListener("0.0.0.0:0", cert, key)
}
We got more args, and function overloading-like magic... Without more information, I'm afraid I would prefer the current style...
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.
We can move the if condition into the StartPProfListener
.
func StartPProfListener(addr, cert, key string) error {
if cert == "" || key == "" {
} else {
}
}
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.
Yep, I think those would make a if
statement within the function, whose condition is the new parameter we added. And in my opinion this is also control coupling or another form of function overloading.
I think make another function(StartPProfListenerTLS
) and let user to decide how to start the pprof listener by callback in the StartDynamicPProfListener
would be more flexible.
I'm wondering if there are some style guides preferring plain arguments or some bad things happened with closures...? If so, I will surely remove those.
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
Why not, um, reuse the method from Lines 95 to 172 in 688c835
|
@kennytm Seems there is strong coupling between this method and lightning... I'm afraid reuse it needs more refactor... |
i mean using this to handle TLS instead of listener, err := net.Listen("tcp", statusAddr)
...
listener = l.globalTLS.WrapListener(listener)
go func() {
err := l.server.Serve(listener)
log.L().Info("stopped HTTP server", log.ShortError(err))
}() |
Well, I think I got it. |
LGTM |
/merge |
/run-all-tests |
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-4.0 in PR #839 |
Signed-off-by: ti-srebot <[email protected]> Co-authored-by: 山岚 <[email protected]> Co-authored-by: Neil Shen <[email protected]>
What problem does this PR solve?
Fixed #817
What is changed and how it works?
Get TLS config and apply it when starting proof.
Check List
Tests
Release Note