Skip to content

Conversation

@johha
Copy link
Contributor

@johha johha commented Jun 10, 2021

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:

    <14>1 2021-06-10T14:55:09.157985Z 10.0.129.64 cloud_controller_ng rs2 - [instance@47450 director="bosh" deployment="cf" group="api" id="bosh-id"] {"timestamp":"2021-06-10T14:55:08.266616342Z","message":"(0.045727s) (app/controllers/v3/domains_controller.rb:26:in `index') (query_length=443579) SELECT \"domains\".* FROM \"domains\" WHERE (((\"domains\".\"owning_organization_id\" IS NULL) OR (\"domains\".\"owning_organization_id\" IN (SELECT \"id\" FROM \"organizations\" WHERE (\"guid\" IN ...
    
  • I have reviewed the contributing guide

  • I have viewed, signed, and submitted the Contributor License Agreement

  • I have made this pull request to the main branch

  • I have run all the unit tests using bundle exec rake

  • I have run CF Acceptance Tests

andy-paine and others added 2 commits June 10, 2021 08:57
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>
Copy link
Contributor

@sweinstein22 sweinstein22 left a 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!

@sweinstein22 sweinstein22 merged commit 214c7d2 into cloudfoundry:main Jun 30, 2021
@andy-paine andy-paine deleted the log-sql-query-sizes branch July 6, 2021 10:05
will-gant pushed a commit to sap-contributions/cloud_controller_ng that referenced this pull request Jul 12, 2021
* 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>
bepotts pushed a commit that referenced this pull request Jul 13, 2021
* 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>
bepotts pushed a commit that referenced this pull request Jul 19, 2021
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants