Commit 5a59980a authored by Andreas Brandl's avatar Andreas Brandl

Merge branch 'ali/db-testing-simplify-observers' into 'master'

DB testing: Simplify migration observers

See merge request gitlab-org/gitlab!68098
parents dc51a059 b864111b
...@@ -6,8 +6,8 @@ module Gitlab ...@@ -6,8 +6,8 @@ module Gitlab
module Observers module Observers
class QueryDetails < MigrationObserver class QueryDetails < MigrationObserver
def before def before
@file_path = File.join(Instrumentation::RESULT_DIR, 'current-details.json') file_path = File.join(Instrumentation::RESULT_DIR, "#{observation.version}_#{observation.name}-query-details.json")
@file = File.open(@file_path, 'wb') @file = File.open(file_path, 'wb')
@writer = Oj::StreamWriter.new(@file, {}) @writer = Oj::StreamWriter.new(@file, {})
@writer.push_array @writer.push_array
@subscriber = ActiveSupport::Notifications.subscribe('sql.active_record') do |*args| @subscriber = ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
...@@ -23,7 +23,7 @@ module Gitlab ...@@ -23,7 +23,7 @@ module Gitlab
end end
def record def record
File.rename(@file_path, File.join(Instrumentation::RESULT_DIR, "#{observation.version}_#{observation.name}-query-details.json")) # no-op
end end
def record_sql_event(_name, started, finished, _unique_id, payload) def record_sql_event(_name, started, finished, _unique_id, payload)
......
...@@ -7,8 +7,8 @@ module Gitlab ...@@ -7,8 +7,8 @@ module Gitlab
class QueryLog < MigrationObserver class QueryLog < MigrationObserver
def before def before
@logger_was = ActiveRecord::Base.logger @logger_was = ActiveRecord::Base.logger
@log_file_path = File.join(Instrumentation::RESULT_DIR, 'current.log') file_path = File.join(Instrumentation::RESULT_DIR, "#{observation.version}_#{observation.name}.log")
@logger = Logger.new(@log_file_path) @logger = Logger.new(file_path)
ActiveRecord::Base.logger = @logger ActiveRecord::Base.logger = @logger
end end
...@@ -18,7 +18,7 @@ module Gitlab ...@@ -18,7 +18,7 @@ module Gitlab
end end
def record def record
File.rename(@log_file_path, File.join(Instrumentation::RESULT_DIR, "#{observation.version}_#{observation.name}.log")) # no-op
end end
end end
end end
......
...@@ -8,7 +8,6 @@ RSpec.describe Gitlab::Database::Migrations::Observers::QueryLog do ...@@ -8,7 +8,6 @@ RSpec.describe Gitlab::Database::Migrations::Observers::QueryLog do
let(:connection) { ActiveRecord::Base.connection } let(:connection) { ActiveRecord::Base.connection }
let(:query) { 'select 1' } let(:query) { 'select 1' }
let(:directory_path) { Dir.mktmpdir } let(:directory_path) { Dir.mktmpdir }
let(:log_file) { "#{directory_path}/current.log" }
let(:migration_version) { 20210422152437 } let(:migration_version) { 20210422152437 }
let(:migration_name) { 'test' } 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