Skip to content

Filter out BEGIN/COMMIT correctly in metrics

Sylvester Chin requested to merge sc1-fix-db-write-count into master

What does this MR do and why?

This MR updates the check in Gitlab::Metrics::Subscribers::ActiveRecord's #ignored_query? to handle BEGIN and COMMIT statements containing marginalia comments.

Related to gitlab-com/gl-infra/scalability#1811 (comment 1332375768). ActionMailer::MailDeliveryJob is showing a db_write_count of 3 even though only 1 INSERT statement shows up on the query recorder / logs. The other 2 are from BEGIN and COMMIT statements due to the marginalia comments causing it to be not ignored.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

How to set up and validate locally

On gdk, running a simple transaction will print in name (time) sql format. We can check on name if its matching 'TRASNACTION' to ignore effects of marginalia.

[4] pry(main)> ActiveRecord::Base.transaction do
[4] pry(main)*   User.first
[4] pry(main)* end
  TRANSACTION (0.5ms)  BEGIN /*application:console,db_config_name:main,console_hostname:Sylvesters-MacBook-Pro-2.local,console_username:sylvesterchin,line:(pry):5:in `block in __pry__'*/

  User Load (0.9ms)  SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 /*application:console,db_config_name:main,console_hostname:Sylvesters-MacBook-Pro-2.local,console_username:sylvesterchin,line:(pry):5:in `block in __pry__'*/
  TRANSACTION (0.2ms)  COMMIT /*application:console,db_config_name:main,console_hostname:Sylvesters-MacBook-Pro-2.local,console_username:sylvesterchin,line:/lib/gitlab/database.rb:387:in `commit'*/
=> #<User id:1 @root>

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Sylvester Chin

Merge request reports