Commit 59652761 authored by Stan Hu's avatar Stan Hu

Gracefully handle case where current instance is not a Geo Node

If the primary Geo Node were deleted or not configured properly,
attempts to retrieve the status of secondaries would fail with an
Error 500.
parent f29bf995
......@@ -39,6 +39,8 @@ module Geo
Array([message, details].compact.join("\n"))
end
rescue Gitlab::Geo::GeoNodeNotFoundError
['This GitLab instance does not appear to be configured properly as a Geo node. Make sure the URLs are using the correct fully-qualified domain names.']
rescue OpenSSL::Cipher::CipherError
['Error decrypting the Geo secret from the database. Check that the primary uses the correct db_key_base.']
rescue HTTParty::Error, Timeout::Error, SocketError, Errno::ECONNRESET, Errno::ECONNREFUSED => e
......
module Gitlab
module Geo
OauthApplicationUndefinedError = Class.new(StandardError)
GeoNodeNotFoundError = Class.new(StandardError)
CACHE_KEYS = %i(
geo_primary_node
......
......@@ -9,6 +9,7 @@ module Gitlab
@request_data = request_data
end
# Raises GeoNodeNotFoundError if current node is not a Geo node
def headers
{
'Authorization' => geo_auth_token(request_data)
......@@ -19,7 +20,7 @@ module Gitlab
def geo_auth_token(message)
geo_node = requesting_node
return unless geo_node
raise GeoNodeNotFoundError unless geo_node
payload = { data: message.to_json, iat: Time.now.to_i }
token = JWT.encode(payload, geo_node.secret_access_key, 'HS256')
......
......@@ -66,5 +66,13 @@ describe Geo::NodeStatusService do
expect(status.health).to eq('Error decrypting the Geo secret from the database. Check that the primary uses the correct db_key_base.')
end
it 'gracefully handles case when primary is deleted' do
primary.destroy
status = subject.call(secondary)
expect(status.health).to eq('This GitLab instance does not appear to be configured properly as a Geo node. Make sure the URLs are using the correct fully-qualified domain names.')
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