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 support to disable /debug/pprof and /debug/flags/v endpoint #98458

Merged
merged 2 commits into from Feb 16, 2021

Conversation

SaranBalaji90
Copy link
Contributor

Co-authored-by: xiaofei.sun sunxiaofei@kuaishou.com
Co-authored-by: SaranBalaji90 srisaranbalaji@gmail.com

What type of PR is this?
/kind feature

What this PR does / why we need it:
This PR adds "EnableProfilingHandler" and "EnableDebugFlagsHandler" flag to kubelet configuration similar to "EnableSystemLogHandler". Based on the value of EnableProfilingHandler, /debug/pprof endpoint will be made available in kubelet and similarly based on "EnableDebugFlagsHandler", /debug/flags will be enabled . Default value for these flag is true.

Special notes for your reviewer:
This change is similar to #87273

Special credit to xiaoanyunfei@ for the initial commit.

Which issue(s) this PR fixes:
Fixes #84165

Does this PR introduce a user-facing change?:

Cluster admins can now turn off /debug/pprof and /debug/flags/v endpoint in kubelet by setting enableProfilingHandler and enableDebugFlagsHandler to false in their kubelet configuration file. enableProfilingHandler and enableDebugFlagsHandler can be set to true only when enableDebuggingHandlers is also set to true.

/sig node

Testing result:

Updated /etc/kubernetes/kubelet/kubelet-config.json with the following values

  "enableDebuggingHandlers": true,
  "enableSystemLogHandler": false,
  "enableDebugFlagsHandler": false,
  "enableProfilingHandler": false,
[ec2-user@ip-192-168-30-66 ~]$ curl -k https://localhost:10250/debug/pprof/symbol
profiling endpoint is disabled.
[ec2-user@ip-192-168-30-66 ~]$ curl -k https://localhost:10250/logs/
logs endpoint is disabled.
[ec2-user@ip-192-168-30-66 ~]$ curl -X PUT -k https://localhost:10250/debug/flags/v -d "2"
flags endpoint is disabled

After updating the values to true again

[ec2-user@ip-192-168-30-66 ~]$ curl -k https://localhost:10250/debug/pprof/symbol
num_symbols: 1
[ec2-user@ip-192-168-30-66 ~]$ curl -k https://localhost:10250/logs/
<pre>
<a href="alternatives.log">alternatives.log</a>
<a href="audit/">audit/</a>

/sig node
/area kubelet
/assign @derekwaynecarr
/assign @dchen1107

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. sig/node Categorizes an issue or PR as relevant to SIG Node. area/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API labels Jan 27, 2021
@SaranBalaji90 SaranBalaji90 force-pushed the profiling branch 2 times, most recently from c38c93d to 14d5a9a Compare January 27, 2021 05:25
@fejta-bot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

@SaranBalaji90 SaranBalaji90 force-pushed the profiling branch 3 times, most recently from a880668 to e109cd3 Compare January 27, 2021 15:56
@SaranBalaji90
Copy link
Contributor Author

Second commit is mostly to improve readability and make future enhancements easier - a880668

@SaranBalaji90 SaranBalaji90 force-pushed the profiling branch 2 times, most recently from c6cdc99 to 3944e1d Compare January 27, 2021 17:09
@ehashman ehashman added this to Triage in SIG Node PR Triage Jan 27, 2021
@ehashman
Copy link
Member

/triage accepted
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jan 29, 2021
@ehashman
Copy link
Member

/retest

@lavalamp
Copy link
Member

lavalamp commented Feb 9, 2021

Release note claims:

Cluster admins can now turn off /debug/pprof and /debug/flags/v endpoint in kubelet by setting enableProfilingHandler and enableDebugFlagsHandler to false in their kubelet configuration file. enableProfilingHandler and enableDebugFlagsHandler can be set to true only when enableDebuggingHandlers is also set to true.

However I don't see any code enforcing that. Maybe the implementation happens to work this way but it's not easy at all to verify. Apart from this the api is fine. I think it's important that these things don't suddenly turn on for people who have them off currently.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 9, 2021
@ehashman ehashman moved this from Needs Approver to Waiting on Author in SIG Node PR Triage Feb 9, 2021
@SaranBalaji90
Copy link
Contributor Author

Release note claims:

Cluster admins can now turn off /debug/pprof and /debug/flags/v endpoint in kubelet by setting enableProfilingHandler and enableDebugFlagsHandler to false in their kubelet configuration file. enableProfilingHandler and enableDebugFlagsHandler can be set to true only when enableDebuggingHandlers is also set to true.

However I don't see any code enforcing that. Maybe the implementation happens to work this way but it's not easy at all to verify. Apart from this the api is fine. I think it's important that these things don't suddenly turn on for people who have them off currently.

Thank you for reviewing the PR @lavalamp :)

