Commit b864111b authored by Alishan Ladhani's avatar Alishan Ladhani

Simplify migration observers

They do not need to rename the file anymore since they are
instantiated with information about the migration being observed.
parent 86abff01
......@@ -6,8 +6,8 @@ module Gitlab
module Observers
class QueryDetails < MigrationObserver
def before
@file_path = File.join(Instrumentation::RESULT_DIR, 'current-details.json')
@file = File.open(@file_path, 'wb')
file_path = File.join(Instrumentation::RESULT_DIR, "#{observation.version}_#{observation.name}-query-details.json")
@file = File.open(file_path, 'wb')
@writer = Oj::StreamWriter.new(@file, {})
@writer.push_array
@subscriber = ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
......@@ -23,7 +23,7 @@ module Gitlab
end
def record
File.rename(@file_path, File.join(Instrumentation::RESULT_DIR, "#{observation.version}_#{observation.name}-query-details.json"))
# no-op
end
def record_sql_event(_name, started, finished, _unique_id, payload)
......
......@@ -7,8 +7,8 @@ module Gitlab
class QueryLog < MigrationObserver
def before
@logger_was = ActiveRecord::Base.logger
@log_file_path = File.join(Instrumentation::RESULT_DIR, 'current.log')
@logger = Logger.new(@log_file_path)
file_path = File.join(Instrumentation::RESULT_DIR, "#{observation.version}_#{observation.name}.log")
@logger = Logger.new(file_path)
ActiveRecord::Base.logger = @logger
end
......@@ -18,7 +18,7 @@ module Gitlab
end
def record
File.rename(@log_file_path, File.join(Instrumentation::RESULT_DIR, "#{observation.version}_#{observation.name}.log"))
# no-op
end
end
end
......
......@@ -8,7 +8,6 @@ RSpec.describe Gitlab::Database::Migrations::Observers::QueryLog do
let(:connection) { ActiveRecord::Base.connection }
let(:query) { 'select 1' }
let(:directory_path) { Dir.mktmpdir }
let(:log_file) { "#{directory_path}/current.log" }
let(:migration_version) { 20210422152437 }
let(:migration_name) { 'test' }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment