Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace QueryLogger in tests with CommandLogger #1866

Merged
merged 1 commit into from
Sep 27, 2018

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Sep 27, 2018

This PR supersedes #1850. I took the original idea and tracked the CommandStartedEvent as well. The reason behind this is that we need to store the original command to use it in the ShardKeyTest. Apart from that, the DataCollector used in the Symfony Bundle also needs to know all commands that were run, which is why I've moved the class to its own Sub-Namespace. With it being part in the API, we can use it in the upcoming bundle version to track queries for the web developer toolbar.

Thanks @caciobanu for getting this started - it was your implementation that gave me the idea how to handle this in the bundle 👍

$this->logCommand(Command::createForSucceededCommand($commandStartedEvent, $event));
}

public function commandFailed(CommandFailedEvent $event)
Copy link
Member

@malarzm malarzm Sep 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case for having 2 methods for finishing a command? I think it'd be easier for a consumer to have one commandFinished(CommandSucceededEvent|CommandFailedEvent $event)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll have to ask @jmikola or @derickr as this interface is provided by the driver: http://php.net/manual/en/class.mongodb-driver-monitoring-commandsubscriber.php.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes more sense now, I somehow thought that users will be calling these methods. Need a coffee ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private function getCommandStartedEvent(string $requestId): ?CommandStartedEvent
{
$startedEvent = $this->startedCommands[$requestId] ?? null;
unset($this->startedCommands[$requestId]);
Copy link
Member

@malarzm malarzm Sep 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think method name should reflect that state is changing, right now calling this twice will yield different results

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about findCommandStartedEvent?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findAndRemoveCommandStartedEvent? Lengthy but self explaining

@alcaeus
Copy link
Member Author

alcaeus commented Sep 27, 2018

Note: corresponding functionality (still WIP) can be seen in doctrine/DoctrineMongoDBBundle@32f92ec.

@malarzm malarzm merged commit bce26f3 into doctrine:master Sep 27, 2018
@alcaeus alcaeus deleted the add-apm-classes branch September 27, 2018 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants