Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Blackfire agent and full support #2448

Merged
merged 13 commits into from
Jan 14, 2021
1 change: 1 addition & 0 deletions .spellcheckwordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ bashrc
bcmath
be
belonging
blackfire
breakpoint
browser
busybox
Expand Down
60 changes: 60 additions & 0 deletions cmd/ddev/cmd/global_dotddev_assets/commands/web/blackfire
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

#ddev-generated: Remove this line to take over this script
## Description: Enable or disable blackfire.io profiling
## Usage: blackfire start|stop|on|off|enable|disable|true|false|status
## Example: "ddev blackfire" (default is "on"), "ddev blackfire off", "ddev blackfire on", "ddev blackfire status"

function enable {
if [ -z ${BLACKFIRE_SERVER_ID} ] || [ -z ${BLACKFIRE_SERVER_TOKEN} ]; then
lolautruche marked this conversation as resolved.
Show resolved Hide resolved
echo "BLACKFIRE_SERVER_ID and BLACKFIRE_SERVER_TOKEN environment variables must be set" >&2
echo "See docs for how to set in global or project config" >&2
echo "For example, ddev config global --web-env=BLACKFIRE_SERVER_ID=<id>,BLACKFIRE_SERVER_TOKEN=<token>"
exit 1
fi
phpenmod blackfire
killall -HUP php-fpm
killall blackfire-agent 2>/dev/null
nohup blackfire-agent --log-level=4 >/tmp/blackfire_nohup.out 2>&1 &
lolautruche marked this conversation as resolved.
Show resolved Hide resolved
sleep 1
echo "Enabled blackfire PHP extension and started blackfire-agent"
exit
}
function disable {
phpdismod blackfire
killall -HUP php-fpm
killall blackfire-agent 2>/dev/null
echo "Disabled blackfire PHP extension and stopped blackfire-agent"
exit
}


if [ $# -eq 0 ] ; then
enable
fi

case $1 in
on|true|enable|start)
disable_xdebug
enable
;;
off|false|disable|stop)
disable
;;
status)
php --version | grep "with blackfire" >/dev/null 2>&1
phpstatus=$?
killall -0 blackfire-agent 2>/dev/null
agentstatus=$?
if [ ${phpstatus} -eq 0 ]; then echo "blackfire PHP extension enabled"; else echo "blackfire PHP extension disabled"; fi
if [ ${agentstatus} -eq 0 ]; then echo "blackfire agent running"; else echo "blackfire agent not running"; fi
lolautruche marked this conversation as resolved.
Show resolved Hide resolved

if [ ${phpstatus} -eq 0 ]; then printf "probe version %s\n" "$(php -v | awk -F '[ ,\~]+' '/blackfire/{ print $4; }')"; fi
printf "agent version %s\n" "$(blackfire-agent -v | awk '{print $2;}')"
printf "cli version %s\n" "$(blackfire version | awk '{print $2;}')"
;;

*)
echo "Invalid argument: $1"
;;
esac
2 changes: 2 additions & 0 deletions cmd/ddev/cmd/packrd/packed-packr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions containers/ddev-webserver/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ RUN mkdir /tmp/ddev && \
MAILHOG_ARCH="linux_amd64"' > /tmp/ddev/vars; \
fi

# blackfire-php is not available for arm64 (yet)
RUN if [[ $TARGETPLATFORM != "linux/arm64" ]]; then \
DEBIAN_FRONTEND=noninteractive apt-get -qq install -o Dpkg::Options::="--force-confold" blackfire-php -y --allow-unauthenticated; \
fi
RUN DEBIAN_FRONTEND=noninteractive apt-get -qq install -o Dpkg::Options::="--force-confold" --no-install-recommends --no-install-suggests -y \
blackfire-agent \
blackfire-php \
fontconfig \
gettext \
git \
Expand Down Expand Up @@ -121,7 +119,7 @@ RUN mkdir -p /etc/nginx/sites-enabled /var/log/apache2 /var/run/apache2 /var/lib
RUN chmod -R 777 /var/log

# we need to create the /var/cache/linux and /var/lib/nginx manually for the arm64 image and chmod them, please don't remove them!
RUN mkdir -p /mnt/ddev-global-cache/mkcert /run/php /var/cache/nginx /var/lib/nginx && chmod -R ugo+rw /mnt/ddev-global-cache/
RUN mkdir -p /mnt/ddev-global-cache/mkcert /run/{php,blackfire} /var/cache/nginx /var/lib/nginx && chmod -R ugo+rw /mnt/ddev-global-cache/

