At the time of writing, Fargate does not support
Daemontasks (see this tracking issue).
Furthermore, Fargate does not allow
"pidMode": "host"in the task definition (see documentation of
pidModehere). Host PID is required for gProfiler to be able to profile processes running in other containers (in case of Fargate, other containers under the same
So in order to deploy gProfiler, we need to modify a container definition to include running gProfiler alongside the actual application. This can be done with the following steps:
- 1.Modify the
entryPointparameters of your entry in the
containerDefinitionsarray. The new command should include the downloading of gProfiler and the execution of it in the background, and entryPoint will be
["/bin/bash"].For example, if your
["python", "/path/to/my/app.py"], we will now change it to:
["-c", "(wget https://github.com/Granulate/gprofiler/releases/latest/download/gprofiler -O /tmp/gprofiler; chmod +x /tmp/gprofiler; /tmp/gprofiler -cu --token <TOKEN> --service-name <SERVICE NAME> --disable-pidns-check --perf-mode none) & python /path/to/my/app.py"].
This new command will start the downloading of gProfiler in the background, then run your application. Make sure to JSON-escape any characters in your command line! For example,
"are replaced with
Additionally, we will set
["/bin/bash"]. If you had used
entryPointprior to incorporating gProfiler, make sure to use it in the new
--disable-pidns-checkis required because, well, we won't run in init PID NS :)
gProfiler and its installation process will send the outputs to your container's
stderr. After verifying that everything works, you can append
> /dev/null 2>&1to the gProfiler command parenthesis (in this example, before the
& python...) to prevent it from spamming your container logs.
This requires your image to have
wgetinstalled. You can make sure
wgetis installed, or substitute the wget command with:
curl -SL https://github.com/Granulate/gprofiler/releases/latest/download/gprofiler --output /tmp/gprofiler
... or any other HTTP-downloader you wish.
linuxParametersto the container definition (this goes directly in your entry in
sys_ptraceis required by various profilers, and Fargate by default denies it for containers.
Alternatively, you can download gProfiler in your
Dockerfileto avoid having to download it every time in run-time. Then you just need to invoke it upon container start-up.