Commit c116f36c authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'add-more-logging-to-repository-mirror-feature' into 'master'

Add more logging to repository mirror feature

See merge request !2292
parents 6856da43 73fa41ec
......@@ -84,6 +84,20 @@ module EE
mirror? && self.mirror_last_update_at
end
def mirror_waiting_duration
return unless mirror?
(mirror_data.last_update_started_at.to_i -
mirror_data.last_update_scheduled_at.to_i).seconds
end
def mirror_update_duration
return unless mirror?
(mirror_last_update_at.to_i -
mirror_data.last_update_started_at.to_i).seconds
end
def mirror_with_content?
mirror? && !empty_repo?
end
......@@ -190,6 +204,7 @@ module EE
super
elsif mirror?
::Gitlab::Mirror.increment_metric(:mirrors_scheduled, 'Mirrors scheduled count')
Rails.logger.info("Mirror update for #{full_path} was scheduled.")
RepositoryUpdateMirrorWorker.perform_async(self.id)
end
......
......@@ -41,19 +41,23 @@ class RepositoryUpdateMirrorWorker
def start_mirror(project)
project.import_start
Gitlab::Mirror.increment_metric(:mirrors_running, 'Mirrors running count')
Rails.logger.info("Mirror update for #{project.full_path} started. Waiting duration: #{project.mirror_waiting_duration}")
end
def fail_mirror(project, message)
project.mark_import_as_failed(message)
error_message = "Mirror update for #{project.full_path} failed with the following message: #{message}"
project.mark_import_as_failed(error_message)
Gitlab::Mirror.increment_metric(:mirrors_failed, 'Mirrors failed count')
Rails.logger.error(message)
Rails.logger.error(error_message)
end
def finish_mirror(project)
project.import_finish
Gitlab::Mirror.increment_metric(:mirrors_finished, 'Mirrors successfully finished count')
Rails.logger.info("Mirror update for #{project.full_path} successfully finished. Update duration: #{project.mirror_update_duration}}.")
end
end
......@@ -28,10 +28,18 @@ FactoryGirl.define do
trait :import_scheduled do
import_status :scheduled
after(:create) do |project, _|
project.mirror_data&.update_attributes(last_update_scheduled_at: Time.now)
end
end
trait :import_started do
import_status :started
after(:create) do |project, _|
project.mirror_data&.update_attributes(last_update_started_at: Time.now)
end
end
trait :import_finished do
......
......@@ -117,6 +117,27 @@ describe Project, models: true do
end
end
describe '#mirror_waiting_duration' do
it 'returns in seconds the time spent in the queue' do
project = create(:empty_project, :mirror, :import_scheduled)
mirror_data = project.mirror_data
mirror_data.update_attributes(last_update_started_at: mirror_data.last_update_scheduled_at + 5.minutes)
expect(project.mirror_waiting_duration).to eq(300)
end
end
describe '#mirror_update_duration' do
it 'returns in seconds the time spent updating' do
project = create(:empty_project, :mirror, :import_started)
project.update_attributes(mirror_last_update_at: project.mirror_data.last_update_started_at + 5.minutes)
expect(project.mirror_update_duration).to eq(300)
end
end
describe '#any_runners_limit' do
let(:project) { create(:empty_project, shared_runners_enabled: shared_runners_enabled) }
let(:specific_runner) { create(:ci_runner) }
......
......@@ -49,7 +49,7 @@ describe RepositoryUpdateMirrorWorker do
end
context 'threshold_reached?' do
let(:mirror) { create(:project, :mirror) }
let(:mirror) { create(:project, :mirror, :import_scheduled) }
before do
expect_any_instance_of(Projects::UpdateMirrorService).to receive(:execute).and_return(status: :success)
......
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