|
| 1 | +[note] |
| 2 | +**Note**: All commands are written for `juju >= v3.1` |
| 3 | + |
| 4 | +If you're using `juju 2.9`, check the [`juju 3.0` Release Notes](https://juju.is/docs/juju/roadmap#heading--juju-3-0-0---22-oct-2022). |
| 5 | +[/note] |
| 6 | + |
| 7 | +# Enable profiling with Parca |
| 8 | + |
| 9 | +This guide contains the steps to enable profiling with [Parca](https://www.parca.dev/docs/overview/) for your PostgreSQL application. |
| 10 | + |
| 11 | +## Summary |
| 12 | +* [Prerequisites](#prerequisites) |
| 13 | +* [Set up the Parca backend](#set-up-the-parca-backend) |
| 14 | + * [Charmed Parca K8s](#charmed-parca-k8s) |
| 15 | + * [Polar Signals Cloud](#polar-signals-cloud) |
| 16 | +* [View profiles](#view-profiles) |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## Prerequisites |
| 21 | + |
| 22 | +[note type=caution] |
| 23 | +**Do not skip this section ** if you are deploying PostgreSQL in an LXD model or if your base is `[email protected]`. |
| 24 | +[/note] |
| 25 | + |
| 26 | + |
| 27 | +This guide assumes you already have a juju model with Charmed PostgreSQL deployed. |
| 28 | + |
| 29 | +> See: [How to deploy PostgreSQL](/t/16811) |
| 30 | +
|
| 31 | +In order for your Charmed PostgreSQL deployment to be correctly set up for integration with Parca, there are two important considerations: |
| 32 | +* [LXD virtualization type](#lxd-virtualization-type) |
| 33 | +* [Base (Ubuntu version)](#base-ubuntu-version) |
| 34 | + |
| 35 | +### LXD virtualization type |
| 36 | + |
| 37 | +**If you are deploying Charmed PostgreSQL in a LXD model, you will need to ensure that LXD's virtualization type is set to `virtual-machine` for the Juju application.** |
| 38 | + |
| 39 | +This is because LXD does not allow `/sys/kernel/tracing` to be mounted in a system container (even in privileged mode) due to security isolation concerns. |
| 40 | + |
| 41 | +To ensure that a virtual machine is used instead of a system container, you would need to add constraints, for example: |
| 42 | +``` |
| 43 | +juju deploy postgresql --constraints="virt-type=virtual-machine"`. |
| 44 | +``` |
| 45 | + |
| 46 | +### Base (Ubuntu version) |
| 47 | +**If your base is `[email protected]`, you will need to ensure that your are using the `generic` flavor of Linux. ** |
| 48 | +> See the output of `uname -r` to confirm. |
| 49 | +
|
| 50 | +If you do not have the `generic` flavor, you can enable it on a unit to be profiled as follows: |
| 51 | + |
| 52 | +``` |
| 53 | +juju ssh postgresql/0 bash |
| 54 | +sudo apt-get update && sudo apt-get install linux-image-virtual |
| 55 | +sudo apt-get autopurge linux-image-kvm |
| 56 | +``` |
| 57 | + |
| 58 | +If your application is deployed in an LXD model, run the following command: |
| 59 | +``` |
| 60 | +rm /etc/default/grub.d/40-force-partuuid.cfg |
| 61 | +``` |
| 62 | + |
| 63 | +Open the `/etc/default/grub` file with your editor of choice and replace the line that starts with `GRUB_DEFAULT=` with: |
| 64 | +``` |
| 65 | +release=$(linux-version list | grep -e '-generic$' | sort -V | tail -n1) |
| 66 | +GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux $release" |
| 67 | +``` |
| 68 | + |
| 69 | +Exit out of the `/etc/default/grub file`, update GRUB, and reboot: |
| 70 | +``` |
| 71 | +sudo update-grub |
| 72 | +sudo reboot |
| 73 | +``` |
| 74 | + |
| 75 | +Nothing needs to be done if the base is `[email protected]`, which already loads the kernel symbol table for debugging by default. |
| 76 | + |
| 77 | +## Set up the Parca backend |
| 78 | + |
| 79 | +There are two potential backends: |
| 80 | +* [Charmed Parca K8s](#charmed-parca-k8s) (requires COS and cross-model integrations) |
| 81 | +* [Polar Signals Cloud](#polar-signals-cloud) (COS is optional) |
| 82 | + |
| 83 | +### Charmed Parca K8s |
| 84 | + |
| 85 | +This section goes through the steps for enabling profiling with Charmed Parca K8s as the backend. |
| 86 | + |
| 87 | +#### 1. Deploy `cos-lite` and `parca-k8s` |
| 88 | + |
| 89 | +Refer to [Getting started on MicroK8s](https://charmhub.io/topics/canonical-observability-stack/tutorials/install-microk8s) and deploy the `cos-lite` bundle from the `latest/edge` track in a Kubernetes environment. |
| 90 | + |
| 91 | +Then, refer to [Deploy Charmed Parca on top of COS-lite](https://discourse.charmhub.io/t/how-to-deploy-charmed-parca-on-top-of-cos-lite/16579) to deploy Charmed Parca K8s in the same model as the `cos-lite` bundle. |
| 92 | + |
| 93 | +#### 2. Offer interfaces |
| 94 | + |
| 95 | +Offer interfaces for cross-model integrations: |
| 96 | + |
| 97 | +``` |
| 98 | +juju offer <parca_k8s_application_name>:parca-store-endpoint |
| 99 | +``` |
| 100 | + |
| 101 | +#### 3. Deploy and integrate `parca-agent` with `postgresql` |
| 102 | + |
| 103 | +Switch to the model containing the Charmed PostgreSQL deployment, deploy Charmed Parca Agent, and integrate it with Charmed PostgreSQL: |
| 104 | + |
| 105 | +``` |
| 106 | +juju switch <machine_controller_name>:<postgresql_model_name> |
| 107 | +
|
| 108 | +juju deploy parca-agent --channel latest/edge |
| 109 | +juju integrate postgresql parca-agent |
| 110 | +``` |
| 111 | + |
| 112 | +#### 4. Integrate `parca-agent` with `parca-k8s` |
| 113 | + |
| 114 | +Consume the parca offer from [Step 2](#2-offer-interfaces) and integrate with them: |
| 115 | + |
| 116 | +``` |
| 117 | +juju find-offers <k8s_controller_name>: |
| 118 | +``` |
| 119 | + |
| 120 | +> :exclamation: Do not miss the colon "`:`" in the command above. |
| 121 | +
|
| 122 | +Below is a sample output where `k8s` is the K8s controller name and `cos` is the model where `cos-lite` and `parca-k8s` are deployed: |
| 123 | + |
| 124 | +``` |
| 125 | +Store URL Access Interfaces |
| 126 | +k8s admin/cos.parca admin parca_store:parca-store-endpoint |
| 127 | +``` |
| 128 | + |
| 129 | +Next, consume this offer so that is reachable from the current machine model: |
| 130 | + |
| 131 | +``` |
| 132 | +juju consume k8s:admin/cos.parca |
| 133 | +``` |
| 134 | + |
| 135 | +Finally, relate Charmed Parca Agent with the consumed offer endpoint: |
| 136 | +``` |
| 137 | +juju integrate parca-agent parca |
| 138 | +``` |
| 139 | + |
| 140 | +### Polar Signals Cloud |
| 141 | + |
| 142 | +This section goes through the steps for enabling profiling with Polar Signals Cloud (PSC) as the backend. |
| 143 | + |
| 144 | +[note] |
| 145 | +With PSC, `cos-lite` and `parca-k8s` are not required. This section goes through the recommended setup, where `polar-signals-cloud-integrator` is deployed in the same model as `postgresql`, and `parca-agent` is used to relay traffic to PSC. |
| 146 | + |
| 147 | +If you would like to use `parca-k8s` to relay traffic to PSC instead, refer to [Steps 1 and 2](#1-deploy-cos-lite-and-parca-k8s) in the Charmed Parca K8s section. |
| 148 | +[/note] |
| 149 | + |
| 150 | +#### 1. Deploy and integrate `parca-agent` with `postgresql` |
| 151 | + |
| 152 | +In the machine model where PostgreSQL is deployed, deploy `parca-agent` and integrate it with `postgresql`: |
| 153 | + |
| 154 | +``` |
| 155 | +juju deploy parca-agent --channel latest/edge |
| 156 | +juju integrate postgresql parca-agent |
| 157 | +``` |
| 158 | + |
| 159 | +#### 2. Integrate `parca-agent` with `polar-signals-cloud-integrator` |
| 160 | + |
| 161 | +Follow the guide [How to integrate with Polar Signals Cloud](https://discourse.charmhub.io/t/charmed-parca-docs-how-to-integrate-with-polar-signals-cloud/16559). |
| 162 | + |
| 163 | + |
| 164 | +## View profiles |
| 165 | + |
| 166 | +After the backend setup is complete, the profiles for the machines where the PostgreSQL units are running will be accessible from the Parca web interface. |
| 167 | + |
| 168 | +If you are running Charmed Parca K8s, you can also access the link for Parca's web interface from COS catalogue (`juju run traefik/0 show-proxied-endpoints` in the K8s model where `cos-lite` is deployed). |
| 169 | + |
| 170 | + |
| 171 | + |
| 172 | +Furthermore, if you have `cos-lite` deployed, you can use Grafana to explore profiles under the `Explore` section with `parca-k8s` as the data source. |
| 173 | + |
| 174 | + |
0 commit comments