Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

[kn-admin] support downloading profiling data for knative components #72

Merged
merged 19 commits into from
Aug 17, 2020

Conversation

xliuxu
Copy link
Contributor

@xliuxu xliuxu commented Jul 21, 2020

This is a draft PR for @chaozbj and I to co-work to implement a profiling subcommand for kn-admin plugin.
Details refer to #66

@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 21, 2020
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jul 21, 2020
@knative-prow-robot
Copy link

Hi @lanceliuu. Thanks for your PR.

I'm waiting for a knative 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.

@knative-prow-robot knative-prow-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 21, 2020
@knative-prow-robot knative-prow-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 21, 2020
Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

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

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -name '*.pb.go' -prune -o -type f -name '*.go' -print)
goimports -w $(find -name '*.go' | grep -v vendor | grep -v third_party | grep -v .pb.go | grep -v wire_gen.go)

Copy link
Member

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

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

Produced via:
gofmt -s -w $(find -path './vendor' -prune -o -path './third_party' -prune -o -name '*.pb.go' -prune -o -type f -name '*.go' -print)
goimports -w $(find -name '*.go' | grep -v vendor | grep -v third_party | grep -v .pb.go | grep -v wire_gen.go)

@daisy-ycguo
Copy link
Member

/ok-to-test

@knative-prow-robot knative-prow-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 22, 2020
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 23, 2020
Copy link
Contributor

@maximilien maximilien left a comment

Choose a reason for hiding this comment

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

Various feedback... I know this is DRAFT but please start adding tests (unit and e2e). At least make sure you have a plan. Perhaps have tests with empty bodies to start with?

// ProfileType enums for all supported profiles
type ProfileType int

const secondsKey = "seconds"
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this not in the const block above?

type Downloader struct {
podName string
namespace string
// Close this will trigger closing for the endCh create by our own and then cancel all sub goroutines
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I understand this comment? "Close ..." you mean closing the stopCh channel?

err := fw.ForwardPorts()
// if the func ForwardPorts() returns, the connection should not be available.
if err != nil {
// TODO: Log for error?
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, definitely add logging support. Perhaps retries IF/WHEN it makes sense.

}

// ProfilingTime is option to add a seconds param in the http request
type ProfilingTime time.Duration
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to separate this (and methods) into its own file? Might make things easier to navigate and manage in the long run...


// Download specific type of profile with options
func (d *Downloader) Download(t ProfileType, output io.Writer, options ...DownloadOptions) error {
if t <= ProfileTypeUnknown || t >= ProfileType(len(ProfileEndpoints)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, this condition reads odd to me. The value ProfileTypeUnknown as per type above is a string. What would t <= another string result to? Maybe I am reading this wrong...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ProfileType is enum type of int. So ProfileTypeUnknown is the default value 0. There is an array declared at line 40 to map ProfileType to the coressponding string.

"k8s.io/client-go/tools/clientcmd"
)

// DO NOT COMMIT
Copy link
Contributor

Choose a reason for hiding this comment

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

"DO NOT COMMIT" and it's in the PR!! :)

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 sample code for reference as I need to co-work with @chaozbj. This file will NOT exist in the final PR.

if err != nil {
log.Fatal(err)
}
f1, _ := ioutil.TempFile("", "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we ignoring errors here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above

@xliuxu
Copy link
Contributor Author

xliuxu commented Jul 24, 2020

@maximilien I will fill up tests and then request for review. Thanks for your comments!

@knative-prow-robot knative-prow-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 26, 2020
@xliuxu
Copy link
Contributor Author

xliuxu commented Jul 26, 2020

/retest

@knative-prow-robot
Copy link

@lanceliuu: The /test command needs one or more targets.
The following commands are available to trigger jobs:

  • /test pull-knative-client-contrib-build-tests
  • /test pull-knative-client-contrib-unit-tests
  • /test pull-knative-client-contrib-integration-tests

Use /test all to run all jobs.

In response to this:

/test

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.

@maximilien
Copy link
Contributor

maximilien commented Jul 30, 2020

Hi, @lanceliuu, is this ready for new review? Does not seem like PROW ran any tests? Please tag me when ready for another review. Thanks.

@xliuxu xliuxu marked this pull request as ready for review July 31, 2020 01:58
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 31, 2020
@xliuxu
Copy link
Contributor Author

xliuxu commented Jul 31, 2020

/retest

plugins/admin/README.adoc Outdated Show resolved Hide resolved
plugins/admin/pkg/command/profiling/profiling.go Outdated Show resolved Hide resolved
@xliuxu
Copy link
Contributor Author

xliuxu commented Jul 31, 2020

@maximilien @zhanggbj This PR is ready for review. Thanks!
e2e tests for this command is currently missing since it depends on #63

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 16, 2020
@zhanggbj
Copy link

Hi @lanceliuu @chaozbj , already LGTM, would you please help to rebase it? Thanks!

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 16, 2020
Lance Liu and others added 19 commits August 17, 2020 10:16
Signed-off-by: chaozbj <[email protected]>
add interface to downloader
add tests to downloader
split downloadOptions to seperate file

Signed-off-by: Lance Liu <[email protected]>
Signed-off-by: Lance Liu <[email protected]>
fix some UT for downloader

Signed-off-by: Lance Liu <[email protected]>
Signed-off-by: Lance Liu <[email protected]>
Signed-off-by: Lance Liu <[email protected]>
Signed-off-by: chaozbj <[email protected]>
@knative-prow-robot knative-prow-robot removed lgtm 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 Aug 17, 2020
@xliuxu
Copy link
Contributor Author

xliuxu commented Aug 17, 2020

@zhanggbj Rebase done. Thank you.

@zhanggbj
Copy link

/lgtm
Great! Thanks!

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 17, 2020
@knative-prow-robot knative-prow-robot merged commit 88f3a66 into knative:master Aug 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants