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
In SQL queries, print out the name of the plugin in a SQL comment for troubleshooting which plugin triggered query #7913
Comments
I think a good practice is to do something like this |
@mgazdzik where do you want to "mark" the queries? Is it for the log (file, CLI output?)? Or is it for MySQL's query log? |
@tsteur - unfortunately such comments aren't visible in mysql logs or in full process lists (or at least weren't visible at moment when we tried them). @mnapoli - simplest thing that comes to my mind is mysql logs (normal log and slowlog). Also long running queries can be seen using "show full processlist", which would also give clue about problematic plugin at first glance. |
if adding comments to SQL works I think it would be best/easiest solution
according to: http://stackoverflow.com/questions/19705881/how-to-get-mysql-comments-to-show-up-in-the-slow-log-or-processlist - comments are stripped when the queries come from mysql client, but they should be there when coming from other APIs eg. php apps. (note: I didn't test) |
Targetting for 2.15.0 as hopefully this is a quick fix |
I did some work to see if it's easy to fix in https://github.com/piwik/piwik/compare/7913 It seems to work but only kinda. The comment containing the plugin name is only visible in a subquery since the query generated by the log aggregator is surrounded by a ranking query usually. It looks like this (look for
Why did I not do this within the RankingQuery? Because a RankingQuery is created by each plugin instance see https://github.com/piwik/piwik/blob/2.14.2/plugins/Actions/Archiver.php#L178 . This means we can't solve it within the Piwik Platform but each plugin would have to set it. We could do this for our plugins but for 3rd party plugins it wouldn't work automatically (including Piwik PRO plugins unless it we don't forget to set it everywhere). Not sure if this is an issue and whether one such hint would be enough even if it is a subquery? |
Looks good to me @tsteur to have the plugin name in subquery only |
Goal of this issue is to make recognition of queries easier by marking queries with name of plugin which launched them.
In some cases, when archiving is slow or unefficient we end up having actual MySQL query that timed out or took DB down.
Currently there is no easy way to find which plugin caused this (sometimes it's archiving, or live plugin, sometimes it's custom plugins using core logic).
Maybe it could be tackled by adding one more "SELECT" item like "$pluginName as pluginName".
It will not be used while building additional archive, but still will "brand" each query with parenting plugin and make debug a bit easier.
Obviously not all plugins will be affected by this change (those with custom queries handled by custom code), but at least those which use core logic will be marked.
Please let me know if you have any questions about this request?
The text was updated successfully, but these errors were encountered: