Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TRACER_SOURCES_INI := -d datadog.trace.sources_path=$(TRACER_SOURCE_DIR)
RUN_TESTS_IS_PARALLEL ?= $(shell test $(PHP_MAJOR_MINOR) -ge 74 && echo 1)

# shuffle parallel tests to evenly distribute test load, avoiding a batch of 32 tests being request-replayer tests
RUN_TESTS_CMD := DD_SERVICE= DD_ENV= DD_TRACE_RETRY_INTERVAL=1 REPORT_EXIT_STATUS=1 TEST_PHP_SRCDIR=$(PROJECT_ROOT) USE_TRACKED_ALLOC=1 php -n -d 'memory_limit=-1' $(BUILD_DIR)/run-tests.php $(if $(QUIET_TESTS),,-g FAIL,XFAIL,BORK,WARN,LEAK,XLEAK,SKIP) $(if $(ASAN), --asan) --show-diff -n -p $(shell which php) -q $(if $(RUN_TESTS_IS_PARALLEL), --shuffle -j$(MAX_TEST_PARALLELISM))
RUN_TESTS_CMD := DD_SERVICE= DD_ENV= REPORT_EXIT_STATUS=1 TEST_PHP_SRCDIR=$(PROJECT_ROOT) USE_TRACKED_ALLOC=1 php -n -d 'memory_limit=-1' $(BUILD_DIR)/run-tests.php $(if $(QUIET_TESTS),,-g FAIL,XFAIL,BORK,WARN,LEAK,XLEAK,SKIP) $(if $(ASAN), --asan) --show-diff -n -p $(shell which php) -q $(if $(RUN_TESTS_IS_PARALLEL), --shuffle -j$(MAX_TEST_PARALLELISM))

C_FILES = $(shell find components components-rs ext src/dogstatsd tracer zend_abstract_interface -name '*.c' -o -name '*.h' | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' )
TEST_FILES = $(shell find tests/ext -name '*.php*' -o -name '*.inc' -o -name '*.json' -o -name '*.yaml' -o -name 'CONFLICTS' | awk '{ printf "$(BUILD_DIR)/%s\n", $$1 }' )
Expand Down Expand Up @@ -211,7 +211,7 @@ test_extension_ci: $(SO_FILE) $(TEST_FILES) $(TEST_STUB_FILES) $(BUILD_DIR)/run-
\
export TEST_PHP_JUNIT=$(JUNIT_RESULTS_DIR)/valgrind-extension-test.xml; \
export TEST_PHP_OUTPUT=$(JUNIT_RESULTS_DIR)/valgrind-run-tests.out; \
DD_SPAWN_WORKER_STABLE_TRAMPOLINE=1 $(ALL_TEST_ENV_OVERRIDE) $(RUN_TESTS_CMD) -d extension=$(SO_FILE) -m -s $$TEST_PHP_OUTPUT $(BUILD_DIR)/$(TESTS) && ! grep -e '^LEAKED TEST SUMMARY' $$TEST_PHP_OUTPUT; \
DD_SPAWN_WORKER_STABLE_TRAMPOLINE=1 $(ALL_TEST_ENV_OVERRIDE) DD_TRACE_AGENT_TIMEOUT=5000 $(RUN_TESTS_CMD) -d extension=$(SO_FILE) -m -s $$TEST_PHP_OUTPUT $(BUILD_DIR)/$(TESTS) && ! grep -e '^LEAKED TEST SUMMARY' $$TEST_PHP_OUTPUT; \
)

