Commit 04756cfc authored by James Fargher's avatar James Fargher

Improve backup logging

Migrates most logging output generated by the backup manager to the new
backup log file. Previously logging was sometimes logged and other times
outputted directly to stdout.

Changelog: fixed
parent a280164f
This diff is collapsed.
...@@ -28,7 +28,7 @@ RSpec.describe Backup::Manager do ...@@ -28,7 +28,7 @@ RSpec.describe Backup::Manager do
it 'calls the named task' do it 'calls the named task' do
expect(task).to receive(:dump) expect(task).to receive(:dump)
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Dumping my task ... ') expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Dumping my task ... ')
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'done') expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Dumping my task ... done')
subject.run_create_task('my_task') subject.run_create_task('my_task')
end end
...@@ -37,8 +37,7 @@ RSpec.describe Backup::Manager do ...@@ -37,8 +37,7 @@ RSpec.describe Backup::Manager do
let(:enabled) { false } let(:enabled) { false }
it 'informs the user' do it 'informs the user' do
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Dumping my task ... ') expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Dumping my task ... [DISABLED]')
expect(Gitlab::BackupLogger).to receive(:info).with(message: '[DISABLED]')
subject.run_create_task('my_task') subject.run_create_task('my_task')
end end
...@@ -48,8 +47,7 @@ RSpec.describe Backup::Manager do ...@@ -48,8 +47,7 @@ RSpec.describe Backup::Manager do
it 'informs the user' do it 'informs the user' do
stub_env('SKIP', 'my_task') stub_env('SKIP', 'my_task')
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Dumping my task ... ') expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Dumping my task ... [SKIPPED]')
expect(Gitlab::BackupLogger).to receive(:info).with(message: '[SKIPPED]')
subject.run_create_task('my_task') subject.run_create_task('my_task')
end end
...@@ -78,7 +76,7 @@ RSpec.describe Backup::Manager do ...@@ -78,7 +76,7 @@ RSpec.describe Backup::Manager do
it 'calls the named task' do it 'calls the named task' do
expect(task).to receive(:restore) expect(task).to receive(:restore)
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Restoring my task ... ').ordered expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Restoring my task ... ').ordered
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'done').ordered expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Restoring my task ... done').ordered
subject.run_restore_task('my_task') subject.run_restore_task('my_task')
end end
...@@ -87,8 +85,7 @@ RSpec.describe Backup::Manager do ...@@ -87,8 +85,7 @@ RSpec.describe Backup::Manager do
let(:enabled) { false } let(:enabled) { false }
it 'informs the user' do it 'informs the user' do
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Restoring my task ... ').ordered expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Restoring my task ... [DISABLED]').ordered
expect(Gitlab::BackupLogger).to receive(:info).with(message: '[DISABLED]').ordered
subject.run_restore_task('my_task') subject.run_restore_task('my_task')
end end
...@@ -100,7 +97,7 @@ RSpec.describe Backup::Manager do ...@@ -100,7 +97,7 @@ RSpec.describe Backup::Manager do
it 'displays and waits for the user' do it 'displays and waits for the user' do
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Restoring my task ... ').ordered expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Restoring my task ... ').ordered
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Watch out!').ordered expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Watch out!').ordered
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'done').ordered expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Restoring my task ... done').ordered
expect(Gitlab::TaskHelpers).to receive(:ask_to_continue) expect(Gitlab::TaskHelpers).to receive(:ask_to_continue)
expect(task).to receive(:restore) expect(task).to receive(:restore)
...@@ -124,7 +121,7 @@ RSpec.describe Backup::Manager do ...@@ -124,7 +121,7 @@ RSpec.describe Backup::Manager do
it 'displays and waits for the user' do it 'displays and waits for the user' do
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Restoring my task ... ').ordered expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Restoring my task ... ').ordered
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'done').ordered expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Restoring my task ... done').ordered
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Watch out!').ordered expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Watch out!').ordered
expect(Gitlab::TaskHelpers).to receive(:ask_to_continue) expect(Gitlab::TaskHelpers).to receive(:ask_to_continue)
expect(task).to receive(:restore) expect(task).to receive(:restore)
...@@ -134,7 +131,7 @@ RSpec.describe Backup::Manager do ...@@ -134,7 +131,7 @@ RSpec.describe Backup::Manager do
it 'does not continue when the user quits' do it 'does not continue when the user quits' do
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Restoring my task ... ').ordered expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Restoring my task ... ').ordered
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'done').ordered expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Restoring my task ... done').ordered
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Watch out!').ordered expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Watch out!').ordered
expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Quitting...').ordered expect(Gitlab::BackupLogger).to receive(:info).with(message: 'Quitting...').ordered
expect(task).to receive(:restore) expect(task).to receive(:restore)
...@@ -248,6 +245,7 @@ RSpec.describe Backup::Manager do ...@@ -248,6 +245,7 @@ RSpec.describe Backup::Manager do
end end
before do before do
allow(Gitlab::BackupLogger).to receive(:info)
allow(Dir).to receive(:chdir).and_yield allow(Dir).to receive(:chdir).and_yield
allow(Dir).to receive(:glob).and_return(files) allow(Dir).to receive(:glob).and_return(files)
allow(FileUtils).to receive(:rm) allow(FileUtils).to receive(:rm)
...@@ -266,7 +264,7 @@ RSpec.describe Backup::Manager do ...@@ -266,7 +264,7 @@ RSpec.describe Backup::Manager do
end end
it 'prints a skipped message' do it 'prints a skipped message' do
expect(progress).to have_received(:puts).with('skipping') expect(Gitlab::BackupLogger).to have_received(:info).with(message: 'Deleting old backups ... [SKIPPED]')
end end
end end
...@@ -290,7 +288,7 @@ RSpec.describe Backup::Manager do ...@@ -290,7 +288,7 @@ RSpec.describe Backup::Manager do
end end
it 'prints a done message' do it 'prints a done message' do
expect(progress).to have_received(:puts).with('done. (0 removed)') expect(Gitlab::BackupLogger).to have_received(:info).with(message: 'Deleting old backups ... done. (0 removed)')
end end
end end
...@@ -307,7 +305,7 @@ RSpec.describe Backup::Manager do ...@@ -307,7 +305,7 @@ RSpec.describe Backup::Manager do
end end
it 'prints a done message' do it 'prints a done message' do
expect(progress).to have_received(:puts).with('done. (0 removed)') expect(Gitlab::BackupLogger).to have_received(:info).with(message: 'Deleting old backups ... done. (0 removed)')
end end
end end
...@@ -348,7 +346,7 @@ RSpec.describe Backup::Manager do ...@@ -348,7 +346,7 @@ RSpec.describe Backup::Manager do
end end
it 'prints a done message' do it 'prints a done message' do
expect(progress).to have_received(:puts).with('done. (8 removed)') expect(Gitlab::BackupLogger).to have_received(:info).with(message: 'Deleting old backups ... done. (8 removed)')
end end
end end
...@@ -372,11 +370,11 @@ RSpec.describe Backup::Manager do ...@@ -372,11 +370,11 @@ RSpec.describe Backup::Manager do
end end
it 'sets the correct removed count' do it 'sets the correct removed count' do
expect(progress).to have_received(:puts).with('done. (7 removed)') expect(Gitlab::BackupLogger).to have_received(:info).with(message: 'Deleting old backups ... done. (7 removed)')
end end
it 'prints the error from file that could not be removed' do it 'prints the error from file that could not be removed' do
expect(progress).to have_received(:puts).with(a_string_matching(message)) expect(Gitlab::BackupLogger).to have_received(:info).with(message: a_string_matching(message))
end end
end end
end end
...@@ -386,6 +384,7 @@ RSpec.describe Backup::Manager do ...@@ -386,6 +384,7 @@ RSpec.describe Backup::Manager do
let(:backup_filename) { File.basename(backup_file.path) } let(:backup_filename) { File.basename(backup_file.path) }
before do before do
allow(Gitlab::BackupLogger).to receive(:info)
allow(subject).to receive(:tar_file).and_return(backup_filename) allow(subject).to receive(:tar_file).and_return(backup_filename)
stub_backup_setting( stub_backup_setting(
...@@ -462,7 +461,7 @@ RSpec.describe Backup::Manager do ...@@ -462,7 +461,7 @@ RSpec.describe Backup::Manager do
it 'sets encryption attributes' do it 'sets encryption attributes' do
subject.create # rubocop:disable Rails/SaveBang subject.create # rubocop:disable Rails/SaveBang
expect(progress).to have_received(:puts).with("done (encrypted with AES256)") expect(Gitlab::BackupLogger).to have_received(:info).with(message: 'Uploading backup archive to remote storage directory ... done (encrypted with AES256)')
end end
end end
...@@ -473,7 +472,7 @@ RSpec.describe Backup::Manager do ...@@ -473,7 +472,7 @@ RSpec.describe Backup::Manager do
it 'sets encryption attributes' do it 'sets encryption attributes' do
subject.create # rubocop:disable Rails/SaveBang subject.create # rubocop:disable Rails/SaveBang
expect(progress).to have_received(:puts).with("done (encrypted with AES256)") expect(Gitlab::BackupLogger).to have_received(:info).with(message: 'Uploading backup archive to remote storage directory ... done (encrypted with AES256)')
end end
end end
...@@ -488,7 +487,7 @@ RSpec.describe Backup::Manager do ...@@ -488,7 +487,7 @@ RSpec.describe Backup::Manager do
it 'sets encryption attributes' do it 'sets encryption attributes' do
subject.create # rubocop:disable Rails/SaveBang subject.create # rubocop:disable Rails/SaveBang
expect(progress).to have_received(:puts).with("done (encrypted with aws:kms)") expect(Gitlab::BackupLogger).to have_received(:info).with(message: 'Uploading backup archive to remote storage directory ... done (encrypted with aws:kms)')
end end
end end
end end
...@@ -570,6 +569,7 @@ RSpec.describe Backup::Manager do ...@@ -570,6 +569,7 @@ RSpec.describe Backup::Manager do
Rake.application.rake_require 'tasks/gitlab/shell' Rake.application.rake_require 'tasks/gitlab/shell'
Rake.application.rake_require 'tasks/cache' Rake.application.rake_require 'tasks/cache'
allow(Gitlab::BackupLogger).to receive(:info)
allow(task1).to receive(:restore).with(File.join(Gitlab.config.backup.path, 'task1.tar.gz')) allow(task1).to receive(:restore).with(File.join(Gitlab.config.backup.path, 'task1.tar.gz'))
allow(task2).to receive(:restore).with(File.join(Gitlab.config.backup.path, 'task2.tar.gz')) allow(task2).to receive(:restore).with(File.join(Gitlab.config.backup.path, 'task2.tar.gz'))
allow(YAML).to receive(:load_file).with(File.join(Gitlab.config.backup.path, 'backup_information.yml')) allow(YAML).to receive(:load_file).with(File.join(Gitlab.config.backup.path, 'backup_information.yml'))
...@@ -680,7 +680,7 @@ RSpec.describe Backup::Manager do ...@@ -680,7 +680,7 @@ RSpec.describe Backup::Manager do
subject.restore subject.restore
expect(progress).to have_received(:print).with('Deleting backups/tmp ... ') expect(Gitlab::BackupLogger).to have_received(:info).with(message: 'Deleting backups/tmp ... ')
end end
end end
end end
...@@ -731,7 +731,7 @@ RSpec.describe Backup::Manager do ...@@ -731,7 +731,7 @@ RSpec.describe Backup::Manager do
subject.restore subject.restore
expect(progress).to have_received(:print).with('Deleting backups/tmp ... ') expect(Gitlab::BackupLogger).to have_received(:info).with(message: 'Deleting backups/tmp ... ')
end end
end end
end end
......
...@@ -199,18 +199,25 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do ...@@ -199,18 +199,25 @@ RSpec.describe 'gitlab:app namespace rake task', :delete do
end end
it 'logs the progress to log file' do it 'logs the progress to log file' do
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping database ... ") expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping database ... [SKIPPED]")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "[SKIPPED]")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping repositories ... ") expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping repositories ... ")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping repositories ... done")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping uploads ... ") expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping uploads ... ")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping uploads ... done")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping builds ... ") expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping builds ... ")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping builds ... done")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping artifacts ... ") expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping artifacts ... ")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping artifacts ... done")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping pages ... ") expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping pages ... ")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping pages ... done")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping lfs objects ... ") expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping lfs objects ... ")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping lfs objects ... done")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping terraform states ... ") expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping terraform states ... ")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping terraform states ... done")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping container registry images ... ") expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping container registry images ... ")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping container registry images ... done")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping packages ... ") expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping packages ... ")
expect(Gitlab::BackupLogger).to receive(:info).with(message: "done").exactly(9).times expect(Gitlab::BackupLogger).to receive(:info).with(message: "Dumping packages ... done")
backup_tasks.each do |task| backup_tasks.each do |task|
run_rake_task("gitlab:backup:#{task}:create") run_rake_task("gitlab:backup:#{task}:create")
......
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