Skip to content

Commit

Permalink
Support custom ini names in installer (#1846)
Browse files Browse the repository at this point in the history
Fixes #1833.

Also update randomized tests instructions and slightly lower the recursion depth for internal-api-stress-test.php

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
  • Loading branch information
bwoebi authored Jan 11, 2023
1 parent 0dc0b2a commit 496cc87
Show file tree
Hide file tree
Showing 36 changed files with 148 additions and 56 deletions.
19 changes: 12 additions & 7 deletions datadog-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ function install($options)
// Writing the ini file
if ($phpProperties[INI_SCANDIR]) {
$iniFileName = '98-ddtrace.ini';
// Search for pre-existing files with extension = ddtrace.so to avoid conflicts
// See issue https://github.com/DataDog/dd-trace-php/issues/1833
foreach (scandir($phpProperties[INI_SCANDIR]) as $ini) {
$path = "{$phpProperties[INI_SCANDIR]}/$ini";
if (is_file($path)) {
if (preg_match('(^\s*extension\s*=.+ddtrace\.so)m', file_get_contents($path))) {
$iniFileName = $ini;
}
}
}

$iniFilePaths = [$phpProperties[INI_SCANDIR] . '/' . $iniFileName];

if (\strpos($phpProperties[INI_SCANDIR], '/cli/conf.d') !== false) {
Expand Down Expand Up @@ -270,7 +281,7 @@ function install($options)
*/
execute_or_exit(
'Impossible to update the INI settings file.',
"sed -i 's@extension \?= \?.*ddtrace.*\(.*\)@extension = ddtrace.so@g' "
"sed -i 's@ \?;\? \?extension \?= \?.*ddtrace.*\(.*\)@extension = ddtrace.so@g' "
. escapeshellarg($iniFilePath)
);

Expand Down Expand Up @@ -308,12 +319,6 @@ function install($options)

// phpcs:disable Generic.Files.LineLength.TooLong
if ($shouldInstallAppsec) {
// Appsec crashes with missing symbols if tracing is not loaded
execute_or_exit(
'Impossible to update the INI settings file.',
"sed -i 's@ \?; \?extension \?= \?ddtrace.so@extension = ddtrace.so@g' "
. escapeshellarg($iniFilePath)
);
execute_or_exit(
'Impossible to update the INI settings file.',
"sed -i 's@ \?; \?extension \?= \?ddappsec.so@extension = ddappsec.so@g' "
Expand Down
1 change: 1 addition & 0 deletions dockerfiles/verify_packages/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ test_first_install.sh \
test_install_no_ldconfig_in_path.sh \
test_install_without_scan_dir.sh \
test_install_add_missing_ini_settings.sh \
test_install_custom_ini_name.sh \
test_install_custom_installation_directory.sh \
test_install_custom_installation_root.sh \
test_install_non_root_user.sh \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apk add php7 php7-json libcurl libexecinfo php7-openssl
assert_no_ddtrace

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php
assert_ddtrace_version "${new_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apk add php7 php7-json libcurl libexecinfo curl
assert_no_ddtrace

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php
assert_ddtrace_version "${new_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apk add php7 curl
assert_no_ddtrace

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"

set +e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apk add php7
assert_no_ddtrace

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"

set +e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ set -e

. "$(dirname ${0})/utils.sh"

if ! is_appsec_installable; then
exit 0
fi

# Initially no ddtrace
assert_no_ddtrace

# Install using the php installer
new_version="0.75.0"
new_version="0.79.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php

assert_ddtrace_version "${new_version}"
assert_appsec_version 0.3.2
assert_appsec_version 0.4.0
assert_appsec_disabled

assert_file_exists "$(get_php_extension_dir)"/ddappsec.so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ set -e

. "$(dirname ${0})/utils.sh"

if ! is_appsec_installable; then
exit 0
fi

# Initially no ddtrace
assert_no_ddtrace

# Install using the php installer
new_version="0.75.0"
new_version="0.79.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php --enable-appsec
assert_ddtrace_version "${new_version}"
assert_appsec_version 0.3.2
assert_appsec_version 0.4.0
assert_appsec_enabled

assert_file_exists "$(get_php_extension_dir)"/ddappsec.so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e
assert_no_ddtrace

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php
assert_ddtrace_version "${new_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apk add php7 php7-json libcurl libexecinfo curl
assert_no_ddtrace

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php
assert_ddtrace_version "${new_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sudo chmod a+w ./build/packages/*
assert_no_ddtrace

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php
assert_ddtrace_version "${new_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ switch-php debug-zts-asan
assert_no_ddtrace

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"

set +e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e
assert_no_ddtrace

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php
assert_ddtrace_version "${new_version}"
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/verify_packages/installer/test_fpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension_dir="$(php -i | grep '^extension_dir' | awk '{ print $NF }')"
ini_dir="$(php -i | grep '^Scan' | awk '{ print $NF }')"

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php-fpm
assert_ddtrace_version "${new_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e
assert_no_ddtrace

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php
assert_ddtrace_version "${new_version}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env sh

set -e

. "$(dirname ${0})/utils.sh"

# Initially no ddtrace
assert_no_ddtrace

# Install using the php installer
new_version="0.78.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php
assert_ddtrace_version "${new_version}"

ini_file="$(get_php_conf_dir)/98-ddtrace.ini"
custom_ini_file="$(get_php_conf_dir)/40-ddtrace.ini"

# remove an INI to see that indeed that ini is changed
assert_file_contains "${ini_file}" 'datadog.version'
sed -i 's/datadog\.version.*//g' "${ini_file}"
assert_file_not_contains "${ini_file}" 'datadog.version'

mv "$ini_file" "$custom_ini_file"

php ./build/packages/datadog-setup.php --php-bin php

assert_file_contains "${custom_ini_file}" 'datadog.version'

assert_file_not_exists "${ini_file}"

assert_request_init_hook_exists
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e
assert_no_ddtrace

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php --install-dir /custom/dd
assert_ddtrace_version "${new_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e
assert_no_ddtrace

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"

# Verify that wrong installation dir (e.g. /) does not delete all files in root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e
assert_no_ddtrace

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"

PHP=$(which php)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -e
. "$(dirname ${0})/utils.sh"

# Install using the php installer
new_version="0.75.0"
new_version="0.79.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin=all

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ assert_no_ddtrace
useradd -m datadog -p datadog
usermod -a -G datadog datadog

new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"

set +e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ if [ "$CIRCLECI" = "true" ]; then
exit 0
fi

new_version="0.74.0"
uname=$(uname -a)
arch=$(if [ -z "${uname##*arm*}" ] || [ -z "${uname##*aarch*}" ]; then echo aarch64; else echo x86_64; fi)

new_version="0.78.0"
generate_installers "${new_version}"
repo_url=${DD_TEST_INSTALLER_REPO:-"https://github.com/DataDog/dd-trace-php"}
curl -L -o /tmp/downloaded.tar.gz "${repo_url}/releases/download/${new_version}/dd-library-php-${new_version}-x86_64-linux-gnu.tar.gz"
curl -L -o /tmp/downloaded.tar.gz "${repo_url}/releases/download/${new_version}/dd-library-php-${new_version}-${arch}-linux-gnu.tar.gz"

# Install using the php installer
php ./build/packages/datadog-setup.php --php-bin php --file /tmp/downloaded.tar.gz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e
assert_no_ddtrace

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension_dir="$(php -i | grep '^extension_dir' | awk '{ print $NF }')"
ini_dir="$(php -i | grep '^Scan' | awk '{ print $NF }')"

# Install using the php installer
new_version="0.75.0"
new_version="0.79.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ set -e

. "$(dirname ${0})/utils.sh"

if ! is_appsec_installable; then
exit 0
fi

# Initially no ddtrace
assert_no_ddtrace

extension_dir="$(php -i | grep '^extension_dir' | awk '{ print $NF }')"
ini_dir="$(php -i | grep '^Scan' | awk '{ print $NF }')"

# Install using the php installer
new_version="0.75.0"
new_version="0.79.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php

Expand All @@ -22,7 +26,7 @@ assert_no_appsec
assert_no_profiler

php ./build/packages/datadog-setup.php --enable-appsec --php-bin php
assert_appsec_version 0.3.2
assert_appsec_version 0.4.0
assert_appsec_enabled

# Appsec requires ddtrace to be enabled, otherwise it crashes with missing symbols.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ set -e

. "$(dirname ${0})/utils.sh"

# 0.75.0 doesn't exist on arm
uname=$(uname -a)
if [ -z "${uname##*arm*}" ] || [ -z "${uname##*aarch*}" ]; then
exit 0
fi

# Initially no ddtrace
assert_no_ddtrace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SCANDIR
chmod +x $(dirname "$(which php)")/php-without-scan-dir

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php-without-scan-dir
assert_ddtrace_version "${new_version}" php-without-scan-dir
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e
assert_no_ddtrace

# Install using the php installer
new_version="0.74.0"
new_version="0.78.0"
generate_installers "${new_version}"
php ./build/packages/datadog-setup.php --php-bin php
assert_ddtrace_version "${new_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@ set -e

. "$(dirname ${0})/utils.sh"

uname=$(uname -a)
arch=$(if [ -z "${uname##*arm*}" ] || [ -z "${uname##*aarch*}" ]; then echo aarch64; else echo x86_64; fi)

# Initially no ddtrace
assert_no_ddtrace

# Install using the php installer
trace_version=$(parse_trace_version)
profiling_version=$(parse_profiling_version)
file="./build/packages/dd-library-php-${trace_version}-${arch}-linux-gnu.tar.gz"
if ! [ -f $file ]; then
trace_version="0.79.0"
profiling_version="0.10.0"
fi
generate_installers "$trace_version"
php ./build/packages/datadog-setup.php --php-bin php --enable-profiling \
--file "./build/packages/dd-library-php-${trace_version}-x86_64-linux-gnu.tar.gz"
$(! [ -f $file ] || echo --file "$file")
assert_ddtrace_version "${trace_version}"

assert_file_exists "$(get_php_extension_dir)"/datadog-profiling.so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e
assert_no_ddtrace

# Install using the php installer
new_version="0.75.0"
new_version="0.79.0"
generate_installers "${new_version}"

set +e
Expand Down
Loading

0 comments on commit 496cc87

Please sign in to comment.