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

Commit

Permalink
[kn-admin] support downloading profiling data for knative components (#…
Browse files Browse the repository at this point in the history
…72)

* add utils for profile downloader

Signed-off-by: Lance Liu <[email protected]>

* fix typo and package name

* remove unnecessary chan in Downloader struct

* move the example main to seperate folder

Signed-off-by: Lance Liu <[email protected]>

* check response code before saving body

* add profiling subcommand

Signed-off-by: chaozbj <[email protected]>

* implemented profiling command and ut codes

Signed-off-by: chaozbj <[email protected]>

* reworded test function names

Signed-off-by: chaozbj <[email protected]>

* improved expected messages for UT

Signed-off-by: chaozbj <[email protected]>

* improved command help

Signed-off-by: chaozbj <[email protected]>

* remove main.go
add interface to downloader
add tests to downloader
split downloadOptions to seperate file

Signed-off-by: Lance Liu <[email protected]>

* add licence to files

Signed-off-by: Lance Liu <[email protected]>

* change downloader initliazer interface for UT
fix some UT for downloader

Signed-off-by: Lance Liu <[email protected]>

* Add more tests for downloader connect function

Signed-off-by: Lance Liu <[email protected]>

* use assert.Error to check error

Signed-off-by: Lance Liu <[email protected]>

* fix lint errors

Signed-off-by: Lance Liu <[email protected]>

* fix typos

Signed-off-by: Lance Liu <[email protected]>

* improve wording

Signed-off-by: chaozbj <[email protected]>

* add e2e to profiling subcommand

Signed-off-by: Lance Liu <[email protected]>

Co-authored-by: chaozbj <[email protected]>
  • Loading branch information
Lance Liu and chaozbj authored Aug 17, 2020
1 parent cd7357b commit 88f3a66
Show file tree
Hide file tree
Showing 12 changed files with 1,794 additions and 2 deletions.
72 changes: 72 additions & 0 deletions plugins/admin/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,56 @@ Global Flags:
Use "kn admin autoscaling [command] --help" for more information about a command.
----

#### `kn admin profiling`

----
Enable Knative Serving components profiling and download profiling data
Usage:
kn admin profiling [flags]
Aliases:
profiling, prof
Examples:
# To enable Knative Serving profiling
kn admin profiling --enable
# To download heap profiling data of autoscaler
kn admin profiling --target autoscaler --heap
# To download 2 minutes execution trace data of networking-istio
kn admin profiling --target networking-istio --trace 2m
# To download go routing block and memory allocations data of activator and save them to /tmp
kn admin profiling --target activator --block --mem-allocs --save-to /tmp
# To download all available profiling data for specified pod activator-5979f56548
kn admin profiling --target activator-5979f56548 --all
Flags:
--all Download all available profiling data
--block Download go routine blocking data
--cpu string Download cpu profiling data, you can specify a profiling data duration with 's' for second(s), 'm' for minute(s) and 'h' for hour(s), e.g: '1m' for one minute (default "5s")
--disable Disable Knative Serving profiling
--enable Enable Knative Serving profiling
--goroutine Download stack traces of all current goroutines data
--heap Download heap profiling data
-h, --help help for profiling
--mem-allocs Download memory allocations data
--mutex Download holders of contended mutexes data
-s, --save-to string The path to save the downloaded profiling data, if not speicifed, the data will be saved in current working folder
-t, --target string The profiling target. It can be a Knative Serving component name or a specific pod name, e.g: 'activator' or 'activator-586d468c99-w59cm'
--thread-create Download stack traces that led to the creation of new OS threads data
--trace string Download execution trace data, you can specify a trace data duration with 's' for second(s), 'm' for minute(s) and 'h' for hour(s), e.g: '1m' for one minute (default "5s")
Global Flags:
--config string config file (default is $HOME/.config/kn/plugins/admin.yaml)
----
### Examples

Expand Down Expand Up @@ -181,3 +231,25 @@ $ kn admin autoscaling update --scale-to-zero
Updated Knative autoscaling config enable-scale-to-zero: true
-----
=====

#### As a Knative administrator, I want to enable Knative Serving profiling and download profile data.

.Enable Knative Serving profiling.
=====
-----
$ kn admin profiling --enable
Knative Serving profiling is enabled
-----
=====

.Download 5 seconds cpu profiling data of activator component and save data to /tmp folder
=====
-----
$ kn admin profiling --target activator --cpu 5s --save-to /tmp
Starting to download profiling data for pod activator-586d468c99-w59cm...
Saving 5 second(s) cpu profiling data to /tmp/activator-586d468c99-w59cm_cpu_5s_20200725165758
Forwarding from 127.0.0.1:18008 -> 8008
Forwarding from [::1]:18008 -> 8008
Handling connection for 18008
-----
=====
6 changes: 4 additions & 2 deletions plugins/admin/core/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import (
"knative.dev/client-contrib/plugins/admin/pkg/command"
"knative.dev/client-contrib/plugins/admin/pkg/command/autoscaling"
"knative.dev/client-contrib/plugins/admin/pkg/command/domain"
"knative.dev/client-contrib/plugins/admin/pkg/command/profiling"
private_registry "knative.dev/client-contrib/plugins/admin/pkg/command/registry"
)

var cfgFile string

// rootCmd represents the base command when called without any subcommands
// NewAdminCommand represents the base command when called without any subcommands
func NewAdminCommand(params ...pkg.AdminParams) *cobra.Command {
p := &pkg.AdminParams{}
p.Initialize()
Expand All @@ -46,10 +47,11 @@ func NewAdminCommand(params ...pkg.AdminParams) *cobra.Command {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.config/kn/plugins/admin.yaml)")
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

rootCmd.SetOut(os.Stdout)
rootCmd.AddCommand(domain.NewDomainCmd(p))
rootCmd.AddCommand(private_registry.NewPrivateRegistryCmd(p))
rootCmd.AddCommand(autoscaling.NewAutoscalingCmd(p))
rootCmd.AddCommand(profiling.NewProfilingCommand(p))
rootCmd.AddCommand(command.NewVersionCommand())

// Add default help page if there's unknown command
Expand Down
1 change: 1 addition & 0 deletions plugins/admin/core/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestNewAdminCommand(t *testing.T) {
"domain",
"registry",
"autoscaling",
"profiling",
}

cmd := NewAdminCommand()
Expand Down
Loading

0 comments on commit 88f3a66

Please sign in to comment.