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