Skip to content

Commit

Permalink
Avoid parseMultipleRequestsFromDumpedData with sidecar
Browse files Browse the repository at this point in the history
  • Loading branch information
bwoebi committed Jun 7, 2024
1 parent 2c99e5a commit 90f1fef
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 95 deletions.
4 changes: 2 additions & 2 deletions .circleci/continue_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ aliases:
DD_REQUEST_DUMPER_FILE: dump.json

- &IMAGE_DOCKER_DD_TEST_AGENT
image: ghcr.io/hoolioh/dd-apm-test-agent/ddapm-test-agent:latest
image: ghcr.io/datadog/dd-apm-test-agent/ddapm-test-agent:latest
name: test-agent
environment:
LOG_LEVEL: DEBUG
Expand Down Expand Up @@ -435,7 +435,7 @@ commands:
-e SNAPSHOT_DIR=/snapshots \
-p "127.0.0.1:9126:9126" \
-v $(pwd)/tests/snapshots:/snapshots \
--name test-agent ghcr.io/hoolioh/dd-apm-test-agent/ddapm-test-agent:latest
--name test-agent ghcr.io/datadog/dd-apm-test-agent/ddapm-test-agent:latest
retry_docker run --detach --rm --net net \
--name httpbin_integration kong/httpbin
retry_docker run --detach --rm --net net \
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ services:
- .:/app

test-agent:
image: ghcr.io/hoolioh/dd-apm-test-agent/ddapm-test-agent:latest
image: ghcr.io/datadog/dd-apm-test-agent/ddapm-test-agent:latest
ports:
- "127.0.0.1:9126:8126"
volumes:
Expand Down
4 changes: 2 additions & 2 deletions tests/Common/TracerTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function inCli($scriptPath, $customEnvs = [], $customInis = [], $argument
return $out;
}

public function executeCli($scriptPath, $customEnvs = [], $customInis = [], $arguments = '', $withOutput = false)
public function executeCli($scriptPath, $customEnvs = [], $customInis = [], $arguments = '', $withOutput = false, $skipSyncFlush = false)
{
$envs = (string) new EnvSerializer(array_merge(
[
Expand Down Expand Up @@ -262,7 +262,7 @@ public function executeCli($scriptPath, $customEnvs = [], $customInis = [], $arg
`$commandToExecute`;
$ret = null;
}
if (\dd_trace_env_config("DD_TRACE_SIDECAR_TRACE_SENDER")) {
if (!$skipSyncFlush && \dd_trace_env_config("DD_TRACE_SIDECAR_TRACE_SENDER")) {
\dd_trace_synchronous_flush();
}
return $ret;
Expand Down
39 changes: 11 additions & 28 deletions tests/Integrations/Laravel/V8_x/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,6 @@ protected function ddSetUp()
$this->resetQueue();
}

protected static function flattenArray($arr)
{
$retArr = [];
foreach ($arr as $val) {
if (isset($val[0]['trace_id'])) {
$retArr[] = [$val];
} else {
$retArr = array_merge($retArr, self::flattenArray($val));
}
}
return $retArr;
}

// Source: https://magp.ie/2015/09/30/convert-large-integer-to-hexadecimal-without-php-math-extension/
protected static function largeBaseConvert($numString, $fromBase, $toBase)
{
Expand Down Expand Up @@ -108,12 +95,11 @@ public function testSimplePushAndProcess()
sleep(3);
});

$this->isolateTracer(function () {
$workTraces = $this->tracesFromWebRequest(function () {
$spec = GetSpec::create('Queue work emails', '/queue/workOn');
$this->call($spec);
sleep(4);
});
$workTraces = $this->parseMultipleRequestsFromDumpedData();

$this->assertFlameGraph(
$createTraces,
Expand All @@ -135,8 +121,8 @@ public function testSimplePushAndProcess()
);

// $workTraces should have 2 traces: 1 'laravel.queue.process' and 1 'laravel.artisan'
$processTrace1 = $workTraces[0];
$artisanTrace = $workTraces[1];
$processTrace1 = [$workTraces[0]];
$artisanTrace = [$workTraces[1]];


$this->assertFlameGraph($processTrace1, [
Expand Down Expand Up @@ -202,12 +188,11 @@ public function testJobFailure()
sleep(3);
});

$this->isolateTracer(function () {
$workTraces = $this->tracesFromWebRequest(function () {
$spec = GetSpec::create('Queue work emails', '/queue/workOn');
$this->call($spec);
sleep(4);
});
$workTraces = $this->parseMultipleRequestsFromDumpedData();

$this->assertFlameGraph(
$createTraces,
Expand All @@ -229,8 +214,8 @@ public function testJobFailure()
);

// $workTraces should have 2 traces: 1 'laravel.queue.process' and 1 'laravel.artisan'
$processTrace1 = $workTraces[0];
$artisanTrace = $workTraces[1];
$processTrace1 = [$workTraces[0]];
$artisanTrace = [$workTraces[1]];

$this->assertFlameGraph(
$processTrace1,
Expand Down Expand Up @@ -276,21 +261,19 @@ public function testDispatchBatchAndProcess()
sleep(3);
});

$this->isolateTracer(function () {
$workTraces = $this->tracesFromWebRequest(function () {
$spec = GetSpec::create('Queue work batch', '/queue/workOn');
$this->call($spec);
sleep(7);
});
$workTraces = $this->parseMultipleRequestsFromDumpedData();

// $workTraces should have 2 traces: One with 2 'laravel.queue.process' and the other with 1 'laravel.artisan'
$workTraces = self::flattenArray($workTraces);
usort($workTraces, function ($a, $b) {
return $a[0][0]['start'] - $b[0][0]['start'];
return $a[0]['start'] - $b[0]['start'];
});
$artisanTrace = $workTraces[0];
$processTrace1 = $workTraces[1];
$processTrace2 = $workTraces[2];
$artisanTrace = [$workTraces[0]];
$processTrace1 = [$workTraces[1]];
$processTrace2 = [$workTraces[2]];

$this->assertFlameGraph($processTrace1, [
$this->spanProcessOneJob('database', 'emails', 'App\Jobs\SendVerificationEmail -> emails', true)
Expand Down
7 changes: 3 additions & 4 deletions tests/Integrations/Laravel/V8_x/QueueTestNotDistributed.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ public function testJobFailureNotDistributed()
$this->call($spec);
});

$this->isolateTracer(function () {
$artisanTrace = $this->tracesFromWebRequest(function () {
$spec = GetSpec::create('Queue work emails', '/queue/workOn');
$this->call($spec);
sleep(4);
});
$workTraces = $this->parseMultipleRequestsFromDumpedData();

// $workTraces should have 1 trace 'laravel.artisan'
$artisanTrace = $workTraces[0];
// $workTraces should have 1 chunk 'laravel.artisan'
$this->assertCount(1, $artisanTrace);

$this->assertFlameGraph(
$artisanTrace,
Expand Down
Loading

0 comments on commit 90f1fef

Please sign in to comment.