Skip to content

Commit abe934d

Browse files
committed
Implement DataCollector::reset()
1 parent 0237510 commit abe934d

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/DataCollector/DriverEventSubscriber.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
use MongoDB\Driver\Monitoring\CommandStartedEvent;
2626
use MongoDB\Driver\Monitoring\CommandSubscriber;
2727
use MongoDB\Driver\Monitoring\CommandSucceededEvent;
28+
use Symfony\Contracts\Service\ResetInterface;
2829

29-
final class DriverEventSubscriber implements CommandSubscriber
30+
/** @internal */
31+
final class DriverEventSubscriber implements CommandSubscriber, ResetInterface
3032
{
3133
/**
3234
* @var list<CommandFailedEvent|CommandStartedEvent|CommandSucceededEvent>
@@ -60,4 +62,9 @@ public function commandSucceeded(CommandSucceededEvent $event): void
6062
{
6163
$this->events[] = $event;
6264
}
65+
66+
public function reset(): void
67+
{
68+
$this->events = [];
69+
}
6370
}

src/DataCollector/MongoDBDataCollector.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Symfony\Component\HttpFoundation\Response;
2929
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
3030

31+
/** @internal */
3132
final class MongoDBDataCollector extends DataCollector
3233
{
3334
/**
@@ -63,23 +64,20 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
6364
'startedAt' => hrtime(true),
6465
'commandName' => $event->getCommandName(),
6566
'command' => $command,
66-
// 'server' => $event->getServer()->getInfo(),
6767
'operationId' => $event->getOperationId(),
6868
'database' => $event->getDatabaseName(),
6969
'serviceId' => $event->getServiceId(),
7070
];
7171
++$requestCount;
7272
} elseif ($event instanceof CommandSucceededEvent) {
7373
$requests[$requestId] += [
74-
// 'reply' => Document::fromPHP($event->getReply()),
7574
'duration' => $event->getDurationMicros(),
7675
'endedAt' => hrtime(true),
7776
'success' => true,
7877
];
7978
$totalTime += $event->getDurationMicros();
8079
} elseif ($event instanceof CommandFailedEvent) {
8180
$requests[$requestId] += [
82-
// 'reply' => Document::fromPHP($event->getReply()),
8381
'duration' => $event->getDurationMicros(),
8482
'error' => $event->getError(),
8583
'success' => false,
@@ -127,6 +125,10 @@ public function getName(): string
127125

128126
public function reset(): void
129127
{
130-
// TODO: Implement reset() method.
128+
$this->data = [];
129+
130+
foreach ($this->clients as ['subscriber' => $subscriber]) {
131+
$subscriber->reset();
132+
}
131133
}
132134
}

0 commit comments

Comments
 (0)