Commit e010e5cd authored by James Lopez's avatar James Lopez

refactor some error logging, added last_repository_sync_failure to project registry and spec

parent dcfc2491
......@@ -150,6 +150,12 @@ module Geo
registry.update!(attrs)
end
def fail_registry(message, error)
log_error(message, error)
registry.update!(last_repository_sync_failure: "#{message}: #{error.message}")
end
def type
self.class.type
end
......
......@@ -20,23 +20,20 @@ module Geo
else
project.ensure_repository
fetch_geo_mirror(project.repository)
end
end update_registry(finished_at: DateTime.now)
update_registry(finished_at: DateTime.now)
log_info('Finished repository sync',
update_delay_s: update_delay_in_seconds,
download_time_s: download_time_in_seconds)
rescue Gitlab::Shell::Error,
Gitlab::Git::RepositoryMirroring::RemoteError,
Geo::EmptyCloneUrlPrefixError => e
log_error('Error syncing repository', e)
registry.increment!(:repository_retry_count)
rescue Gitlab::Git::Repository::NoRepository => e
log_error('Invalid repository', e)
fail_registry('Error syncing repository', e)
registry.increment!(:repository_retry_count)rescue Gitlab::Git::Repository::NoRepository => e
fail_registry('Invalid repository', e)
log_info('Setting force_to_redownload flag')
registry.update(force_to_redownload_repository: true,
repository_retry_count: retry_count + 1)
log_info('Expiring caches')
repository_retry_count: retry_count + 1) log_info('Expiring caches')
project.repository.after_create
ensure
clean_up_temporary_repository if redownload
......
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20171101105200) do
ActiveRecord::Schema.define(version: 20171115143841) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -50,6 +50,7 @@ ActiveRecord::Schema.define(version: 20171101105200) do
t.integer "wiki_retry_count"
t.datetime "wiki_retry_at"
t.boolean "force_to_redownload_wiki"
t.string "last_repository_sync_failure"
end
add_index "project_registry", ["last_repository_successful_sync_at"], name: "index_project_registry_on_last_repository_successful_sync_at", using: :btree
......
module Gitlab
module Geo
include LogHelpers
InvalidDecryptionKeyError = Class.new(StandardError)
class JwtRequestDecoder
......@@ -33,7 +35,7 @@ module Gitlab
data = decode_auth_header
rescue OpenSSL::Cipher::CipherError
message = 'Error decrypting the Geo secret from the database. Check that the primary and secondary have the same db_key_base.'
Rails.logger.error(message)
log_error(message)
raise InvalidDecryptionKeyError.new(message)
end
......@@ -54,7 +56,7 @@ module Gitlab
data&.deep_symbolize_keys!
data
rescue JWT::DecodeError => e
Rails.logger.error("Error decoding Geo request: #{e}")
log_error("Error decoding Geo request: #{e}")
return
end
end
......
......@@ -26,7 +26,7 @@ module Gitlab
end
def fetch_ref
@project.repository.fetch_ref(@project.repository, source_ref: @diff_head_sha, target_ref: @merge_request.source_branch)
@project.repository.fetceh_ref(@project.repository, source_ref: @diff_head_sha, target_ref: @merge_request.source_branch)
end
def branch_exists?(branch_name)
......
......@@ -145,7 +145,7 @@ describe Geo::RepositorySyncService do
let(:registry) { Geo::ProjectRegistry.find_by(project_id: project.id) }
before do
allow(repository).to receive(:fetch_as_mirror).with(url_to_repo, forced: true) { raise Gitlab::Shell::Error }
allow(repository).to receive(:fetch_as_mirror).with(url_to_repo, forced: true) { raise Gitlab::Shell::Error, 'shell error' }
subject.execute
end
......@@ -223,6 +223,10 @@ describe Geo::RepositorySyncService do
# of range" in the first update to the project registry.
registry.reload
expect(registry.repository_retry_at).to be_nil
it 'sets last_repository_sync_failure' do
expect(registry.last_repository_sync_failure).to eq('Error syncing repository: shell error')
end
end
end
......
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