build_tea: TEA_BUILD_TESTS=ON
Expand Down
2 changes: 1 addition & 1 deletion ext/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum datadog_sidecar_connection_mode {
* A user hit an issue with the userland time of 100.
*/
#define DD_TRACE_AGENT_CONNECT_TIMEOUT_VAL 100
#define DD_TRACE_AGENT_TIMEOUT_VAL 500
#define DD_TRACE_AGENT_TIMEOUT_VAL 3000
#define DD_TRACE_AGENT_FLUSH_INTERVAL_VAL 1001

#define DD_CFG_STR(str) #str
Expand Down
1 change: 1 addition & 0 deletions ext/sidecar.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ ddog_Endpoint *datadog_sidecar_agent_endpoint(void) {

if (agent_endpoint) {
dd_set_endpoint_test_token(agent_endpoint);
ddog_endpoint_set_timeout(agent_endpoint, get_global_DD_TRACE_AGENT_TIMEOUT());
}

return agent_endpoint;
Expand Down
4 changes: 2 additions & 2 deletions metadata/supported-configurations.json
Original file line number Diff line number Diff line change
Expand Up @@ -786,9 +786,9 @@
],
"DD_TRACE_AGENT_TIMEOUT": [
{
"implementation": "B",
"implementation": "C",
"type": "int",
"default": "500"
"default": "3000"
}
],
"DD_TRACE_AGENT_URL": [
Expand Down
2 changes: 2 additions & 0 deletions tests/ext/appsec/sca_flag_is_sent_01.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ require __DIR__ . '/../includes/clear_skipif_telemetry.inc'
--ENV--
DD_TRACE_GENERATE_ROOT_SPAN=0
DD_INSTRUMENTATION_TELEMETRY_ENABLED=1
DD_TRACE_AGENT_TIMEOUT=200
DD_TRACE_RETRY_INTERVAL=1
--INI--
datadog.trace.agent_url="file://{PWD}/sca_flag_is_sent_01-telemetry.out"
--FILE_EXTERNAL--
Expand Down
2 changes: 2 additions & 0 deletions tests/ext/appsec/sca_flag_is_sent_02.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ require __DIR__ . '/../includes/clear_skipif_telemetry.inc'
DD_TRACE_GENERATE_ROOT_SPAN=0
DD_INSTRUMENTATION_TELEMETRY_ENABLED=1
DD_APPSEC_SCA_ENABLED=true
DD_TRACE_AGENT_TIMEOUT=200
DD_TRACE_RETRY_INTERVAL=1
--INI--
datadog.trace.agent_url="file://{PWD}/sca_flag_is_sent_02-telemetry.out"
--FILE_EXTERNAL--
Expand Down
2 changes: 2 additions & 0 deletions tests/ext/appsec/sca_flag_is_sent_03.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ require __DIR__ . '/../includes/clear_skipif_telemetry.inc'
DD_TRACE_GENERATE_ROOT_SPAN=0
DD_INSTRUMENTATION_TELEMETRY_ENABLED=1
DD_APPSEC_SCA_ENABLED=false
DD_TRACE_AGENT_TIMEOUT=200
DD_TRACE_RETRY_INTERVAL=1
--INI--
datadog.trace.agent_url="file://{PWD}/sca_flag_is_sent_03-telemetry.out"
--FILE_EXTERNAL--
Expand Down
2 changes: 2 additions & 0 deletions tests/ext/appsec/sca_flag_is_sent_04.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ require __DIR__ . '/../includes/clear_skipif_telemetry.inc'
--ENV--
DD_TRACE_GENERATE_ROOT_SPAN=0
DD_INSTRUMENTATION_TELEMETRY_ENABLED=1
DD_TRACE_AGENT_TIMEOUT=200
DD_TRACE_RETRY_INTERVAL=1
--INI--
datadog.trace.agent_url="file://{PWD}/sca_flag_is_sent_04-telemetry.out"
datadog.appsec.sca_enabled=1
Expand Down
2 changes: 2 additions & 0 deletions tests/ext/appsec/sca_flag_is_sent_05.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ require __DIR__ . '/../includes/clear_skipif_telemetry.inc'
--ENV--
DD_TRACE_GENERATE_ROOT_SPAN=0
DD_INSTRUMENTATION_TELEMETRY_ENABLED=1
DD_TRACE_AGENT_TIMEOUT=200
DD_TRACE_RETRY_INTERVAL=1
--INI--
datadog.trace.agent_url="file://{PWD}/sca_flag_is_sent_05-telemetry.out"
datadog.appsec.sca_enabled=0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ $proxy = RequestReplayer::launchUnixProxy(str_replace("unix://", "", getenv("DD_
\DDTrace\start_span();
\DDTrace\close_span();

// ensure the response also is received by the sender first, to avoid retries holding up other tests
dd_trace_internal_fn("synchronous_flush");

echo PHP_EOL;
$headers = $rr->replayHeaders([
'content-type',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ include_once __DIR__ . '/../startup_logging.inc';
$logs = dd_get_startup_logs([], [
'DD_AGENT_HOST' => '::1',
'DD_TRACE_DEBUG' => 1,
'DD_TRACE_AGENT_TIMEOUT' => 200,
'DD_TRACE_RETRY_INTERVAL' => 1,
]);

dd_dump_startup_logs($logs, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ DD_AGENT_HOST=192.0.2.1
DD_TRACE_AGENT_PORT=18126
DD_TRACE_SIDECAR_TRACE_SENDER=0
DD_TRACE_SHUTDOWN_TIMEOUT=2000
DD_TRACE_AGENT_TIMEOUT=500
DD_TRACE_AGENT_CONNECT_TIMEOUT=500
DD_TRACE_AGENT_TIMEOUT=200
DD_TRACE_AGENT_CONNECT_TIMEOUT=200
DD_TRACE_RETRY_INTERVAL=1
DD_TRACE_AGENT_RETRIES=0
DD_INSTRUMENTATION_TELEMETRY_ENABLED=0
DD_REMOTE_CONFIG_ENABLED=0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ If an agent unix domain socket exists it will try to connect to it
<?php include __DIR__ . '/../includes/skipif_no_dev_env.inc'; ?>
<?php @mkdir("/var/run/datadog"); if (!is_dir("/var/run/datadog")) { shell_exec("sudo mkdir /var/run/datadog <&-; sudo chown $(id -u) /var/run/datadog"); } if (!is_file("/var/run/datadog/apm.socket") && !is_writable("/var/run/datadog")) die("skip: no permissions to create a /var/run/datadog/apm.socket"); ?>
--ENV--
DD_TRACE_GENERATE_ROOT_SPAN=0
DD_INSTRUMENTATION_TELEMETRY_ENABLED=0
DD_REMOTE_CONFIG_ENABLED=0
DD_AGENT_HOST=
--FILE--
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ The sidecar properly handles invalid agent urls
DD_TRACE_AGENT_URL=/invalid
DD_TRACE_SIDECAR_TRACE_SENDER=1
DD_CRASHTRACKING_ENABLED=0
DD_TRACE_AGENT_TIMEOUT=200
DD_TRACE_RETRY_INTERVAL=1
--FILE--
<?php

Expand Down
59 changes: 30 additions & 29 deletions tests/ext/includes/request_replayer.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ ini_set("datadog.trace.httpstream_enabled", 0);

class ProxyContainer {
public $proc;
public function __construct($proc) {
$this->proc = $proc;
}
private $pipes;

public function __destruct() {
proc_terminate($this->proc, 9);
public function __construct($proc, array $pipes) {
$this->proc = $proc;
$this->pipes = $pipes;
}
}

Expand Down Expand Up @@ -203,32 +202,34 @@ class RequestReplayer
]));
}

public static function launchUnixProxy($socketPath) {
/**
* Serves $socketPath and forwards everything to the request-replayer, so
* that the tracer's unix socket agent transport can be tested.
*
* Launches unix_socket_proxy.php.
*/
public static function launchUnixProxy($socketPath, $upstream = "request-replayer:80") {
@unlink($socketPath);
$code = str_replace("\n", "", '
ignore_user_abort(true); /* prevent bailout... */
$server = stream_socket_server("unix://' . $socketPath . '");
print "1\n"; /* ready marker */
while ($client = stream_socket_accept($server, 5)) {
file_put_contents("/tmp/unix-proxy-' . basename($socketPath) . '", "connected\n", FILE_APPEND);
$replayer = stream_socket_client("request-replayer:80");
$all = $read = [$client, $replayer];
foreach ($read as $fp) stream_set_blocking($fp, false);
while (stream_select($read, $w, $e, null)) {
$data = fread($fp = reset($read), 4096);
if ($data == "") {
file_put_contents("/tmp/unix-proxy-' . basename($socketPath) . '", "end\n", FILE_APPEND);
break;

// -n: run without any php.ini, so the proxy does not itself load
// ddtrace and send agent requests into the socket it is serving.
$cmd = PHP_BINARY . " -n " . escapeshellarg(__DIR__ . "/unix_socket_proxy.php")
. " " . escapeshellarg($socketPath) . " " . escapeshellarg($upstream);
// stdin is a pipe on purpose: the proxy exits once it hits EOF there,
// which happens as soon as this process is gone. That avoids both a
// leaked proxy and the previous inactivity timeout, which killed the
// proxy while a test was still running.
$proc = proc_open($cmd, [["pipe", "r"], ["pipe", "w"], STDERR], $pipes);
if (!is_resource($proc)) {
throw new Exception("failed to launch unix proxy for $socketPath");
}

if (fread($pipes[1], 1) !== "1") { // ready marker
fclose($pipes[0]);
proc_close($proc);
throw new Exception("unix proxy for $socketPath failed to start");
}
file_put_contents("/tmp/unix-proxy-' . basename($socketPath) . '", "$data\n", FILE_APPEND);
fwrite($fp == $replayer ? $client : $replayer, $data);
$read = $all;
}
}
');

$proc = proc_open(PHP_BINARY . " -r '$code'", [STDIN, ["pipe", "w"], STDERR], $pipes);
fread($pipes[1], 1); // ready
return new ProxyContainer($proc);
return new ProxyContainer($proc, [$pipes[0]]);
}
}
Loading
Loading