Commit 42ea9799 authored by Ash McKenzie's avatar Ash McKenzie

Geo redirect message for all secondary HTTP pushes

parent 06dfc9ab
...@@ -18,6 +18,7 @@ module EE ...@@ -18,6 +18,7 @@ module EE
override :ee_post_receive_response_hook override :ee_post_receive_response_hook
def ee_post_receive_response_hook(response) def ee_post_receive_response_hook(response)
response.add_basic_message(geo_redirect_to_primary_message) if display_geo_redirect_to_primary_message?
response.add_basic_message(geo_secondary_lag_message) if geo_display_secondary_lag_message? response.add_basic_message(geo_secondary_lag_message) if geo_display_secondary_lag_message?
end end
...@@ -41,6 +42,19 @@ module EE ...@@ -41,6 +42,19 @@ module EE
end end
end end
def display_geo_redirect_to_primary_message?
::Gitlab::Geo.primary? && geo_redirect_to_primary_message
end
def geo_redirect_to_primary_message
return unless geo_referred_node
@geo_redirect_to_primary_message ||= begin
url = "#{::Gitlab::Geo.current_node.url.chomp('/')}/#{project.full_path}.git"
::Gitlab::Geo.redirecting_push_to_primary_message(url)
end
end
override :check_allowed override :check_allowed
def check_allowed(params) def check_allowed(params)
ip = params.fetch(:check_ip, nil) ip = params.fetch(:check_ip, nil)
......
...@@ -4,8 +4,10 @@ require 'spec_helper' ...@@ -4,8 +4,10 @@ require 'spec_helper'
describe API::Internal::Base do describe API::Internal::Base do
include EE::GeoHelpers include EE::GeoHelpers
let_it_be(:primary_node, reload: true) { create(:geo_node, :primary) } let_it_be(:primary_url) { 'http://primary.example.com' }
let_it_be(:secondary_node, reload: true) { create(:geo_node) } let_it_be(:secondary_url) { 'http://secondary.example.com' }
let_it_be(:primary_node, reload: true) { create(:geo_node, :primary, url: primary_url) }
let_it_be(:secondary_node, reload: true) { create(:geo_node, url: secondary_url) }
describe 'POST /internal/post_receive', :geo do describe 'POST /internal/post_receive', :geo do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
...@@ -96,6 +98,23 @@ describe API::Internal::Base do ...@@ -96,6 +98,23 @@ describe API::Internal::Base do
expect(json_response['messages']).not_to include({ 'message' => a_string_matching('replication lag'), 'type' => anything }) expect(json_response['messages']).not_to include({ 'message' => a_string_matching('replication lag'), 'type' => anything })
end end
end end
it 'includes a message advising a redirection occurred' do
redirect_message = <<~STR
You're pushing to a Geo secondary! We'll help you by redirecting this
request to the primary:
http://primary.example.com/#{project.full_path}.git
STR
post api('/internal/post_receive'), params: valid_params
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['messages']).to include({
'type' => 'basic',
'message' => redirect_message
})
end
end end
context 'when the push was not redirected from a Geo secondary to the primary' do context 'when the push was not redirected from a Geo secondary to the primary' do
......
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