Only notify/update geo nodes that are enabled

[ci skip]
parent af9e0b04
......@@ -17,8 +17,11 @@ module Geo
content = { projects: projects }.to_json
::Gitlab::Geo.secondary_nodes.each do |node|
next unless node.enabled?
notify_url = node.send(notify_url_method.to_sym)
success, message = notify(notify_url, content)
unless success
Rails.logger.error("GitLab failed to notify #{node.url} to #{notify_url} : #{message}")
queue.store_batched_data(projects)
......
......@@ -2,6 +2,7 @@ class GeoBackfillWorker
include Sidekiq::Worker
include CronjobQueue
LEASE_TIMEOUT = 24.hours.freeze
RUN_TIME = 5.minutes.to_i.freeze
def perform
......@@ -9,6 +10,7 @@ class GeoBackfillWorker
project_ids.each do |project_id|
break if Time.now - start >= RUN_TIME
break unless node_enabled?
project = Project.find(project_id)
next if project.repository_exists?
......@@ -30,10 +32,8 @@ class GeoBackfillWorker
end
def try_obtain_lease
uuid = Gitlab::ExclusiveLease.new(
lease_key,
timeout: 24.hours
).try_obtain
uuid = Gitlab::ExclusiveLease.new(lease_key, timeout: LEASE_TIMEOUT)
.try_obtain
return unless uuid
......@@ -49,4 +49,17 @@ class GeoBackfillWorker
def lease_key
'repository_backfill_service'
end
def node_enabled?
# No caching of the enabled! If we cache it and an admin disables
# this node, an active GeoBackfillWorker would keep going for up
# to max run time after the node was disabled.
current_node.enabled?
end
def current_node
GeoNode.find_by(host: Gitlab.config.gitlab.host,
port: Gitlab.config.gitlab.port,
relative_url_root: Gitlab.config.gitlab.relative_url_root)
end
end
......@@ -35,6 +35,7 @@ module API
# POST /geo/refresh_wikis
post 'refresh_wikis' do
authenticated_as_admin!
require_node_to_be_enabled!
required_attributes! [:projects]
::Geo::ScheduleWikiRepoUpdateService.new(params[:projects]).execute
end
......@@ -45,6 +46,7 @@ module API
# POST /geo/receive_events
post 'receive_events' do
authenticate_by_gitlab_geo_token!
require_node_to_be_enabled!
required_attributes! %w(event_name)
case params['event_name']
......@@ -75,5 +77,11 @@ module API
end
end
end
helpers do
def require_node_to_be_enabled!
forbidden! 'Geo node is disabled.' unless Gitlab::Geo.current_node.enabled?
end
end
end
end
......@@ -9,6 +9,10 @@ describe API::Geo, api: true do
{ 'X-Gitlab-Token' => geo_node.system_hook.token }
end
before(:each) do
allow(Gitlab::Geo).to receive(:current_node) { geo_node }
end
describe 'POST /geo/receive_events authentication' do
it 'denies access if token is not present' do
post api('/geo/receive_events')
......@@ -21,6 +25,26 @@ describe API::Geo, api: true do
end
end
describe 'POST /geo/refresh_wikis disabled node' do
it 'responds with forbidden' do
geo_node.enabled = false
post api('/geo/refresh_wikis', admin), nil
expect(response).to have_http_status(403)
end
end
describe 'POST /geo/receive_events disabled node' do
it 'responds with forbidden' do
geo_node.enabled = false
post api('/geo/receive_events'), nil, geo_token_header
expect(response).to have_http_status(403)
end
end
describe 'POST /geo/receive_events key events' do
before(:each) { allow_any_instance_of(::Geo::ScheduleKeyChangeService).to receive(:execute) }
......
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