Skip to content

Conversation

@dlespiau
Copy link
Contributor

@dlespiau dlespiau commented Sep 14, 2018

This commit adds two new global options to kubectl: --profile and
--profile-output, writing out go profiles to disk to debug interesting and
unexpected kubectl behaviour.

As an example, here is how to capture a block file, eg. for how long are we
blocked on I/O and where?

$ kubectl get nodes --profile=block -v6
$ go tool pprof -png ./profile.pprof > out.png
$ google-chrome out.png

What this PR does / why we need it:

This instrumentation is useful to debug abnormal kubectl behaviour or do performance work.

Fixes: #68679

kubectl has gained new --profile and --profile-output options to output go profiles

As an example here's a block profile for the kubectl get nodes command above, rebuilding its cache. The api server isn't local.

screenshot from 2018-09-14 16-29-33

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 14, 2018
@bboreham
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 14, 2018
@neolit123
Copy link
Member

/kind feature
up to the maintainers.

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Sep 15, 2018
@dlespiau
Copy link
Contributor Author

dlespiau commented Sep 17, 2018

/retest

The pull-kubernetes-e2e-kops-aws failure seems like a flake.
The pull-kubernetes-verify test is still using the previous version of the PR:

I0914 16:31:40.316] Args: --job=pull-kubernetes-verify --service-account=/etc/service-account/service-account.json --upload=gs://kubernetes-jenkins/logs --job=pull-kubernetes-verify --repo=k8s.io/kubernetes=master:94e59f1636a8f8b1566ef35180519d4de5586b79,68681:8653e09382d6becd8a72d0bc06a47e7020008a2b --service-account=/etc/service-account/service-account.json --upload=gs://kubernetes-jenkins/pr-logs --timeout=75 --scenario=kubernetes_verify -- '--branch=${PULL_BASE_REF}' --script=./hack/jenkins/verify-dockerized.sh

8653e09382d6becd8a72d0bc06a47e7020008a2b is the previous commit. Hoping /retest will do the right thing.

Edit: The bot edited the previous comment removing the pull-kubernetes-verify failure!
Edit2: Ah, now I get it, the ci bot only keep one comment with the latest test results, oops!
Edit3: All good!

Copy link
Member

@apelisse apelisse left a comment

Choose a reason for hiding this comment

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

Looks good to me, it should either fail or default if no profile is specified though

Copy link
Member

Choose a reason for hiding this comment

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

What's the goal of this profile? Does it do something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just a map lookup to check if profileName is the name of an existing profile, validating the input parameter.

Given it prompted a question, it's definitely worth a comment, added it!

@dlespiau
Copy link
Contributor Author

If no profile is specified, profileName is "" and those functions do nothing, which is the intended behaviour. If profileName is non zero, the profile name is validated by initProfiling to make sure it's the name of a valid profile and fails if it isn't. I think we're covered then.

@dims
Copy link
Member

dims commented Sep 18, 2018

/uncc

@k8s-ci-robot k8s-ci-robot removed the request for review from dims September 18, 2018 12:54
@apelisse
Copy link
Member

If no profile is specified, profileName is "" and those functions do nothing

Yeah, I don't think I agree. Running kubectl --profile whatever shouldn't skip profiling, that's too confusing.

@dlespiau
Copy link
Contributor Author

Ah I see what you mean, I think that's a general problem with options though :)

$ kubectl --kubeconfig get nodes
Error: unknown command "nodes" for "kubectl"
Run 'kubectl --help' for usage.
unknown command "nodes" for "kubectl"

--profile alone has the same behaviour:

$ ./_output/bin/kubectl --profile get nodes
Error: unknown command "nodes" for "kubectl"
Run 'kubectl --help' for usage.
unknown command "nodes" for "kubectl"

--profile alone isn't meaningful, just like --kubeconfig alone isn't. The parser takes the next token as the --profile option and tries to find the nodes sub-command, which doesn't exist. I tried to play with -- to terminate the option list and force an empty --profile option but to no avail. --profile on its own is simply not valid, just like --kubeconfig on its own.

To achieve meaningful --profile option, we'd need to have it a boolean option I believe and the UX would become:

$ kubectl --profile --profile-kind=block --profile-output=foo.pprof get nodes

with --profile-kind defaulting to, say, cpu. I have a preference for only having two options.

Just in case the whatever in your example meant a bogus profile name, the current code errors out:

$ ./_output/bin/kubectl --profile whatever get nodes
[...]
unknown profile 'whatever'

@apelisse
Copy link
Member

Sorry, I made a mistake ... I meant $ kubectl --profile= get pods. It's still weird if this does no profiling.

@apelisse
Copy link
Member

apelisse commented Sep 18, 2018

Sorry, I made a mistake ... I meant $ kubectl --profile= get pods. It's still weird if this does no profiling.

or maybe it's not, maybe you should have an option named "none", and make it the default?

This commit adds two new global options to kubectl: --profile and
--profile-output, writing out go profiles to disk to debug interesting and
unexpected kubectl behaviour.

As an example, here is how to capture a block file, eg. for how long are we
blocked on I/O and where?

$ kubectl get nodes --profile=mutex -v6
$ go tool pprof -png ./profile.pprof > out.png
$ google-chrome out.png

Fixes: kubernetes#68679
@dlespiau
Copy link
Contributor Author

dlespiau commented Sep 18, 2018

Oh I like the "none" idea! Thanks for taking the time to think about it and make a great suggestion!

Now, giving a "" string errors out as such:

./_output/bin/kubectl --profile= get nodes
[...]
unknown profile ''

Updated the code and help string with `"none"``.

@apelisse
Copy link
Member

/lgtm

Thanks!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: apelisse, dlespiau

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

The pull request process is described here

Details 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 Sep 18, 2018
@dlespiau
Copy link
Contributor Author

Thanks a lot for the review!

@seans3
Copy link
Contributor

seans3 commented Sep 20, 2018

Would it be possible to add a unit test (e.g. profile_test.go)?

@dlespiau
Copy link
Contributor Author

Thinking a bit about it, we could maybe add tests along the lines of:

  • Check that giving a bogus profile name leads initProfiling to return an error
  • Check that giving a valid profile name generates a file (and maybe even check that is indeed a pprof file). Maybe cycle through all profile names to check all well-known names generate profiles.

@k8s-ci-robot k8s-ci-robot merged commit cc04abc into kubernetes:master Sep 26, 2018
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. area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants