Skip to content

Commit e1da67b

Browse files
authored
Merge branch 'master' into estringana/minify-json-blocking-error
2 parents ad6b3be + 9468244 commit e1da67b

File tree

10 files changed

+195
-36
lines changed

10 files changed

+195
-36
lines changed

.gitlab/benchmarks.yml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,22 @@ workflow:
7171
- when: manual
7272
interruptible: true
7373

74+
.on-master-or-nightly-benchmarks-or-release-always-and-not-interruptible: &on-master-or-nightly-benchmarks-or-release-always-and-not-interruptible
75+
if: '($CI_COMMIT_REF_NAME == "master" && ($NIGHTLY_BENCHMARKS || $CI_PIPELINE_SOURCE != "schedule")) || $CI_COMMIT_REF_NAME =~ /^ddtrace-/'
76+
when: always
77+
interruptible: false
78+
7479
.macrobenchmarks-rules: &macrobenchmarks-rules
75-
- if: $CI_COMMIT_REF_NAME == "master" && $NIGHTLY_BENCHMARKS
76-
when: always
77-
interruptible: false
78-
- if: $CI_COMMIT_REF_NAME == "master" && $CI_PIPELINE_SOURCE != "schedule"
79-
when: always
80-
interruptible: false
81-
- if: $CI_COMMIT_REF_NAME =~ /^ddtrace-/
82-
when: always
83-
interruptible: false
80+
- <<: *on-master-or-nightly-benchmarks-or-release-always-and-not-interruptible
8481
- when: manual
8582
interruptible: true
8683

84+
.pre-release-performance-quality-gates-rules: &pre-release-performance-quality-gates-rules
85+
- <<: *on-master-or-nightly-benchmarks-or-release-always-and-not-interruptible
86+
# Unlike on "master", on nightly benchmarks, or on release branches there's
87+
# no strict requirement to run the check unconditionally with "when: always".
88+
- interruptible: true
89+
8790
.microbenchmarks:
8891
stage: benchmarks
8992
tags: ["runner:apm-k8s-tweaked-metal"]
@@ -182,13 +185,13 @@ check-big-regressions:
182185

183186
.macrobenchmarks:
184187
stage: benchmarks
185-
rules: *macrobenchmarks-rules
186-
tags: ["runner:apm-k8s-same-cpu"]
187188
needs:
188189
- job: "package extension: [amd64, x86_64-unknown-linux-gnu]"
189190
artifacts: true
190191
- job: datadog-setup.php
191192
artifacts: true
193+
rules: *macrobenchmarks-rules
194+
tags: ["runner:apm-k8s-same-cpu"]
192195
timeout: 1h
193196
image: $MACROBENCHMARKS_CI_IMAGE
194197
script:
@@ -229,7 +232,7 @@ check-slo-breaches:
229232
extends: .check-slo-breaches
230233
stage: gate
231234
needs: ["macrobenchmarks"]
232-
when: on_success
235+
rules: *pre-release-performance-quality-gates-rules
233236
artifacts:
234237
name: "artifacts"
235238
when: always
@@ -245,6 +248,6 @@ notify-slo-breaches:
245248
extends: .notify-slo-breaches
246249
stage: notify
247250
needs: ["check-slo-breaches"]
248-
when: always
251+
rules: *pre-release-performance-quality-gates-rules
249252
variables:
250253
CHANNEL: "guild-dd-php"

.gitlab/check_test_agent.sh

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,61 @@
11
#!/usr/bin/env bash
22
set -eo pipefail
33

4-
set +e # Disable exiting from testagent response failure
5-
SUMMARY_RESPONSE=$(curl -s -w "\n%{http_code}" -o summary_response.txt http://test-agent:9126/test/trace_check/summary)
6-
set -e
7-
SUMMARY_RESPONSE_CODE=$(echo "$SUMMARY_RESPONSE" | awk 'END {print $NF}')
8-
if [[ SUMMARY_RESPONSE_CODE -eq 200 ]]; then
4+
MAX_RETRIES=5
5+
RETRY_DELAY=3
6+
7+
check_test_agent_with_retry() {
8+
local endpoint=$1
9+
local output_file=$2
10+
local attempt=1
11+
12+
while [ $attempt -le $MAX_RETRIES ]; do
13+
set +e
14+
response=$(curl -s -w "\n%{http_code}" -o "$output_file" "http://test-agent:9126$endpoint")
15+
response_code=$(echo "$response" | awk 'END {print $NF}')
16+
set -e
17+
18+
if [[ $response_code -eq 200 ]] || [[ $response_code -eq 404 ]]; then
19+
echo "$response_code"
20+
return 0
21+
fi
22+
23+
echo "Attempt $attempt/$MAX_RETRIES: Test agent returned $response_code, retrying in ${RETRY_DELAY}s..." >&2
24+
sleep $RETRY_DELAY
25+
attempt=$((attempt + 1))
26+
done
27+
28+
echo "0" # Failed after all retries
29+
return 1
30+
}
31+
32+
# Check if test agent is running
33+
summary_code=$(check_test_agent_with_retry "/test/trace_check/summary" "summary_response.txt")
34+
35+
if [[ $summary_code -eq 200 ]]; then
936
echo "APM Test Agent is running. (HTTP 200)"
37+
elif [[ $summary_code -eq 404 ]]; then
38+
echo "Real APM Agent running in place of TestAgent, no checks to validate!"
39+
exit 0
1040
else
1141
echo "APM Test Agent is not running and was not used for testing. No checks failed."
1242
exit 0
1343
fi
1444

15-
RESPONSE=$(curl -s -w "\n%{http_code}" -o response.txt http://test-agent:9126/test/trace_check/failures)
16-
RESPONSE_CODE=$(echo "$RESPONSE" | awk 'END {print $NF}')
45+
# Check for failures with retry
46+
failures_code=$(check_test_agent_with_retry "/test/trace_check/failures" "response.txt")
1747

18-
if [[ $RESPONSE_CODE -eq 200 ]]; then
48+
if [[ $failures_code -eq 200 ]]; then
1949
echo "All APM Test Agent Check Traces returned successful! (HTTP 200)"
2050
echo "APM Test Agent Check Traces Summary Results:"
2151
cat summary_response.txt | jq '.'
22-
elif [[ $RESPONSE_CODE -eq 404 ]]; then
52+
elif [[ $failures_code -eq 404 ]]; then
2353
echo "Real APM Agent running in place of TestAgent, no checks to validate!"
2454
else
25-
echo "APM Test Agent Check Traces failed with response code: $RESPONSE_CODE"
55+
echo "APM Test Agent Check Traces failed with response code: $failures_code"
2656
echo "Failures:"
2757
cat response.txt
2858
echo "APM Test Agent Check Traces Summary Results:"
2959
cat summary_response.txt | jq '.'
3060
exit 1
31-
fi
61+
fi

.gitlab/generate-appsec.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242

4343
.appsec_test:
4444
tags: [ "arch:${ARCH}" ]
45+
interruptible: true
46+
rules:
47+
- if: $CI_COMMIT_BRANCH == "master"
48+
interruptible: false
49+
- when: on_success
4550
before_script:
4651
<?php unset_dd_runner_env_vars() ?>
4752
- git config --global --add safe.directory "$(pwd)/appsec/third_party/libddwaf"

.gitlab/generate-common.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ function unset_dd_runner_env_vars() {
5050
- runner_system_failure
5151
- scheduler_failure
5252
- api_failure
53+
- script_failure
54+
- stuck_or_timeout_failure
55+
- job_execution_timeout
5356

5457
.all_targets: &all_minor_major_targets
5558
<?php

.gitlab/generate-package.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@
11701170

11711171
# Install system dependencies
11721172
apt-get update -o dir::state::lists="$APT_CACHE/lists"
1173-
apt-get install -y --no-install-recommends -o dir::state::lists="$APT_CACHE/lists" -o dir::cache::archives="$APT_CACHE/archives" ca-certificates curl git
1173+
apt-get install -y --no-install-recommends -o dir::state::lists="$APT_CACHE/lists" -o dir::cache::archives="$APT_CACHE/archives" ca-certificates curl git build-essential
11741174
mkdir -p /etc/apt/keyrings
11751175
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
11761176
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" > /etc/apt/sources.list.d/docker.list

.gitlab/generate-shared.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
tags: [ "arch:amd64" ]
8282
stage: test
8383
image: "registry.ddbuild.io/images/mirror/datadog/dd-trace-ci:php-${PHP_MAJOR_MINOR}_bookworm-5"
84+
interruptible: true
85+
rules:
86+
- if: $CI_COMMIT_BRANCH == "master"
87+
interruptible: false
88+
- when: on_success
8489
after_script:
8590
- mkdir -p tmp/artifacts
8691
- cp tmp/build*/Testing/Temporary/LastTest.log tmp/artifacts/LastTest.log

.gitlab/generate-tracer.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ function before_script_steps() {
123123
GIT_CONFIG_VALUE_1: true
124124
CONTAINER_NAME: $CI_JOB_NAME_SLUG
125125
GIT_STRATEGY: clone
126+
GIT_CLEAN_FLAGS: -ffdxq
126127
IMAGE: "registry.ddbuild.io/images/mirror/datadog/dd-trace-ci:php-${PHP_MAJOR_MINOR}_windows"
127128
script: |
128129
# Make sure we actually fail if a command fails
@@ -154,13 +155,13 @@ function before_script_steps() {
154155
try { docker stop -t 5 ${CONTAINER_NAME} } catch { }
155156
after_script:
156157
- |
157-
docker exec php cmd.exe /s /c xcopy /y /c /s /e C:\ProgramData\Microsoft\Windows\WER\ReportQueue .\app\dumps\
158+
docker exec ${CONTAINER_NAME} cmd.exe /s /c xcopy /y /c /s /e C:\ProgramData\Microsoft\Windows\WER\ReportQueue .\app\dumps\
158159
exit 0
159160
- 'powershell -NoProfile -Command "try { docker logs request-replayer } catch {}"'
160161
- 'powershell -NoProfile -Command "try { docker logs httpbin-integration } catch {}"'
161-
- 'powershell -NoProfile -Command "try { docker stop -t 5 request-replayer } catch {}"'
162+
- 'powershell -NoProfile -Command "try { docker stop -t 15 request-replayer } catch {}"'
162163
- 'powershell -NoProfile -Command "try { docker rm -f request-replayer } catch {}"'
163-
- 'powershell -NoProfile -Command "try { docker stop -t 5 httpbin-integration } catch {}"'
164+
- 'powershell -NoProfile -Command "try { docker stop -t 15 httpbin-integration } catch {}"'
164165
- 'powershell -NoProfile -Command "try { docker rm -f httpbin-integration } catch {}"'
165166
- 'powershell -NoProfile -Command "try { docker network rm net } catch {}"'
166167
artifacts:
@@ -194,6 +195,11 @@ function before_script_steps() {
194195
tags: [ "arch:${ARCH}" ]
195196
image: registry.ddbuild.io/images/mirror/datadog/dd-trace-ci:php-${PHP_MAJOR_MINOR}_bookworm-5
196197
timeout: 60m
198+
interruptible: true
199+
rules:
200+
- if: $CI_COMMIT_BRANCH == "master"
201+
interruptible: false
202+
- when: on_success
197203
variables:
198204
host_os: linux-gnu
199205
COMPOSER_MEMORY_LIMIT: "-1"
@@ -206,7 +212,7 @@ function before_script_steps() {
206212
HTTPBIN_PORT: 8080
207213
before_script:
208214
<?php before_script_steps() ?>
209-
- for host in ${WAIT_FOR:-}; do wait-for $host --timeout=180; done
215+
- .gitlab/wait-for-service-ready.sh
210216

211217
.asan_test:
212218
extends: .base_test
@@ -496,7 +502,7 @@ function before_script_steps() {
496502
- if [[ "$MAKE_TARGET" != "test_composer" ]] || ! [[ "$PHP_MAJOR_MINOR" =~ 8.[01] ]]; then sudo composer self-update --$COMPOSER_VERSION --no-interaction; fi
497503
- COMPOSER_MEMORY_LIMIT=-1 composer update --no-interaction # disable composer memory limit completely
498504
- make composer_tests_update
499-
- for host in ${WAIT_FOR:-}; do wait-for $host --timeout=180; done
505+
- .gitlab/wait-for-service-ready.sh
500506
script:
501507
- DD_TRACE_AGENT_TIMEOUT=1000 make $MAKE_TARGET RUST_DEBUG_BUILD=1 PHPUNIT_OPTS="--log-junit artifacts/tests/results.xml" <?= ASSERT_NO_MEMLEAKS ?>
502508
<?php after_script(".", true); ?>
@@ -513,7 +519,7 @@ function before_script_steps() {
513519
$services["deferred_loading"] = "mysql";
514520
$services["deferred_loadin"] = "redis";
515521
$services["pdo"] = "mysql";
516-
$services["kafk"] = ["kafka", "zookeeper"];
522+
$services["kafka"] = ["kafka", "zookeeper"]; // Overwrite auto-generated entry
517523

518524
$jobs = [];
519525
preg_match_all('(^TEST_(?<type>INTEGRATIONS|WEB)_(?<major>\d+)(?<minor>\d)[^\n]+(?<targets>.*?)^(?!\t))ms', file_get_contents(__DIR__ . "/../Makefile"), $matches, PREG_SET_ORDER);

.gitlab/wait-for-service-ready.sh

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
detect_service_type() {
6+
local host=${1}
7+
case ${host} in
8+
test-agent) echo "test-agent" ;;
9+
mysql-integration) echo "mysql" ;;
10+
elasticsearch*) echo "elasticsearch" ;;
11+
kafka*) echo "kafka" ;;
12+
redis*) echo "redis" ;;
13+
httpbin*) echo "httpbin" ;;
14+
*) echo "generic" ;;
15+
esac
16+
}
17+
18+
wait_for_single_service() {
19+
local HOST=${1}
20+
local PORT=${2}
21+
local SERVICE_TYPE=${3:-generic}
22+
local MAX_ATTEMPTS=${4:-30}
23+
local RETRY_DELAY=${5:-5}
24+
25+
echo "Waiting for ${HOST}:${PORT} to be reachable..."
26+
if ! wait-for "${HOST}:${PORT}" --timeout=180; then
27+
echo "ERROR: Could not reach ${HOST}:${PORT}" >&2
28+
return 1
29+
fi
30+
31+
for i in $(seq 1 ${MAX_ATTEMPTS}); do
32+
case ${SERVICE_TYPE} in
33+
test-agent)
34+
if curl -sf "http://${HOST}:${PORT}/info" > /dev/null 2>&1; then
35+
echo "Test agent is ready"
36+
return 0
37+
fi
38+
;;
39+
mysql)
40+
if mysqladmin ping -h"${HOST}" --silent 2>/dev/null; then
41+
echo "MySQL is ready"
42+
return 0
43+
fi
44+
;;
45+
elasticsearch)
46+
if curl -sf "http://${HOST}:${PORT}/_cluster/health?wait_for_status=yellow&timeout=1s" > /dev/null 2>&1; then
47+
echo "Elasticsearch is ready"
48+
return 0
49+
fi
50+
;;
51+
kafka)
52+
# Kafka readiness via nc check + settle time
53+
if timeout 5 nc -z "${HOST}" "${PORT}" 2>/dev/null; then
54+
sleep 2 # Additional settle time for Kafka
55+
echo "Kafka is ready"
56+
return 0
57+
fi
58+
;;
59+
redis)
60+
if redis-cli -h "${HOST}" ping 2>/dev/null | grep -q PONG; then
61+
echo "Redis is ready"
62+
return 0
63+
fi
64+
;;
65+
httpbin)
66+
# httpbin-specific check
67+
if curl -sf "http://${HOST}:${PORT}/status/200" > /dev/null 2>&1; then
68+
echo "httpbin is ready"
69+
return 0
70+
fi
71+
;;
72+
generic|*)
73+
# For generic services, just verify port + HTTP 200/health endpoint
74+
if curl -sf "http://${HOST}:${PORT}/" > /dev/null 2>&1 || curl -sf "http://${HOST}:${PORT}/health" > /dev/null 2>&1; then
75+
echo "${HOST}:${PORT} is ready"
76+
return 0
77+
fi
78+
# If HTTP fails, at least verify the port is still open
79+
if nc -z "${HOST}" "${PORT}" 2>/dev/null; then
80+
echo "${HOST}:${PORT} port is open (non-HTTP service)"
81+
return 0
82+
fi
83+
;;
84+
esac
85+
86+
echo "Attempt ${i}/${MAX_ATTEMPTS}: Service not ready yet, retrying in ${RETRY_DELAY}s..."
87+
sleep ${RETRY_DELAY}
88+
done
89+
90+
echo "ERROR: Service ${HOST}:${PORT} (${SERVICE_TYPE}) failed to become ready after ${MAX_ATTEMPTS} attempts"
91+
return 1
92+
}
93+
94+
if [ -n "${WAIT_FOR:-}" ]; then
95+
for service in ${WAIT_FOR}; do
96+
host="$(echo ${service} | cut -d: -f1)"
97+
port="$(echo ${service} | cut -d: -f2)"
98+
service_type="$(detect_service_type "${host}")"
99+
100+
if ! wait_for_single_service "${host}" "${port}" "${service_type}" 30 5; then
101+
exit 1
102+
fi
103+
done
104+
fi

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,9 +1208,10 @@ endef
12081208
define run_tests_debug
12091209
$(eval TEST_EXTRA_ENV=$(TEST_EXTRA_ENV) DD_TRACE_DEBUG=1)
12101210
(set -o pipefail; { $(call run_tests,$(1)) 2>&1 >&3 | \
1211-
tee >(grep -vE '\[ddtrace\] \[debug\]|\[ddtrace\] \[info\]' >&2) | \
1212-
{ ! (grep -E '\[error\]|\[warning\]|\[deprecated\]' >/dev/null && \
1213-
echo $$'\033[41m'"ERROR: Found debug log errors in the output."$$'\033[0m'); }; } 3>&1)
1211+
tee >(grep --line-buffered -vE '\[ddtrace\] \[debug\]|\[ddtrace\] \[info\]' >&2) | \
1212+
{ ! (grep --line-buffered -E '\[error\]|\[warning\]|\[deprecated\]' >/dev/null && \
1213+
echo $$'\033[41m'"ERROR: Found debug log errors in the output."$$'\033[0m'); }; } 3>&1); \
1214+
timeout 10 bash -c 'wait' 2>/dev/null || true
12141215
$(eval TEST_EXTRA_ENV=)
12151216
endef
12161217

appsec/src/extension/request_abort.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,10 @@ zend_array *nonnull dd_request_abort_static_page_spec(
515515
}
516516

517517
{
518-
char buf[sizeof("18446744073709551615") - 1];
519-
size_t len = sprintf(buf, "%zu", body_len);
518+
// This magic number is the string representation of SIZE_MAX on 64 bit
519+
// systems
520+
char buf[sizeof("18446744073709551615")];
521+
size_t len = snprintf(buf, sizeof(buf), "%zu", body_len);
520522
zend_string *s = zend_string_init(buf, len, 0);
521523
zval cont_len_zv;
522524
ZVAL_STR(&cont_len_zv, s);

0 commit comments

Comments
 (0)