Commit 4944db99 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch...

Merge branch '202037-geo-ssh-clone-pull-redirect-to-primary-when-selective-sync-enabled-and-project-not-selected-pre' into 'master'

Geo: Simplify Geo proxying/redirecting messages

See merge request gitlab-org/gitlab!28178
parents b5834108 84b1d700
...@@ -51,7 +51,7 @@ module EE ...@@ -51,7 +51,7 @@ module EE
@geo_redirect_to_primary_message ||= begin @geo_redirect_to_primary_message ||= begin
url = "#{::Gitlab::Geo.current_node.url.chomp('/')}/#{project.full_path}.git" url = "#{::Gitlab::Geo.current_node.url.chomp('/')}/#{project.full_path}.git"
::Gitlab::Geo.redirecting_push_to_primary_message(url) ::Gitlab::Geo.interacting_with_primary_message(url)
end end
end end
......
...@@ -40,7 +40,7 @@ module EE ...@@ -40,7 +40,7 @@ module EE
end end
def messages def messages
messages = ::Gitlab::Geo.proxying_push_to_primary_message(primary_ssh_url_to_repo).split("\n") messages = ::Gitlab::Geo.interacting_with_primary_message(primary_ssh_url_to_repo).split("\n")
lag_message = current_replication_lag_message lag_message = current_replication_lag_message
return messages unless lag_message return messages unless lag_message
......
...@@ -137,33 +137,25 @@ module Gitlab ...@@ -137,33 +137,25 @@ module Gitlab
Gitlab::CIDR.new(allowed_ips).match?(ip) Gitlab::CIDR.new(allowed_ips).match?(ip)
end end
def self.proxying_push_to_primary_message(url) def self.interacting_with_primary_message(url)
push_to_primary_message(url, 'proxying') return unless url
end
def self.redirecting_push_to_primary_message(url)
push_to_primary_message(url, 'redirecting')
end
def self.push_to_primary_message(url, action)
return unless url && action
# This is formatted like this to fit into the console 'box', e.g. # This is formatted like this to fit into the console 'box', e.g.
# #
# remote: # remote:
# remote: You're pushing to a Geo secondary! We'll help you by <action> this # remote: This request to a Geo secondary node will be forwarded to the
# remote: request to the primary: # remote: Geo primary node:
# remote: # remote:
# remote: <url> # remote: <url>
# remote: # remote:
template = <<~STR template = <<~STR
You're pushing to a Geo secondary! We'll help you by %{action} this This request to a Geo secondary node will be forwarded to the
request to the primary: Geo primary node:
%{url} %{url}
STR STR
_(template) % { action: _(action), url: url } _(template) % { url: url }
end end
end end
end end
...@@ -312,13 +312,13 @@ describe Gitlab::Geo, :geo, :request_store do ...@@ -312,13 +312,13 @@ describe Gitlab::Geo, :geo, :request_store do
it 'returns a message as a string' do it 'returns a message as a string' do
url = 'ssh://git@primary.com/namespace/repo.git' url = 'ssh://git@primary.com/namespace/repo.git'
message = <<~STR message = <<~STR
You're pushing to a Geo secondary! We'll help you by proxying this This request to a Geo secondary node will be forwarded to the
request to the primary: Geo primary node:
#{url} #{url}
STR STR
expect(described_class.proxying_push_to_primary_message(url)).to eq(message) expect(described_class.interacting_with_primary_message(url)).to eq(message)
end end
end end
...@@ -326,13 +326,13 @@ describe Gitlab::Geo, :geo, :request_store do ...@@ -326,13 +326,13 @@ describe Gitlab::Geo, :geo, :request_store do
it 'returns a message as a string' do it 'returns a message as a string' do
url = 'http://primary.com/namespace/repo.git' url = 'http://primary.com/namespace/repo.git'
message = <<~STR message = <<~STR
You're pushing to a Geo secondary! We'll help you by redirecting this This request to a Geo secondary node will be forwarded to the
request to the primary: Geo primary node:
#{url} #{url}
STR STR
expect(described_class.redirecting_push_to_primary_message(url)).to eq(message) expect(described_class.interacting_with_primary_message(url)).to eq(message)
end end
end end
end end
...@@ -101,8 +101,8 @@ describe API::Internal::Base do ...@@ -101,8 +101,8 @@ describe API::Internal::Base do
it 'includes a message advising a redirection occurred' do it 'includes a message advising a redirection occurred' do
redirect_message = <<~STR redirect_message = <<~STR
You're pushing to a Geo secondary! We'll help you by redirecting this This request to a Geo secondary node will be forwarded to the
request to the primary: Geo primary node:
http://primary.example.com/#{project.full_path}.git http://primary.example.com/#{project.full_path}.git
STR STR
......
...@@ -39,8 +39,8 @@ RSpec.shared_examples 'a read-only GitLab instance' do ...@@ -39,8 +39,8 @@ RSpec.shared_examples 'a read-only GitLab instance' do
end end
let(:console_messages) do let(:console_messages) do
[ [
"You're pushing to a Geo secondary! We'll help you by proxying this", "This request to a Geo secondary node will be forwarded to the",
"request to the primary:", "Geo primary node:",
"", "",
" #{primary_repo_ssh_url}" " #{primary_repo_ssh_url}"
] ]
......
...@@ -83,7 +83,7 @@ module QA ...@@ -83,7 +83,7 @@ module QA
# as ssh:// can appear depending on how GitLab is configured. # as ssh:// can appear depending on how GitLab is configured.
ssh_uri = project.repository_ssh_location.git_uri.to_s.gsub(%r{ssh://}, '') ssh_uri = project.repository_ssh_location.git_uri.to_s.gsub(%r{ssh://}, '')
expect(push.output).to match(%r{We'll help you by proxying this.*request to the primary:.*#{ssh_uri}}m) expect(push.output).to match(%r{This request to a Geo secondary node will be forwarded to the.*Geo primary node:.*#{ssh_uri}}m)
# Validate git push worked and new content is visible # Validate git push worked and new content is visible
Page::Project::Show.perform do |show| Page::Project::Show.perform do |show|
...@@ -171,7 +171,7 @@ module QA ...@@ -171,7 +171,7 @@ module QA
end end
ssh_uri = project.repository_ssh_location.git_uri.to_s.gsub(%r{ssh://}, '') ssh_uri = project.repository_ssh_location.git_uri.to_s.gsub(%r{ssh://}, '')
expect(push.output).to match(%r{We'll help you by proxying this.*request to the primary:.*#{ssh_uri}}m) expect(push.output).to match(%r{This request to a Geo secondary node will be forwarded to the.*Geo primary node:.*#{ssh_uri}}m)
expect(push.output).to match(/Locking support detected on remote "#{location.uri}"/) expect(push.output).to match(/Locking support detected on remote "#{location.uri}"/)
# Validate git push worked and new content is visible # Validate git push worked and new content is visible
......
...@@ -86,7 +86,7 @@ module QA ...@@ -86,7 +86,7 @@ module QA
# as ssh:// can appear depending on how GitLab is configured. # as ssh:// can appear depending on how GitLab is configured.
ssh_uri = wiki.repository_ssh_location.git_uri.to_s.gsub(%r{ssh://}, '') ssh_uri = wiki.repository_ssh_location.git_uri.to_s.gsub(%r{ssh://}, '')
expect(push.output).to match(%r{We'll help you by proxying this.*request to the primary:.*#{ssh_uri}}m) expect(push.output).to match(%r{This request to a Geo secondary node will be forwarded to the.*Geo primary node:.*#{ssh_uri}}m)
# Validate git push worked and new content is visible # Validate git push worked and new content is visible
Page::Project::Menu.perform(&:click_wiki) Page::Project::Menu.perform(&:click_wiki)
......
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