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

Add pprof server to moco-controller #500

Merged
merged 2 commits into from
Feb 3, 2023
Merged

Add pprof server to moco-controller #500

merged 2 commits into from
Feb 3, 2023

Conversation

masa213f
Copy link
Contributor

@masa213f masa213f commented Jan 27, 2023

Add pprof server to moco-controller.
The pprof server will start only when --pprof-addr option is set.

Note
We can remove the pprof.Handler added in this PR after merging the following PR into the controller runtime.
kubernetes-sigs/controller-runtime#1943

Usage: View the trace data

  1. Deploy the moco-controller with --pprof-addr=:9090 option.
  2. Get trace data and run the trace viewer.
    # Get trace data
    $ kubectl port-forward -n moco-system POD_NAME  9090:9090 &
    $ curl -s http://localhost:9090/debug/pprof/trace?seconds=10 > trace.out
    
    # Run trace viewer
    $ go tool trace -http="localhost:9091" trace.out 
  3. Open http://localhost:9091 with a Web brower.

Signed-off-by: Masayuki Ishii masa213f@gmail.com

@masa213f masa213f self-assigned this Jan 27, 2023
@masa213f masa213f changed the title Add pprof handler Add pprof server to moco-controller Jan 27, 2023
Signed-off-by: Masayuki Ishii <masa213f@gmail.com>
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)

server := &http.Server{Addr: h.bindAddr, Handler: mux}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't use cybozu-go/well to keep the log format consistent with the reconciler.
For this usage, the default http server is enough, in my opinion.

Copy link
Member

Choose a reason for hiding this comment

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

I agree. 👍

@masa213f masa213f marked this pull request as ready for review February 2, 2023 09:04
@@ -136,6 +137,13 @@ func subMain(ns, addr string, port int) error {
return err
}

if config.pprofAddr != "" {
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to disable pprof even when 0 is specified.
This is because it will be incompatible when using controller-runtime's pprof in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's good. Fixed. 6cf0e1c

Signed-off-by: Masayuki Ishii <masa213f@gmail.com>
Copy link
Contributor

@kmdkuk kmdkuk left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@zoetrope zoetrope left a comment

Choose a reason for hiding this comment

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

LGTM

@masa213f masa213f merged commit 0b64a72 into main Feb 3, 2023
@masa213f masa213f deleted the pprof branch February 3, 2023 07:02
@masa213f masa213f mentioned this pull request May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants