-
Notifications
You must be signed in to change notification settings - Fork 368
Log caller and query length for sql queries #2329
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
Log caller and query length for sql queries #2329
Conversation
Logs the calling function (of cloud_controller_ng code) for each DB query if SQL logging is enabled. This should help track down which functions are calling expensive queries and where excessive queries are being made. Running some perf tests against this, it appears to have little to no impact on the performance of CC since I suspect all this information is readily available in the callstack and the regex isn't too complex
We've seen some queries get extremely long (>1MB) which causes CC to run slow whilst building the query. To help monitor this and fix endpoints generating large queries, log the character length of the query in the SQL query logging string Co-authored-by: johha <45264872+johha@users.noreply.github.com>
sweinstein22
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ran through a quick check to see the behavior introduced:
ssh'd onto the api vm for the boshlite
Manually adjusted the cloud controller config's db section to include log_level: "info" and log_db_queries: true.
Ran monit restart cloud_controller_ng, waited for the restart to complete, ran cf curl /v3/security_groups
Checked cloud_controller_ng.log on the api instance, confirmed that query_length now appears as part of output:
{"timestamp":"2021-06-30T21:23:32.543213998Z","message":"(0.000497s) (app/presenters/v3/security_group_presenter.rb:45:in `space_guid_hash_for') (query_length=217) SELECT `guid` FROM `spaces` INNER JOIN `staging_security_groups_spaces` ON (`staging_security_groups_spaces`.`staging_space_id` = `spaces`.`id`) WHERE (`staging_security_groups_spaces`.`staging_security_group_id` = 3)","log_level":"info",...}
The changes look good, thanks for the PR!
* Log caller for SQL queries Logs the calling function (of cloud_controller_ng code) for each DB query if SQL logging is enabled. This should help track down which functions are calling expensive queries and where excessive queries are being made. Running some perf tests against this, it appears to have little to no impact on the performance of CC since I suspect all this information is readily available in the callstack and the regex isn't too complex * Add extension to log SQL query length We've seen some queries get extremely long (>1MB) which causes CC to run slow whilst building the query. To help monitor this and fix endpoints generating large queries, log the character length of the query in the SQL query logging string Co-authored-by: johha <45264872+johha@users.noreply.github.com> Co-authored-by: andy-paine <andy.paine@engineerbetter.com>
* Log caller for SQL queries Logs the calling function (of cloud_controller_ng code) for each DB query if SQL logging is enabled. This should help track down which functions are calling expensive queries and where excessive queries are being made. Running some perf tests against this, it appears to have little to no impact on the performance of CC since I suspect all this information is readily available in the callstack and the regex isn't too complex * Add extension to log SQL query length We've seen some queries get extremely long (>1MB) which causes CC to run slow whilst building the query. To help monitor this and fix endpoints generating large queries, log the character length of the query in the SQL query logging string Co-authored-by: johha <45264872+johha@users.noreply.github.com> Co-authored-by: andy-paine <andy.paine@engineerbetter.com>
* Log caller for SQL queries Logs the calling function (of cloud_controller_ng code) for each DB query if SQL logging is enabled. This should help track down which functions are calling expensive queries and where excessive queries are being made. Running some perf tests against this, it appears to have little to no impact on the performance of CC since I suspect all this information is readily available in the callstack and the regex isn't too complex * Add extension to log SQL query length We've seen some queries get extremely long (>1MB) which causes CC to run slow whilst building the query. To help monitor this and fix endpoints generating large queries, log the character length of the query in the SQL query logging string Co-authored-by: johha <45264872+johha@users.noreply.github.com> Co-authored-by: andy-paine <andy.paine@engineerbetter.com>
Thanks for contributing to cloud_controller_ng. To speed up the process of reviewing your pull request please provide us with:
A short explanation of the proposed change:
For better analyzing load pattern we want to log the caller and length of db queries. This is related to the slow requests we found recently (e.g.
security_groups)Log example:
I have reviewed the contributing guide
I have viewed, signed, and submitted the Contributor License Agreement
I have made this pull request to the
mainbranchI have run all the unit tests using
bundle exec rakeI have run CF Acceptance Tests