-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [Addon] pyroscope addon Signed-off-by: fourierr <[email protected]> * [Addon] pyroscope addon Signed-off-by: fourierr <[email protected]>
- Loading branch information
Showing
7 changed files
with
418 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
pyroscope: { | ||
attributes: { | ||
appliesToWorkloads: ["*"] | ||
podDisruptive: false | ||
} | ||
description: "" | ||
labels: {} | ||
type: "trait" | ||
} | ||
|
||
template: { | ||
// +patchStrategy=jsonMergePatch | ||
patch: spec: template: spec: containers: [{ | ||
env: [ | ||
{ | ||
name: "server" | ||
value: parameter.server | ||
}, | ||
{ | ||
name: "appName" | ||
if parameter.appName != _|_ { | ||
value: parameter.appName | ||
} | ||
if parameter.appName == _|_ { | ||
value: context.name | ||
} | ||
}, | ||
{ | ||
name: "logger" | ||
value: parameter.logger | ||
}] | ||
},...] | ||
parameter: { | ||
server: string | ||
appName?: string | ||
logger: string | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: pyroscope | ||
version: 0.17.1 | ||
description: Pyroscope is an open source platform, consisting of server and agent. It allows the user to collect, store, and query the profiling data in a CPU and disk efficient way. | ||
url: https://github.com/pyroscope-io/pyroscope | ||
icon: https://raw.githubusercontent.com/pyroscope-io/pyroscope/main/webapp/images/favicon.ico | ||
|
||
tags: | ||
- profiling tool | ||
|
||
deployTo: | ||
control_plane: true | ||
|
||
dependencies: | ||
- name: fluxcd | ||
|
||
needNamespace: | ||
- vela-system | ||
|
||
invisible: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
# Pyroscope | ||
|
||
This addon is built based [Pyroscope](https://github.com/pyroscope-io/pyroscope), which consist of server and agent. It allows the user to collect, store, and query the profiling data in a CPU and disk efficient way. | ||
|
||
## install | ||
|
||
```shell | ||
vela addon enable pyroscope | ||
``` | ||
After enable pyroscope successfully, you can execute command to expose the port for Dashboard UI | ||
```shell | ||
export POD_NAME=$(kubectl get pods --namespace vela-system -l "app.kubernetes.io/name=pyroscope,app.kubernetes.io/instance=pyroscope" -o jsonpath="{.items[0].metadata.name}") | ||
export CONTAINER_PORT=$(kubectl get pod --namespace vela-system $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") | ||
kubectl --namespace vela-system port-forward $POD_NAME 8083:$CONTAINER_PORT | ||
``` | ||
|
||
## uninstall | ||
|
||
```shell | ||
vela addon disable pyroscope | ||
``` | ||
|
||
|
||
# How to start | ||
Use a component typed webservice to start, keep the following to pyroscope-demo.yaml, then vela up -f app-demo.yaml | ||
```yaml | ||
apiVersion: core.oam.dev/v1beta1 | ||
kind: Application | ||
metadata: | ||
name: pyroscope-app | ||
namespace: fourier | ||
spec: | ||
components: | ||
- name: pyroscope-comp-01 | ||
type: webservice | ||
properties: | ||
image: nginx:latest | ||
ports: | ||
- expose: true | ||
port: 80 | ||
protocol: TCP | ||
imagePullPolicy: IfNotPresent | ||
traits: | ||
- type: pyroscope | ||
properties: | ||
server: "http://pyroscope-server:9084" | ||
logger: "pyroscope.StandardLogger" | ||
appName: "pyroscope-test" | ||
- type: scaler | ||
properties: | ||
replicas: 1 | ||
``` | ||
And the parameter `appName` is a optional field, default value is the component name. | ||
|
||
## Note | ||
### Pyroscope for Golang applications | ||
|
||
- To start profiling a Go application, you need to include our go module in your app | ||
```shell | ||
# make sure you also upgrade pyroscope server to version 0.3.1 or higher | ||
go get github.com/pyroscope-io/client/pyroscope | ||
``` | ||
- Then add the following code to your application: | ||
```go | ||
package main | ||
import "github.com/pyroscope-io/client/pyroscope" | ||
func main() { | ||
pyroscope.Start(pyroscope.Config{ | ||
ApplicationName: "simple.golang.app", | ||
// replace this with the address of pyroscope server | ||
ServerAddress: "http://pyroscope-server:4040", | ||
// you can disable logging by setting this to nil | ||
Logger: pyroscope.StandardLogger, | ||
// optionally, if authentication is enabled, specify the API key: | ||
// AuthToken: os.Getenv("PYROSCOPE_AUTH_TOKEN"), | ||
// by default all profilers are enabled, but you can select the ones you want to use: | ||
ProfileTypes: []pyroscope.ProfileType{ | ||
pyroscope.ProfileCPU, | ||
pyroscope.ProfileAllocObjects, | ||
pyroscope.ProfileAllocSpace, | ||
pyroscope.ProfileInuseObjects, | ||
pyroscope.ProfileInuseSpace, | ||
}, | ||
}) | ||
// your code goes here | ||
} | ||
``` | ||
- Check out the [examples](https://github.com/pyroscope-io/pyroscope/tree/main/examples/golang-push) directory in our repository to learn more | ||
|
||
### Pyroscope for Java applications | ||
|
||
- Java integration is distributed as a single jar file: pyroscope.jar. It contains native async-profiler libraries | ||
- To start profiling a Java application, run your application with pyroscope.jar javaagent: | ||
```shell | ||
export PYROSCOPE_APPLICATION_NAME=my.java.app | ||
export PYROSCOPE_SERVER_ADDRESS=http://pyroscope-server:4040 | ||
# Optionally, if authentication is enabled, specify the API key. | ||
# export PYROSCOPE_AUTH_TOKEN={YOUR_API_KEY} | ||
java -javaagent:pyroscope.jar -jar app.jar | ||
``` | ||
- Check out the [examples](https://github.com/pyroscope-io/pyroscope/tree/main/examples/java) folder in our repository to learn more | ||
|
||
### Pyroscope for .net applications | ||
|
||
- To start profiling a .NET application inside a container, you may wrap your application with pyroscope exec as an entrypoint of your image. The tricky part is that you need to copy pyroscope binary to your docker container. To do that, use COPY --from command in your Dockerfile. | ||
The following example Dockerfile shows how to build the image: | ||
```dockerfile | ||
FROM mcr.microsoft.com/dotnet/sdk:5.0 | ||
WORKDIR /dotnet | ||
COPY --from=pyroscope/pyroscope:latest /usr/bin/pyroscope /usr/bin/pyroscope | ||
ADD my-app . | ||
RUN dotnet publish -o . -r $(dotnet --info | grep RID | cut -b 6- | tr -d ' ') | ||
# optionally you may set the pyroscope server address as well as the app name and other configuration options. | ||
ENV PYROSCOPE_SERVER_ADDRESS=http://pyroscope-server:4040 | ||
ENV PYROSCOPE_APPLICATION_NAME=my.dotnet.app | ||
ENV PYROSCOPE_LOG_LEVEL=debug | ||
CMD ["pyroscope", "exec", "dotnet", "/dotnet/my-app.dll"] | ||
``` | ||
- If you are using Docker Compose, you can run both pyroscope server and agent with this configuration: | ||
```yaml | ||
--- | ||
version: "3.9" | ||
services: | ||
pyroscope-server: | ||
image: "pyroscope/pyroscope:latest" | ||
ports: | ||
- "4040:4040" | ||
command: | ||
- "server" | ||
app: | ||
image: "my-app:latest" | ||
environment: | ||
PYROSCOPE_APPLICATION_NAME: my.dotnet.app | ||
PYROSCOPE_SERVER_ADDRESS: http://pyroscope-server:4040 | ||
PYROSCOPE_LOG_LEVEL: debug | ||
ASPNETCORE_URLS: http://*:5000 | ||
ports: | ||
- "5000:5000" | ||
cap_add: | ||
- SYS_PTRACE | ||
``` | ||
- Check out the [examples](https://github.com/pyroscope-io/pyroscope/tree/main/examples/dotnet) folder in our repository to learn more | ||
|
||
### Pyroscope for Python applications | ||
|
||
- First, install pyroscope-io pip package: | ||
```shell | ||
pip install pyroscope-io | ||
``` | ||
- Add the following code to your application. This code will initialize pyroscope profiler and start profiling: | ||
```shell | ||
import pyroscope | ||
pyroscope.configure( | ||
app_name = "my.python.app", # replace this with some name for your application | ||
server_address = "http://my-pyroscope-server:4040", # replace this with the address of your pyroscope server | ||
# auth_token = "{YOUR_API_KEY}", # optionally, if authentication is enabled, specify the API key | ||
) | ||
``` | ||
- Check out the [example python project in pyroscope repository](https://github.com/pyroscope-io/pyroscope/tree/main/examples/python) for examples of how you can use these features. | ||
|
||
### Pyroscope for PHP applications | ||
|
||
- To start profiling a PHP application in a container, you may wrap your application with pyroscope exec as an entrypoint of your image. The tricky part is that you need to copy pyroscope binary to your docker container. To do that, use COPY --from command in your Dockerfile. | ||
The following example Dockerfile shows how to build the image: | ||
```dockerfile | ||
FROM php:7.3.27 | ||
WORKDIR /var/www/html | ||
# this copies pyroscope binary from pyroscope image to your image: | ||
COPY --from=pyroscope/pyroscope:latest /usr/bin/pyroscope /usr/bin/pyroscope | ||
COPY main.php ./main.php | ||
# optionally you may set the pyroscope server address as well as the app name, make sure you change these: | ||
ENV PYROSCOPE_APPLICATION_NAME=my.php.app | ||
ENV PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040/ | ||
# this starts your app with pyroscope profiler, make sure to change "php" and "main.php" to the actual command. | ||
CMD ["pyroscope", "exec", "php", "main.php"] | ||
``` | ||
- If you are using Docker Compose, you can run both pyroscope server and agent with this configuration: | ||
```yaml | ||
--- | ||
services: | ||
pyroscope-server: | ||
image: "pyroscope/pyroscope:latest" | ||
ports: | ||
- "4040:4040" | ||
command: | ||
- "server" | ||
app: | ||
image: "my-app:latest" | ||
env: | ||
PYROSCOPE_SERVER_ADDRESS: http://pyroscope-server:4040 | ||
PYROSCOPE_APPLICATION_NAME: my.php.app | ||
cap_add: | ||
- SYS_PTRACE | ||
``` | ||
- Check out the [examples](https://github.com/pyroscope-io/pyroscope/tree/main/examples/php) folder in our repository to learn more | ||
|
||
### Pyroscope for NodeJS applications | ||
|
||
- To start profiling a NodeJS application, you need to include the npm module in your app: | ||
```shell | ||
npm install @pyroscope/nodejs | ||
# or | ||
yarn add @pyroscope/nodejs | ||
``` | ||
- Then add the following code to your application: | ||
```js | ||
const Pyroscope = require('@pyroscope/nodejs'); | ||
Pyroscope.init({ | ||
serverAddress: 'http://pyroscope:4040', | ||
appName: 'myNodeService' | ||
}); | ||
Pyroscope.start() | ||
``` | ||
- Check out the [examples](https://github.com/pyroscope-io/pyroscope/tree/main/examples/nodejs) directory in our repository to learn more |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
parameter: { | ||
// +usage=Specify image to use for deploying | ||
"image.repository": *"pyroscope/pyroscope" | string | ||
// +usage=Specify tag for pyroscope image to use | ||
"image.tag": *"0.17.1" | string | ||
// +usage=Specify image pull policy | ||
"image.pullPolicy": *"IfNotPresent" | string | ||
// +usage=Specify image pull secrets | ||
"imagePullSecrets": *[] | [...string] | ||
|
||
// +usage=Specify enables Ingress | ||
"ingress.enabled": *false | bool | ||
// +usage=Specify ingress accepted hostnames | ||
"ingress.hosts": #host | ||
// +usage=Specify ingress custom rules. Take precedence over chart built-ins. | ||
"ingress.rules": *[] | [...string] | ||
// +usage=Specify ingress TLS configuration | ||
"ingress.tls": *[] | [...string] | ||
|
||
// +usage=Specify persistence access modes | ||
"persistence.accessModes": *"ReadWriteOnce" | string | ||
// +usage=Specify use persistent volume to store data | ||
"persistence.enabled": *false | bool | ||
// +usage=Specify persistentVolumeClaim finalizers | ||
"persistence.finalizers": *["kubernetes.io/pvc-protection"] | [...string] | ||
// +usage=Specify size of persistent volume claim | ||
"persistence.size": *"10Gi" | string | ||
|
||
// +usage=Specify pyroscope server configuration. Please refer to https://pyroscope.io/docs/server-configuration | ||
"pyroscopeConfigs":*{} | #map | ||
|
||
// +usage=Specify extra rules for created cluster role | ||
"rbac.clusterRole.extraRules": *[] | [...string] | ||
// +usage=Specify cluster role name. If not set, the fully qualified app name is used | ||
"rbac.clusterRole.name": *"" | string | ||
// +usage=Specify cluster role binding name. If not set, the fully qualified app name is used | ||
"rbac.clusterRoleBinding.name":*"" | string | ||
// +usage=Specify creates Pyroscope cluster role and binds service account to it; requires service account to be created | ||
"rbac.create": *false | bool | ||
|
||
// +usage=Specify kubernetes port where service is exposed | ||
"service.port": *4040 | int | ||
// +usage=Specify service type | ||
"service.type": *"ClusterIP" | string | ||
// +usage=Specify create service account | ||
"serviceAccount.create": *true | bool | ||
// +usage=Specify service account name to use, when empty will be set to created account if serviceAccount.create is set else to default | ||
"serviceAccount.name": * "" | string | ||
} | ||
|
||
#host: [...{ | ||
"host": *"chart-example.local" | string | ||
"paths": #paths | ||
}] | ||
|
||
#paths: [...{ | ||
"path": *"/" | string | ||
"pathType": *"Prefix" | string | ||
}] | ||
|
||
#map: [string]: string |
Oops, something went wrong.