debian-mirror-gitlab/lib/gitlab/database/migrations/observers/query_details.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

2021-09-04 01:27:46 +05:30
# frozen_string_literal: true
module Gitlab
module Database
module Migrations
module Observers
class QueryDetails < MigrationObserver
def before
2022-05-07 20:08:51 +05:30
file_path = File.join(output_dir, "query-details.json")
2021-10-27 15:23:28 +05:30
@file = File.open(file_path, 'wb')
2021-09-04 01:27:46 +05:30
@writer = Oj::StreamWriter.new(@file, {})
@writer.push_array
@subscriber = ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
record_sql_event(*args)
end
end
def after
ActiveSupport::Notifications.unsubscribe(@subscriber)
@writer.pop_all
@writer.flush
@file.close
end
2021-10-27 15:23:28 +05:30
def record
# no-op
2021-09-04 01:27:46 +05:30
end
def record_sql_event(_name, started, finished, _unique_id, payload)
@writer.push_value({
start_time: started.iso8601(6),
end_time: finished.iso8601(6),
sql: payload[:sql],
binds: payload[:type_casted_binds]
})
end
end
end
end
end
end