-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #488 from heroku/blackfire-agent-package
Blackfire: tests, agent v2, separate agent package, blackfireio/integration-heroku buildpack support
- Loading branch information
Showing
20 changed files
with
224 additions
and
93 deletions.
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
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 |
---|---|---|
|
@@ -6,3 +6,4 @@ gem 'rspec-expectations' | |
gem 'sem_version' | ||
gem "parallel_tests" | ||
gem "rake" | ||
gem "ansi" |
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
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
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
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,62 @@ | ||
#!/usr/bin/env bash | ||
# Build Path: /app/.heroku/php | ||
|
||
OUT_PREFIX=$1 | ||
|
||
# fail hard | ||
set -o pipefail | ||
# fail harder | ||
set -eu | ||
|
||
source $(dirname $BASH_SOURCE)/_util/include/manifest.sh | ||
|
||
bin_dir=${OUT_PREFIX}/bin | ||
|
||
dep_formula=${0#$WORKSPACE_DIR/} | ||
dep_name=$(basename $BASH_SOURCE) | ||
dep_version=${dep_formula#"${dep_name}-"} | ||
dep_package=${dep_name}-${dep_version} | ||
dep_manifest=${dep_package}.composer.json | ||
|
||
echo "-----> Packaging ${dep_package}..." | ||
echo "FYI: Blackfire API reports latest version as $(curl -A "Heroku" -I -L -s https://blackfire.io/api/v1/releases/cli/linux/amd64 | grep -i 'X-Blackfire-Release-Version: ' | sed "s%X-Blackfire-Release-Version: %%i" | sed s%.$%%)" | ||
|
||
curl -L "https://packages.blackfire.io/binaries/blackfire/${dep_version}/blackfire-linux_amd64.tar.gz" | tar xz | ||
|
||
mkdir -p ${OUT_PREFIX}/var/blackfire/run | ||
mkdir -p ${bin_dir} | ||
chmod +x blackfire | ||
mv blackfire ${bin_dir}/ | ||
|
||
find ${OUT_PREFIX} -type f \( -executable -o -name '*.a' \) -exec sh -c "file -i '{}' | grep -Eq 'application/x-(archive|executable|sharedlib); charset=binary'" \; -print | xargs strip --strip-unneeded | ||
|
||
# these env var defaults we want both during a build (used in the INI futher below) and at boot time | ||
tee ${OUT_PREFIX}/bin/export.blackfire.sh > ${OUT_PREFIX}/bin/profile.blackfire.sh <<'EOF' | ||
# hard-code these two; no need for users to override them | ||
export BLACKFIRE_LOG_FILE=stderr | ||
export BLACKFIRE_AGENT_SOCKET="unix:///app/.heroku/php/var/blackfire/run/agent.sock" | ||
EOF | ||
|
||
# PATH should be available both for subsequent buildpacks and on boot | ||
cat >> ${OUT_PREFIX}/bin/export.blackfire.sh <<'EOF' | ||
export PATH="/app/.heroku/php/bin:$PATH" | ||
EOF | ||
|
||
# gets sourced on dyno boot | ||
cat >> ${OUT_PREFIX}/bin/profile.blackfire.sh <<'EOF' | ||
export PATH="$HOME/.heroku/php/bin:$PATH" | ||
# we need no config, as everything will be read from the environment | ||
# exception is BLACKFIRE_SOCKET, which we pass in explicitly; the extension uses BLACKFIRE_AGENT_SOCKET instead | ||
/app/.heroku/php/bin/blackfire agent:start --config="/dev/null" --socket="${BLACKFIRE_AGENT_SOCKET}" & | ||
EOF | ||
|
||
MANIFEST_REQUIRE="${MANIFEST_REQUIRE:-"{}"}" | ||
MANIFEST_CONFLICT="${MANIFEST_CONFLICT:-"{}"}" | ||
MANIFEST_REPLACE="${MANIFEST_REPLACE:-"{}"}" | ||
MANIFEST_PROVIDE="${MANIFEST_PROVIDE:-"{}"}" | ||
MANIFEST_EXTRA="${MANIFEST_EXTRA:-"{\"export\":\"bin/export.blackfire.sh\",\"profile\":\"bin/profile.blackfire.sh\"}"}" | ||
|
||
python $(dirname $BASH_SOURCE)/_util/include/manifest.py "heroku-sys-program" "heroku-sys/${dep_name}" "$dep_version" "${dep_formula}.tar.gz" "$MANIFEST_REQUIRE" "$MANIFEST_CONFLICT" "$MANIFEST_REPLACE" "$MANIFEST_PROVIDE" "$MANIFEST_EXTRA" > $dep_manifest | ||
|
||
print_or_export_manifest_cmd "$(generate_manifest_cmd "$dep_manifest")" |
File renamed without changes.
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
File renamed without changes.
4 changes: 0 additions & 4 deletions
4
support/build/extensions/no-debug-non-zts-20170718/blackfire-1.54.0
This file was deleted.
Oops, something went wrong.
File renamed without changes.
4 changes: 0 additions & 4 deletions
4
support/build/extensions/no-debug-non-zts-20180731/blackfire-1.54.0
This file was deleted.
Oops, something went wrong.
File renamed without changes.
4 changes: 0 additions & 4 deletions
4
support/build/extensions/no-debug-non-zts-20190902/blackfire-1.54.0
This file was deleted.
Oops, something went wrong.
File renamed without changes.
4 changes: 0 additions & 4 deletions
4
support/build/extensions/no-debug-non-zts-20200930/blackfire-1.54.0
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
support/build/extensions/no-debug-non-zts-20200930/blackfire-1.62.0
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,4 @@ | ||
#!/usr/bin/env bash | ||
# Build Path: /app/.heroku/php | ||
|
||
source $(dirname $0)/../no-debug-non-zts-20160303/blackfire |
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,113 @@ | ||
require_relative "spec_helper" | ||
require 'ansi/core' | ||
|
||
describe "A PHP application using ext-blackfire" do | ||
["blackfireio/integration-heroku", "our blackfire package"].each do |agent| | ||
context "and #{agent}" do | ||
["explicitly", "without BLACKFIRE_SERVER_TOKEN", "with default BLACKFIRE_LOG_LEVEL", "implicitly"].each do |mode| | ||
next if mode == "without BLACKFIRE_SERVER_TOKEN" and agent == "blackfireio/integration-heroku" # blackfire buildpack would error on invalid credentials | ||
context "#{mode}" do | ||
before(:all) do | ||
buildpacks = [:default] | ||
buildpacks.unshift("https://github.com/blackfireio/integration-heroku") if agent == "blackfireio/integration-heroku" | ||
credentials = { | ||
"BLACKFIRE_CLIENT_ID" => ENV["BLACKFIRE_CLIENT_ID"], | ||
"BLACKFIRE_CLIENT_TOKEN" => ENV["BLACKFIRE_CLIENT_TOKEN"], | ||
"BLACKFIRE_SERVER_ID" => ENV["BLACKFIRE_SERVER_ID"], | ||
"BLACKFIRE_SERVER_TOKEN" => ENV["BLACKFIRE_SERVER_TOKEN"], | ||
} | ||
if mode == "explicitly" | ||
# ext-blackfire is listed as a dependency in composer.json, and a BLACKFIRE_SERVER_TOKEN/ID is provided | ||
@app = new_app_with_stack_and_platrepo('test/fixtures/bootopts', | ||
buildpacks: buildpacks, | ||
config: credentials.merge({ "BLACKFIRE_LOG_LEVEL" => "4"}), | ||
before_deploy: -> { system("composer require --quiet --ignore-platform-reqs 'php:*' 'ext-blackfire:*'") or raise "Failed to require PHP/ext-blackfire" }, | ||
run_multi: true | ||
) | ||
elsif mode == "without BLACKFIRE_SERVER_TOKEN" | ||
# ext-blackfire is listed as a dependency in composer.json, but a BLACKFIRE_SERVER_TOKEN/ID is missing | ||
@app = new_app_with_stack_and_platrepo('test/fixtures/bootopts', | ||
buildpacks: buildpacks, | ||
config: { "BLACKFIRE_LOG_LEVEL" => "4" }, | ||
before_deploy: -> { system("composer require --quiet --ignore-platform-reqs 'php:*' 'ext-blackfire:*'") or raise "Failed to require PHP/ext-blackfire" }, | ||
run_multi: true | ||
) | ||
elsif mode == "with default BLACKFIRE_LOG_LEVEL" | ||
# ext-blackfire is listed as a dependency in composer.json, and BLACKFIRE_LOG_LEVEL is the default (1=error) | ||
@app = new_app_with_stack_and_platrepo('test/fixtures/bootopts', | ||
buildpacks: buildpacks, | ||
config: credentials, | ||
before_deploy: -> { system("composer require --quiet --ignore-platform-reqs 'php:*' 'ext-blackfire:*'") or raise "Failed to require PHP/ext-blackfire" }, | ||
run_multi: true | ||
) | ||
else | ||
# a BLACKFIRE_SERVER_TOKEN/ID triggers the automatic installation of ext-blackfire at the end of the build | ||
@app = new_app_with_stack_and_platrepo('test/fixtures/bootopts', | ||
buildpacks: buildpacks, | ||
config: credentials.merge({ "BLACKFIRE_LOG_LEVEL" => "4"}), | ||
before_deploy: -> { system("composer require --quiet --ignore-platform-reqs 'php:*'") or raise "Failed to require PHP version" }, | ||
run_multi: true | ||
) | ||
end | ||
@app.deploy | ||
end | ||
after(:all) do | ||
@app.teardown! | ||
end | ||
|
||
it "installs Blackfire" do | ||
if agent == "our blackfire package" | ||
expect(@app.output).not_to match(/Blackfire CLI version \d+\.\d+\.\d+ detected/) | ||
else | ||
expect(@app.output).to match(/Blackfire CLI version \d+\.\d+\.\d+ detected/) | ||
end | ||
|
||
if mode == "implicitly" | ||
expect(@app.output).to match(/Blackfire detected, installed ext-blackfire/) # auto-install at the end | ||
else | ||
if agent == "our blackfire package" | ||
expect(@app.output).to match(/- blackfire/) | ||
else | ||
expect(@app.output).not_to match(/- blackfire/) | ||
end | ||
|
||
expect(@app.output).to match(/- ext-blackfire/) | ||
|
||
if mode == "with default BLACKFIRE_LOG_LEVEL" | ||
expect(@app.output).not_to match(/\[Debug\] APM: disabled/) # this message should not occur if defaults are applied correctly at build time | ||
else | ||
expect(@app.output).to match(/\[Debug\] APM: disabled/) # extension disabled during builds | ||
end | ||
end | ||
end | ||
|
||
['heroku-php-apache2', 'heroku-php-nginx'].each do |script| | ||
# without log level info, we will not see the messages we're using to test any behavior | ||
# but we need to assert that no info is printed at all in this case | ||
it "does not output info messages during startup with #{script}", if: mode == "with default BLACKFIRE_LOG_LEVEL" do | ||
out = @app.run("#{script} -F conf/fpm.include.broken") # prevent FPM from starting up using an invalid config, that way we don't have to wrap the server start in a `timeout` call | ||
expect(out).not_to match(/\[Info\]/) # this message should not occur if defaults are applied correctly | ||
end | ||
it "launches blackfire CLI, but not the extension, during boot preparations, with #{script}", if: mode != "with default BLACKFIRE_LOG_LEVEL" do | ||
out = @app.run("#{script} -F conf/fpm.include.broken") # prevent FPM from starting up using an invalid config, that way we don't have to wrap the server start in a `timeout` call | ||
|
||
out_before_fpm, out_after_fpm = out.unansi.split("Starting php-fpm", 2) | ||
|
||
expect(out_before_fpm).to match(/blackfire Reading agent configuration file/) # that is the very first thing the agent prints | ||
if mode == "without BLACKFIRE_SERVER_TOKEN" | ||
expect(out_before_fpm).to match(/The server ID parameter is not set/) | ||
else | ||
expect(out.unansi).to match(/blackfire Waiting for new connection/) # match on whole output in case it takes a bit longer to start <up></up> | ||
end | ||
expect(out_before_fpm).not_to match(/\[Warning\] APM: Cannot start/) # extension does not attempt to start on `php-fpm -i` during boot | ||
expect(out_before_fpm).to match(/\[Debug\] APM: disabled/) # blackfire reports itself disabled (by us) during the various boot prep PHP invocations | ||
|
||
expect(out_after_fpm).not_to match(/\[Debug\] APM: disabled/) | ||
expect(out_after_fpm).to match(/\[Info\] APCu extension is not loaded/) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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
Oops, something went wrong.