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

✨ Introduce pprof server to manager #1943

Merged
merged 1 commit into from Apr 12, 2023

Conversation

zqzten
Copy link
Member

@zqzten zqzten commented Jun 25, 2022

This PR introduces a configurable standalone server for serving pprof to manager, just like the health and metrics server.

fixes #1779

Additional thoughts:
I've been aware of metricsExtraHandlers introduced in #824 which might be an alternative for end users to serve pprof, but I don't think it's quite appropriate to do so, mainly for these two reasons:

  1. pprof is a language built-in feature which is widely used, so it's more appropriate to make its server built-in in the library rather than let end users construct and run themselves in every controller.
  2. metricsExtraHandlers bind all handlers to metrics listener which is not that general and flexible, it cannot meet cases that user want to expose metrics and pprof by different listeners (common use case: a 0.0.0.0: listener for serving metrics and a 127.0.0.1: listener for serving pprof).

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 25, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @zqzten. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot requested a review from droot June 25, 2022 08:46
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 25, 2022
@AlmogBaku
Copy link
Member

TBH, I'm against this one. This is very tempting to add functionality such as this to your solution, but enabling it on production might cause a sensitive information leakage.

I suggest adding a "hint" in your "DEVELOPMENT.MD" file as I did here:
https://github.com/natun-ai/natun/blob/master/CONTRIBUTING.md#profiling

@FillZpp
Copy link
Contributor

FillZpp commented Jul 1, 2022

This is very tempting to add functionality such as this to your solution, but enabling it on production might cause a sensitive information leakage.

That's true if we enable pprof and bind it to 0.0.0.0:<port> on production. But I think this PR is ok, since it just provides an option which is disabled by default and we can add doc comments to recommend ppl only bind it to localhost.

@zqzten
Copy link
Member Author

zqzten commented Jul 1, 2022

@AlmogBaku Thanks for the security remind, but I don't think it as a blocking issue as we have ways to protect it:

  • By binding its listener to 127.0.0.1:, as @FillZpp suggested, which is a very common and naive solution. This is also why seperated listener is introduced instead of reusing metricsExtraHandlers.
  • By protecting pprof server by kube-rbac-proxy, which is also the default solution to protect metrics server in kubebuilder. This is a sophisticated solution which is similarly used by kube-controller-manager (it does the rbac proxy by itself though).

Security is very important indeed, I'll add some doc comments on it, also we can put best practice usage in kubebuilder after this feature is added.

@FillZpp
Copy link
Contributor

FillZpp commented Jul 1, 2022

/ok-to-test

/cc @alvaroaleman

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 1, 2022
@AlmogBaku
Copy link
Member

what about adding a build tag as a solution?

@zqzten
Copy link
Member Author

zqzten commented Jul 2, 2022

what about adding a build tag as a solution?

I'm not sure whether this solution is appropriate in this project. Let's just wait for opinions from other maintainers.

@alvaroaleman
Copy link
Member

Kind of torn here. Not having pprof is extremely annoying in production, but it definitely exposes sensitive information.

@AlmogBaku what is the reason why you would prefer build tags over off-by-default, i.E. what is the problem you see from having it compiled in but disabled?

@AlmogBaku
Copy link
Member

AlmogBaku commented Jul 6, 2022

Exposing this setting using a build tag is like having a “remote debugger” - possible, but should be allowed implicitly and temporary on production mode

@alvaroaleman
Copy link
Member

Exposing this setting using a build tag is like having a “remote debugger” - possible, but should be allowed implicitly and temporary on production mode

I actually disagree with that. Pprof needs to always be enabled or it is useless. If it requires a binary restart of any kind it becomes impossible to debug in situations where there is no clear reproducer. The remaining concern here is that we can't tell if ppl properly wall off connectivity to their controllers, which is why it might be problematic to enable by default.

pkg/config/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/config/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/config/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/manager/internal.go Outdated Show resolved Hide resolved
pkg/manager/manager.go Outdated Show resolved Hide resolved
@zqzten zqzten force-pushed the pprof branch 4 times, most recently from a15d1eb to 833a6e6 Compare December 9, 2022 11:49
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 31, 2023
@zqzten
Copy link
Member Author

zqzten commented Mar 13, 2023

@alvaroaleman @vincepri @FillZpp Mind give some further points on this? It would be very appreciated. There're many ppl around calling for this feature.

@vincepri vincepri added this to the v0.15.x milestone Apr 12, 2023
Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 12, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vincepri, zqzten

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 12, 2023
@k8s-ci-robot k8s-ci-robot merged commit fbd6b94 into kubernetes-sigs:main Apr 12, 2023
2 checks passed
@fovgrubby128
Copy link

fovgrubby128 commented Apr 12, 2023

A dumb question here, it would be released in the next version, right?

@zqzten zqzten deleted the pprof branch April 13, 2023 02:54
@sbueringer
Copy link
Member

Yes, that's the plan

@fovgrubby128
Copy link

Yes, that's the plan

Could I know the next release date please since we want to introduce this change in our code for some deadline? thanks!

@sbueringer
Copy link
Member

sbueringer commented Apr 18, 2023

There is no fixed date as far as I know. But I think we want to get #2189 in first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request] Add support for pprof
9 participants