From ec730bc5608527c191a3cbf7ff0c61a7fc8017ed Mon Sep 17 00:00:00 2001 From: Jim Bugwadia Date: Mon, 22 Apr 2024 22:47:16 -0700 Subject: [PATCH] update dev docs (#10089) * update dev docs Signed-off-by: Jim Bugwadia * update dev docs Signed-off-by: Jim Bugwadia --------- Signed-off-by: Jim Bugwadia --- DEVELOPMENT.md | 84 ++++++++++++++++++++++++++++++++++++++++++++++ docs/dev/README.md | 7 ++++ 2 files changed, 91 insertions(+) create mode 100644 docs/dev/README.md diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index ccbf048641..5dfbd878b3 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -27,6 +27,10 @@ It contains instructions to build, run, and test Kyverno. - [Generating helm charts CRDs](#generating-helm-charts-crds) - [Generating helm charts docs](#generating-helm-charts-docs) - [Debugging local code](#debugging-local-code) +- [Profiling](#profiling) +- [Other Topics](#other-topics) +- [Selecting Issues](#selecting-issues) + ## Open project in devcontainer (recommended) - Clone the project to your local machine. @@ -427,3 +431,83 @@ go run ./cmd/kyverno/ --kubeconfig ~/.kube/config --serverIP=:9443 --b ``` You will need to adapt those steps to run debug sessions in your IDE of choice, but the general idea remains the same. + + +## Profiling + +### Enable profiling +To profile Kyverno application running inside a Kubernetes pod, set `--profile` flag to `true` in [install.yaml](https://github.com/kyverno/kyverno/blob/main/definitions/install.yaml). The default profiling port is 6060, and it can be configured via `profile-port`. + +``` + --profile + Set this flag to 'true', to enable profiling. + --profile-port string + Enable profiling at given port, defaults to 6060. (default "6060") +``` + +### Expose the endpoint on a local port +You can get at the application in the pod by port forwarding with kubectl, for example: + +````shell +$ kubectl -n kyverno get pod +NAME READY STATUS RESTARTS AGE +kyverno-7d67c967c6-slbpr 1/1 Running 0 19s +```` + +````bash +$ kubectl -n kyverno port-forward kyverno-7d67c967c6-slbpr 6060 +Forwarding from 127.0.0.1:6060 -> 6060 +Forwarding from [::1]:6060 -> 6060 +```` + +The HTTP endpoint will now be available as a local port. + +Alternatively, use a Service of the type `LoadBalancer` to expose Kyverno. An example Service manifest is given below: + +```yaml +apiVersion: v1 +kind: Service +metadata: + name: pproc-service + namespace: kyverno +spec: + selector: + app: kyverno + ports: + - protocol: TCP + port: 6060 + targetPort: 6060 + type: LoadBalancer +``` + + +### Generate the data +You can then generate the file for the **memory** profile with curl and pipe the data to a file: +````shell +$ curl http://localhost:6060/debug/pprof/heap > heap.pprof +```` + +Generate the file for the **CPU** profile with curl and pipe the data to a file: +```shell +curl "http://localhost:6060/debug/pprof/profile?seconds=60" > cpu.pprof +``` + +### Analyze the data +To analyze the data: +````shell +go tool pprof heap.pprof +```` + +### Read more about profiling +- [Profiling Golang Programs on Kubernetes](https://danlimerick.wordpress.com/2017/01/24/profiling-golang-programs-on-kubernetes/) +- [Official GO blog](https://blog.golang.org/pprof) + + +## Other Topics + +Additional advanced developer docs are avaialable in the [developer docs folder](./docs/dev/). + + +## Selecting Issues + +When you are ready to contribute, you can select issue at [Good First Issues](https://github.com/orgs/kyverno/projects/10). diff --git a/docs/dev/README.md b/docs/dev/README.md new file mode 100644 index 0000000000..fadf2114eb --- /dev/null +++ b/docs/dev/README.md @@ -0,0 +1,7 @@ +# Developer Documentation (Advanced Topics) + +This folder contains developer documentation. + +To get started see: [DEVELOPMENT.md](../../DEVELOPMENT.md). + +When you are ready to contribute, you can select issue at [Good First Issues](https://github.com/orgs/kyverno/projects/10). \ No newline at end of file