Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/root_span_for_PHP_lifecycle_re…
Browse files Browse the repository at this point in the history
…quest' into root_span_for_PHP_lifecycle_request
  • Loading branch information
SergeyKleyman committed May 28, 2024
2 parents 51b96d5 + 98e9363 commit dd9bad8
Show file tree
Hide file tree
Showing 78 changed files with 440 additions and 119 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ jobs:
run: |
uname -a
echo "Detected CPUs: $(nproc)"
echo "User: ${CURRENT_UID}:${CURRENT_GID}"
echo "User: $(id -u):$(id -g)}"
echo "PWD: ${PWD}"
echo "Arch: ${BUILD_ARCHITECTURE}"
docker run --rm -t -u ${CURRENT_UID}:${CURRENT_GID} -v ${PWD}:/source -w /source/prod/native elasticobservability/apm-agent-php-dev:native-build-gcc-12.2.0-${BUILD_ARCHITECTURE}-0.0.2 sh -c "cmake --preset ${BUILD_ARCHITECTURE}-release && cmake --build --preset ${BUILD_ARCHITECTURE}-release && ctest --preset ${BUILD_ARCHITECTURE}-release --verbose"
docker run --rm -t -u : -v ${PWD}:/source -w /source/prod/native elasticobservability/apm-agent-php-dev:native-build-gcc-12.2.0-${BUILD_ARCHITECTURE}-0.0.2 sh -c "cmake --preset ${BUILD_ARCHITECTURE}-release && cmake --build --preset ${BUILD_ARCHITECTURE}-release && ctest --preset ${BUILD_ARCHITECTURE}-release --verbose"
- uses: actions/upload-artifact@v4
with:
name: build-native-${{ matrix.arch }}
path: |
prod/native/_build/${{ matrix.arch }}-release/ext/elastic_apm*.so
prod/native/_build/${{ matrix.arch }}-release/ext/elastic_apm*.debug
prod/native/_build/${{ matrix.arch }}-release/loader/code/elastic_apm_loader.so
prod/native/_build/${{ matrix.arch }}-release/loader/code/elastic_apm_loader.debug
prod/native/_build/${{ matrix.arch }}-release/extension/code/elastic_otel_php*.so
prod/native/_build/${{ matrix.arch }}-release/extension/code/elastic_otel_php*.debug
prod/native/_build/${{ matrix.arch }}-release/loader/code/elastic_otel_php_loader.so
prod/native/_build/${{ matrix.arch }}-release/loader/code/elastic_otel_php_loader.debug
5 changes: 4 additions & 1 deletion .github/workflows/build-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ jobs:
echo "Creating debug symbols artifacts"
DBGSYM="${PWD}/build/packages/elastic-otel-php-debugsymbols-${{ matrix.arch }}.tar.gz"
tar -czf ${DBGSYM} prod/native/_build/${{ matrix.arch }}-release/loader/code/elastic_apm_loader.debug prod/native/_build/${{ matrix.arch }}-release/ext/*.debug
pushd prod/native/_build/${{ matrix.arch }}-release
tar --transform 's/.*\///g' -zcvf ${DBGSYM} extension/code/*.debug loader/code/*.debug
popd
pushd "${PWD}/build/packages"
md5sum ${DBGSYM} >${DBGSYM}.sha512
popd
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ jobs:
needs:
- build-native
uses: ./.github/workflows/build-packages.yml



tests-phpt:
needs:
- build-native
uses: ./.github/workflows/test-phpt.yml


# The very last job to report whether the Workflow passed.
# This will act as the Branch Protection gatekeeper
Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/test-phpt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---

# Runs the build based on the provided files in test.yml
name: build

on:
workflow_call:
inputs:
build_arch:
required: false
type: string
default: 'x86_64'
workflow_dispatch:
inputs:
build_arch:
type: choice
description: Build architecture
default: 'x86_64'
options:
- all
- x86_64
- arm64

jobs:
setup-build-matrix:
uses: ./.github/workflows/build-arch-matrix-generator.yml
with:
build_arch: ${{ inputs.build_arch }}

test-phpt:
name: test-phpt
runs-on: ubuntu-latest
needs: setup-build-matrix
timeout-minutes: 300
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.setup-build-matrix.outputs.matrix-combinations) }}
env:
BUILD_ARCHITECTURE: ${{ matrix.arch }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: build-native-${{ matrix.arch }}
path: prod/native/_build/${{ matrix.arch }}-release/
- if: ${{ matrix.run_qemu }}
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Run phpt tests
run: |
uname -a
echo "Arch: ${BUILD_ARCHITECTURE}"
pushd prod/native/extension/phpt
mkdir ${PWD}/results
PHP_VERSIONS=( 80 81 82 83 )
for PHP_VERSION in "${PHP_VERSIONS[@]}"
do
./run.sh -b ${BUILD_ARCHITECTURE} -p ${PHP_VERSION} -f ${PWD}/results/phpt-${PHP_VERSION}.tar.gz || TEST_ERROR=1
done
popd
if [ $TEST_ERROR -eq 1 ]; then
echo "Some tests failed"
exit 1
fi
- uses: actions/upload-artifact@v4
if: failure()
with:
name: test-phpt-failures-${{ matrix.arch }}
path: |
prod/native/extension/phpt/results/*
4 changes: 2 additions & 2 deletions packaging/nfpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ homepage: "https://github.com/elastic/elastic-otel-php"
license: "ASL 2.0"
#changelog: "changelog.yaml"
contents:
- src: /source/prod/native/_build/${ELASTIC_OTEL_PHP_PLATFORM}-release/loader/code/elastic_apm_loader.so
- src: /source/prod/native/_build/${ELASTIC_OTEL_PHP_PLATFORM}-release/loader/code/elastic_otel_php_loader.so
dst: /opt/elastic/elastic-otel-php/
expand: true
- src: /source/prod/native/_build/${ELASTIC_OTEL_PHP_PLATFORM}-release/ext/elastic_apm-*.so
- src: /source/prod/native/_build/${ELASTIC_OTEL_PHP_PLATFORM}-release/extension/code/elastic_otel_php_*.so
dst: /opt/elastic/elastic-otel-php/
expand: true
- src: /source/prod/php
Expand Down
6 changes: 1 addition & 5 deletions prod/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ set(_supported_php_versions 80 81 82 83)

function(get_php_api_from_release php_version ret_val)
block(SCOPE_FOR VARIABLES)
set(_php_release_72 20170718)
set(_php_release_73 20180731)
set(_php_release_74 20190902)
set(_php_release_80 20200930)
set(_php_release_81 20210902)
set(_php_release_82 20220829)
Expand Down Expand Up @@ -122,5 +119,4 @@ enable_testing()
add_subdirectory(libcommon)
add_subdirectory(libphpbridge)
add_subdirectory(loader)

add_subdirectory(ext)
add_subdirectory(extension)
2 changes: 2 additions & 0 deletions prod/native/extension/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

add_subdirectory(code)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
AUX_SOURCE_DIRECTORY(. SrcFiles)

foreach(_php_version ${_supported_php_versions})
set (_Target elasticapm_${_php_version})
set (_Target elastic_otel_php_${_php_version})

add_library (${_Target}
SHARED ${SrcFiles}
Expand Down Expand Up @@ -36,17 +36,15 @@ foreach(_php_version ${_supported_php_versions})
libphpbridge_${_php_version}
)

get_php_api_from_release(${_php_version} _ZEND_API_version)

set_target_properties(${_Target}
PROPERTIES OUTPUT_NAME elastic_apm-${_ZEND_API_version}
PROPERTIES OUTPUT_NAME elastic_otel_php_${_php_version}
PREFIX ""
)

set_target_properties(${_Target}
PROPERTIES OUTPUT_NAME elastic_apm-${_ZEND_API_version}
PROPERTIES OUTPUT_NAME elastic_otel_php_${_php_version}
PREFIX ""
DEBUG_SYMBOL_FILE "elastic_apm-${_ZEND_API_version}.debug"
DEBUG_SYMBOL_FILE "elastic_otel_php_${_php_version}.debug"
)

if (RELEASE_BUILD)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions prod/native/extension/phpt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tests/*.sh
tests/*.diff
tests/*.exp
tests/*.log
tests/*.php



94 changes: 94 additions & 0 deletions prod/native/extension/phpt/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash

function show_help {

echo -e "$0 -b build_architecture -p php_version [-t tests]
Arguments description:
-b build_architecture required, architecture of agent so library, f.ex. linux-x86-64
-p php_version PHP version f.ex. 80 or 83
-t tests Tests to run, folder or particular test file name. Default: tests
-f path Generate test failures archive and save it in path
-h print this help
"
}

TESTS_TO_RUN=tests

while getopts "b:p:t:f:h" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
b) BUILD_ARCHITECTURE="${OPTARG}"
;;
p) PHP_VERSION="${OPTARG}"
;;
t) TESTS_TO_RUN="${OPTARG}"
;;
f) TESTS_FAILURES_ARCHIVE="${OPTARG}"
;;
esac
done

if [ -z "${BUILD_ARCHITECTURE}" ] || [ -z "${PHP_VERSION}" ]; then
show_help
exit 1
fi

ELASTIC_AGENT_SO_PATH=${PWD}/../../_build/${BUILD_ARCHITECTURE}-release/extension/code/elastic_otel_php_${PHP_VERSION}.so
if [ ! -f ${ELASTIC_AGENT_SO_PATH} ]; then
echo "Native build not found: '${ELASTIC_AGENT_SO_PATH}'"
exit 1
fi

if [[ ! "${BUILD_ARCHITECTURE}" =~ "musl" ]]; then
echo "Running using glibc docker image";
else
echo "Running using musl docker image";
ALPINE_IMAGE=-alpine
fi

ELASTIC_AGENT_PHP_PATH=${PWD}/../../../php


LOCAL_TMP_DIR=$(mktemp -d)

LOCAL_LOG_FAILED_TESTS=${LOCAL_TMP_DIR}/test-run-failures.log
touch ${LOCAL_LOG_FAILED_TESTS}

LOCAL_LOG_TEST_RUN=${LOCAL_TMP_DIR}/test-run.log
touch ${LOCAL_LOG_TEST_RUN}

LOG_FAILED_TESTS=/phpt-tests/test-run-failures.log
LOG_TEST_RUN=/phpt-tests/test-run.log

RUN_TESTS=/usr/local/lib/php/build/run-tests.php

# copy test folder or test file into temp folder
mkdir -p ${LOCAL_TMP_DIR}/$(dirname ${TESTS_TO_RUN})
cp -R ${TESTS_TO_RUN} ${LOCAL_TMP_DIR}/${TESTS_TO_RUN}

docker run --rm \
-v ${LOCAL_TMP_DIR}/tests:/phpt-tests/tests \
-v ./tests_util:/phpt-tests/tests_util \
-v ${LOCAL_LOG_FAILED_TESTS}:${LOG_FAILED_TESTS} \
-v ${LOCAL_LOG_TEST_RUN}:${LOG_TEST_RUN} \
-v ${ELASTIC_AGENT_PHP_PATH}:/elastic/php \
-v ${ELASTIC_AGENT_SO_PATH}:/elastic/elastic_otel_php.so \
-w /phpt-tests \
php:${PHP_VERSION:0:1}.${PHP_VERSION:1:1}-cli${ALPINE_IMAGE} sh -c "php -n ${RUN_TESTS} -w ${LOG_FAILED_TESTS} ${TESTS_TO_RUN} 2>&1 | tee ${LOG_TEST_RUN}"

if [ -s ${LOCAL_LOG_FAILED_TESTS} ]; then
echo "Test failed"

pushd ${LOCAL_TMP_DIR}
tar -czf ${TESTS_FAILURES_ARCHIVE} .
popd
rm -rf ${LOCAL_TMP_DIR}

exit 1
fi

rm -rf ${LOCAL_TMP_DIR}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 0 (in this case using environment variable) s
ELASTIC_APM_ENABLED=0
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
--INI--
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertSame("getenv('ELASTIC_APM_ENABLED')", getenv('ELASTIC_APM_ENABLED'), '0');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 0 (in this case using ini file) should be int
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
--INI--
elastic_apm.enabled=0
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertSame("ini_get('elastic_apm.enabled')", ini_get('elastic_apm.enabled'), '0');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 1 (in this case using environment variable) s
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
ELASTIC_APM_ENABLED=1
--INI--
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertSame("getenv('ELASTIC_APM_ENABLED')", getenv('ELASTIC_APM_ENABLED'), '1');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 1 (in this case using ini file) should be int
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
--INI--
elastic_apm.enabled=1
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertSame("ini_get('elastic_apm.enabled')", ini_get('elastic_apm.enabled'), '1');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 'FaLSe' (in this case using environment varia
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
ELASTIC_APM_ENABLED=FaLSe
--INI--
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertSame("getenv('ELASTIC_APM_ENABLED')", getenv('ELASTIC_APM_ENABLED'), 'FaLSe');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 'FaLSe' (in this case using ini file) should
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
--INI--
elastic_apm.enabled=FaLSe
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertEqual("ini_get('elastic_apm.enabled')", ini_get('elastic_apm.enabled'), false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 'no' (in this case using environment variable
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
ELASTIC_APM_ENABLED=No
--INI--
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertSame("getenv('ELASTIC_APM_ENABLED')", getenv('ELASTIC_APM_ENABLED'), 'No');

Expand Down
Loading

0 comments on commit dd9bad8

Please sign in to comment.