RUN chmod -R ugo+w /usr/sbin /usr/bin /etc/nginx /var/cache/nginx /var/lib/nginx /run /var/www /etc/php/*/*/conf.d/ /var/lib/php/modules /etc/alternatives /usr/lib/node_modules /etc/php /etc/apache2 /var/log/apache2/ /var/run/apache2 /var/lib/apache2 /mnt/ddev-global-cache/*

Expand All @@ -133,6 +131,8 @@ RUN touch /var/log/nginx/error.log /var/log/nginx/access.log /var/log/php-fpm.lo
RUN a2dismod mpm_event
RUN a2enmod ssl headers expires

RUN phpdismod blackfire

# scripts added last because they're most likely place to make changes, speeds up build
ADD ddev-webserver-base-scripts /
RUN chmod ugo+x /start.sh /healthcheck.sh
Expand Down
1 change: 1 addition & 0 deletions containers/ddev-webserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This is a Dockerfile to build a container image for ddev's web container.
* [Composer](https://getcomposer.org/) (from the production container)
* [Drush](http://www.drush.org) (from the production container)
* [WP-CLI](http://www.wp-cli.org) (from the production container)
* [Blackfire CLI](https://blackfire.io/docs/cookbooks/profiling-http-via-cli)
* [Mailhog](https://github.com/mailhog/MailHog)
* npm
* yarn
Expand Down
26 changes: 26 additions & 0 deletions docs/users/blackfire-profiling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Profiling with Blackfire.io

DDEV-Local has built-in [blackfire.io](https://blackfire.io) integration.

### Basic Blackfire Usage (Using Browser Plugin)

1. Create an account on [blackfire.io](https://blackfire.io)
2. Install the Chrome or Firefox [browser plugin](https://blackfire.io/docs/profiling-cookbooks/profiling-http-via-browser).
3. Get the Server ID, Server Token, Client ID, and Client Token from your Account->Credentials or environment on blackfire.io.
4. Configure ddev with the credentials, `ddev config global --web-environment="BLACKFIRE_SERVER_ID=<id>,BLACKFIRE_SERVER_TOKEN=<token>,BLACKFIRE_CLIENT_ID=<id>,BLACKFIRE_CLIENT_TOKEN=<token>"`. It's easiest to do this globally, but you can do the same thing at the project-level using `ddev config --web-environment`. (Note that you can also just manually edit the relevant config file.)
5. `ddev start`
6. `ddev blackfire on` to enable, `ddev blackfire off` to disable, `ddev blackfire status` to see status.
7. With Blackfire enabled, you can use the [browser extension](https://blackfire.io/docs/profiling-cookbooks/profiling-http-via-browser).

### Profiling with the Blackfire CLI

The Blackfire CLI is built into the web container.

1. `ddev config global --web-environment="BLACKFIRE_SERVER_ID=<id>,BLACKFIRE_SERVER_TOKEN=<token>,BLACKFIRE_CLIENT_ID=<id>,BLACKFIRE_CLIENT_TOKEN=<token>"`
2. `ddev start`
3. Examples of using the Blackfire CLI:

* `ddev exec blackfire curl https://<yoursite>.ddev.site`
* `ddev exec blackfire drush st`
* `ddev exec blackfire curl https://<yoursite>.ddev.site`
* `ddev ssh` and then use the Blackfire CLI as described in [Profiling HTTP Requests with the CLI](https://blackfire.io/docs/profiling-cookbooks/profiling-http-via-cli).
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pages:
- 'ddev Hooks': 'users/extending-commands.md'
- 'Using Developer Tools with ddev': 'users/developer-tools.md'
- 'PHP Step Debugging': 'users/step-debugging.md'
- 'Profiling with Blackfire': 'users/blackfire-profiling.md'
- 'Troubleshooting': 'users/troubleshooting.md'
- 'Docker Installation': 'users/docker_installation.md'
- 'Performance': 'users/performance.md'
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var DockerComposeFileFormatVersion = "3.6"
var WebImg = "drud/ddev-webserver"

// WebTag defines the default web image tag for drud dev
var WebTag = "20210107_hardened_drush" // Note that this can be overridden by make
var WebTag = "20210111_lolautruche_blackfire" // Note that this can be overridden by make

// DBImg defines the default db image used for applications.
var DBImg = "drud/ddev-dbserver"
Expand Down