|
28 | 28 | use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface; |
29 | 29 | use Throwable; |
30 | 30 |
|
31 | | -use function array_column; |
32 | 31 | use function array_diff_key; |
33 | | -use function array_map; |
34 | | -use function array_sum; |
35 | | -use function count; |
36 | | -use function iterator_to_array; |
37 | 32 |
|
38 | 33 | /** @internal */ |
39 | 34 | final class MongoDBDataCollector extends DataCollector implements LateDataCollectorInterface |
@@ -66,15 +61,36 @@ public function collect(Request $request, Response $response, ?Throwable $except |
66 | 61 |
|
67 | 62 | public function lateCollect(): void |
68 | 63 | { |
| 64 | + $requests = $this->requests; |
| 65 | + $requestCount = 0; |
| 66 | + $errorCount = 0; |
| 67 | + $durationMicros = 0; |
| 68 | + |
| 69 | + foreach ($requests as $clientName => $requestsByClient) { |
| 70 | + foreach ($requestsByClient as $requestId => $request) { |
| 71 | + $requestCount++; |
| 72 | + $durationMicros += $request['durationMicros'] ?? 0; |
| 73 | + $errorCount += isset($request['error']) ? 1 : 0; |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + $clients = []; |
| 78 | + foreach ($this->clients as $name => $client) { |
| 79 | + $clients[$name] = [ |
| 80 | + 'serverBuildInfo' => array_diff_key( |
| 81 | + (array) $client->getManager()->executeCommand('admin', new Command(['buildInfo' => 1]))->toArray()[0], |
| 82 | + ['versionArray' => 0, 'ok' => 0], |
| 83 | + ), |
| 84 | + 'clientInfo' => array_diff_key($client->__debugInfo(), ['manager' => 0]), |
| 85 | + ]; |
| 86 | + } |
| 87 | + |
69 | 88 | $this->data = [ |
70 | | - 'clients' => array_map(static fn (Client $client) => [ |
71 | | - 'serverBuildInfo' => $client->getManager()->executeCommand('admin', new Command(['buildInfo' => 1]))->toArray()[0], |
72 | | - 'clientInfo' => array_diff_key($client->__debugInfo(), ['manager' => 1]), |
73 | | - ], iterator_to_array($this->clients)), |
74 | | - 'requests' => $this->requests, |
75 | | - 'requestCount' => array_sum(array_map(count(...), $this->requests)), |
76 | | - 'errorCount' => array_sum(array_map(static fn (array $requests) => count(array_column($requests, 'error')), $this->requests)), |
77 | | - 'durationMicros' => array_sum(array_map(static fn (array $requests) => array_sum(array_column($requests, 'durationMicros')), $this->requests)), |
| 89 | + 'clients' => $clients, |
| 90 | + 'requests' => $requests, |
| 91 | + 'requestCount' => $requestCount, |
| 92 | + 'errorCount' => $errorCount, |
| 93 | + 'durationMicros' => $durationMicros, |
78 | 94 | ]; |
79 | 95 | } |
80 | 96 |
|
|
0 commit comments