We are using enableDebuggingHandlers as the parent knob to turn on/off all the sub handlers like /logs or /pprof and other handlers. If at present if admin has enableDebuggingHandlers set to false then it wont turn on these handlers. Like you mentioned we decided this route earlier just to avoid turning on the feature accidentally and also to make it backward compatible.

we enforce that here - https://github.com/kubernetes/kubernetes/pull/98458/files#diff-c3e7f724d1b0dcee40df80716ed57d90d2649710150fa92bf9822bdad35e0429R239 enableDebuggingHandlers should be set to true to enable/disable other child handlers.

@lavalamp
Copy link
Member

lavalamp commented Feb 9, 2021

we enforce that here

I guess I'm not sure why you install a "not turned on" handler if it is off? I think it would be easier to audit if the section of code you linked me to was just if statements.

I also don't really like that this is so inconsistent with how apiserver handles this, but I don't know that anything can be done about that.

Anyway, kubelet is not my binary so I don't really have a strong opinion, if you all are certain enough then that's fine.

For the API:
/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 9, 2021
@SaranBalaji90
Copy link
Contributor Author

I guess I'm not sure why you install a "not turned on" handler if it is off? I think it would be easier to audit if the section of code you linked me to was just if statements.

If its off, Kubelet just return messages like "logs(profiling) endpoint is disabled."

@SaranBalaji90
Copy link
Contributor Author

SaranBalaji90 commented Feb 9, 2021

I also don't really like that this is so inconsistent with how apiserver handles this, but I don't know that anything can be done about that.

@lavalamp is it due to the fact that single --profiling cmd line argument takes care of turning off /debug/pprof and /debug/flags/v endpoints in ApiServer but we are turning off in Kubelet with two different flags? (our thought process is documented here for reference #84165 (comment)) or is it in general how Kubelet handles these handlers.

Co-authored-by: xiaofei.sun <sunxiaofei@kuaishou.com>
Co-authored-by: SaranBalaji90 <srisaranbalaji@gmail.com>
@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Feb 12, 2021
@lavalamp
Copy link
Member

I guess I'm not sure why you install a "not turned on" handler if it is off? I think it would be easier to audit if the section of code you linked me to was just if statements.

If its off, Kubelet just return messages like "logs(profiling) endpoint is disabled."

Yes, I understood, I just am not sure why that's desirable.

@SaranBalaji90
Copy link
Contributor Author

I guess I'm not sure why you install a "not turned on" handler if it is off? I think it would be easier to audit if the section of code you linked me to was just if statements.

If its off, Kubelet just return messages like "logs(profiling) endpoint is disabled."

Yes, I understood, I just am not sure why that's desirable.

Ah ok.. I can remove if we don't need to return anything.. I added with assumption that it provides better wording(UX) when disabled.

@ehashman
Copy link
Member

From what I can see the latest update has changed quite a bit from the last... @sjenning can you PTAL?

@SaranBalaji90
Copy link
Contributor Author

SaranBalaji90 commented Feb 12, 2021

actually @ehashman I didn't make any change though between 3944e1d and 51c5401 but for some reason robot reported - "New changes are detected"

@lavalamp
Copy link
Member

I added with assumption that it provides better wording(UX) when disabled.

It's up to the Kubelet owners. :)

@ehashman
Copy link
Member

actually @ehashman I didn't make any change though between 3944e1d and 51c5401 but for some reason robot reported - "New changes are detected"

When I tried to diff the branches the diff numbers didn't match... I didn't do the initial review but I am not the right person to LGTM this :)

@SaranBalaji90
Copy link
Contributor Author

actually @ehashman I didn't make any change though between 3944e1d and 51c5401 but for some reason robot reported - "New changes are detected"

When I tried to diff the branches the diff numbers didn't match... I didn't do the initial review but I am not the right person to LGTM this :)

looks like there was some log format changes in master which was missed after rebase. Fixed it now :)

@kikisdeliveryservice kikisdeliveryservice moved this from Waiting on Author to Needs Reviewer in SIG Node PR Triage Feb 12, 2021
@liggitt liggitt added this to API review completed, 1.20 in API Reviews Feb 16, 2021
@derekwaynecarr
Copy link
Member

/approve
/lgtm

@andrewsykim maybe you can help restructure this in a follow-on to make the code path clearer per @lavalamp comments as part of overall /pkg/kubelet/server cleanup?

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: derekwaynecarr, dims, lavalamp, SaranBalaji90, sjenning

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 merged commit d0a433f into kubernetes:master Feb 16, 2021
SIG Node PR Triage automation moved this from Needs Reviewer to Done Feb 16, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.21 milestone Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review Categorizes an issue or PR as actively needing an API review. approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubelet cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/node Categorizes an issue or PR as relevant to SIG Node. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: API review completed, 1.20
Development

Successfully merging this pull request may close these issues.

Add --profiling flag to kubelet
10 participants