From 838a6885194b4a8b6f626a5d620e706a114a33c0 Mon Sep 17 00:00:00 2001 From: Xueliang Yang Date: Sun, 5 Jun 2022 11:47:46 +0800 Subject: [PATCH] trait:pyroscope Signed-off-by: Xueliang Yang --- addons/trait-pyroscope/README.md | 99 +++++++++++ addons/trait-pyroscope/metadata.yaml | 16 ++ .../trait-pyroscope/resources/pyroscope.cue | 167 ++++++++++++++++++ 3 files changed, 282 insertions(+) create mode 100644 addons/trait-pyroscope/README.md create mode 100644 addons/trait-pyroscope/metadata.yaml create mode 100644 addons/trait-pyroscope/resources/pyroscope.cue diff --git a/addons/trait-pyroscope/README.md b/addons/trait-pyroscope/README.md new file mode 100644 index 000000000..9768f1fb1 --- /dev/null +++ b/addons/trait-pyroscope/README.md @@ -0,0 +1,99 @@ +# pyroscope + +This addon is for pyroscope + + +In this addon, the repo is from https://github.com/pyroscope-io/pyroscope + +## install + +```shell +vela addon enable pyroscope +``` + +## uninstall + +```shell +vela addon disable pyroscope +``` + +# Supported workload type +Pyroscope Trait supports following component types: webservice态worker and cloneset. + +# How to start +- Use a component typed webservice to start, keep the following to app-demo.yaml, then vela up -f app-demo.yaml +```shell +apiVersion: core.oam.dev/v1beta1 +kind: Application +metadata: + name: app-show + namespace: real-new-ns +spec: + components: + - name: web-show + type: webservice + properties: + exposeType: ClusterIP + image: beellzrocks/shippingservice + env: + - name: PORT + value: "50051" + - name: APPLICATION_NAME # Application name shown in the Pyroscope UI + value: "web-show" + - name: SERVER_ADDRESS # To change Pyroscope Server Port change the value, the naming rule is pyroscope- + value: "http://pyroscope-web-show:4040" + traits: + - type: pyroscope +``` +- Check the app status +```shell +vela ls -n real-new-ns +APP COMPONENT TYPE TRAITS PHASE HEALTHY STATUS CREATED-TIME +app-show web-show webservice pyroscope running healthy Ready:1/1 2022-06-03 19:41:05 +0800 CST + +vela status app-show -n real-new-ns +About: + + Name: app-show + Namespace: real-new-ns + Created at: 2022-06-03 19:41:05 +0800 CST + Status: running + +Workflow: + + mode: DAG + finished: true + Suspend: false + Terminated: false + Steps + - id:zsbjvp7fg5 + name:web-show + type:apply-component + phase:succeeded + message: + +Services: + + - Name: web-show + Cluster: local Namespace: real-new-ns + Type: webservice + Healthy Ready:1/1 + Traits: + ? pyroscope +``` + +- Use the port-forward to visit the pyroscope UI +```shell +vela port-forward app-show 8080:4040 -n real-new-ns +? You have 3 deployed resources in your app. Please choose one: Cluster: local | Namespace: real-new-ns | Kind: Service | Name: pyroscope-web-show +Forwarding from 127.0.0.1:8080 -> 4040 +Forwarding from [::1]:8080 -> 4040 + +Forward successfully! Opening browser ... + +Failed to open browser: exec: "xdg-open": executable file not found in $PATHHandling connection for 8080 +Handling connection for 8080 + +Then you can visit the http://:8080 in the browser +``` + diff --git a/addons/trait-pyroscope/metadata.yaml b/addons/trait-pyroscope/metadata.yaml new file mode 100644 index 000000000..b73f1042c --- /dev/null +++ b/addons/trait-pyroscope/metadata.yaml @@ -0,0 +1,16 @@ +name: pyroscope +version: v0.17.1 +description: "Continuous Profiling Platform. Debug performance issues down to a single line of code" +icon: "https://user-images.githubusercontent.com/662636/105129037-11334180-5a99-11eb-8951-1d4aaaed50de.png" +url: "https://github.com/pyroscope-io/pyroscope" + +tags: + - extended_trait + +deployTo: + control_plane: true + +dependencies: + - name: fluxcd + +invisible: false diff --git a/addons/trait-pyroscope/resources/pyroscope.cue b/addons/trait-pyroscope/resources/pyroscope.cue new file mode 100644 index 000000000..1a85774d2 --- /dev/null +++ b/addons/trait-pyroscope/resources/pyroscope.cue @@ -0,0 +1,167 @@ +pyroscope: { + annotations: {} + attributes: { + appliesToWorkloads: ["*"] + conflictsWith: [] + podDisruptive: false + workloadRefPath: "" + } + description: "" + labels: {} + type: "trait" +} + +template: { + outputs: + "pyroscope-deployment":{ + metadata: { + name: "pyroscope-"+context.name + labels: { + "app.kubernetes.io/instance": "pyroscope-"+context.name + "app.kubernetes.io/name": "pyroscope-"+context.name + "app.kubernetes.io/version": "0.17.1" + } + namespace: context.namespace + } + spec: { + progressDeadlineSeconds: 600 + replicas: 1 + revisionHistoryLimit: 10 + selector: matchLabels: { + "app.kubernetes.io/instance": "pyroscope-"+context.name + "app.kubernetes.io/name": "pyroscope-"+context.name + } + strategy: type: "Recreate" + template: { + metadata: { + labels: { + "app.kubernetes.io/instance": "pyroscope-"+context.name + "app.kubernetes.io/name": "pyroscope-"+context.name + } + creationTimestamp: null + } + spec: { + securityContext: fsGroup: 101 + containers: [{ + name: "pyroscope-"+context.name + args: ["server", "-config", "/tmp/config.yaml"] + image: "pyroscope/pyroscope:0.17.1" + imagePullPolicy: "IfNotPresent" + livenessProbe: { + failureThreshold: 3 + httpGet: { + path: "/healthz" + port: 4040 + scheme: "HTTP" + } + initialDelaySeconds: 30 + periodSeconds: 15 + successThreshold: 1 + timeoutSeconds: 30 + } + ports: [{ + name: "api" + containerPort: 4040 + protocol: "TCP" + }] + readinessProbe: { + failureThreshold: 3 + httpGet: { + path: "/healthz" + port: 4040 + scheme: "HTTP" + } + initialDelaySeconds: 30 + periodSeconds: 5 + successThreshold: 1 + timeoutSeconds: 30 + } + resources: {} + securityContext: {} + terminationMessagePath: "/dev/termination-log" + terminationMessagePolicy: "File" + volumeMounts: [{ + name: "config" + mountPath: "/tmp/config.yaml" + subPath: "config.yaml" + }] + }] + dnsPolicy: "ClusterFirst" + restartPolicy: "Always" + schedulerName: "default-scheduler" + serviceAccount: "pyroscope-"+context.name + serviceAccountName: "pyroscope-"+context.name + terminationGracePeriodSeconds: 30 + volumes: [{ + name: "config" + configMap: { + name: "pyroscope-"+context.name + defaultMode: 420 + } + }] + } + } + } + apiVersion: "apps/v1" + kind: "Deployment" + } + outputs: + "pyroscope-cm":{ + apiVersion: "v1" + data: "config.yaml": """ + {} + + """ + kind: "ConfigMap" + metadata: { + name: "pyroscope-"+context.name + labels: { + "app.kubernetes.io/instance": "pyroscope-"+context.name + "app.kubernetes.io/name": "pyroscope-"+context.name + } + namespace: context.namespace + } + } + outputs: + "pyroscope-svc":{ + apiVersion: "v1" + kind: "Service" + metadata: { + name: "pyroscope-"+context.name + labels: { + "app.kubernetes.io/instance": "pyroscope-"+context.name + "app.kubernetes.io/name": "pyroscope-"+context.name + } + namespace: context.namespace + } + spec: { + ports: [{ + name: "http" + port: 4040 + protocol: "TCP" + targetPort: "api" + }] + selector: { + "app.kubernetes.io/instance": "pyroscope-"+context.name + "app.kubernetes.io/name": "pyroscope-"+context.name + } + sessionAffinity: "None" + type: "ClusterIP" + } + } + + outputs: + "pyroscope-sa": { + apiVersion: "v1" + kind: "ServiceAccount" + metadata: { + name: "pyroscope-"+context.name + labels: { + "app.kubernetes.io/instance": "pyroscope-"+context.name + "app.kubernetes.io/name": "pyroscope-"+context.name + } + namespace: context.namespace + } + } + parameter: {} +}