Commit e30e9a9b authored by Ash McKenzie's avatar Ash McKenzie

Use gl_console_messages in favour of info_message

parent a9536dd6
...@@ -10,8 +10,12 @@ Example of the output you will see when pushing to a **secondary** node: ...@@ -10,8 +10,12 @@ Example of the output you will see when pushing to a **secondary** node:
```bash ```bash
$ git push $ git push
> GitLab: You're pushing to a Geo secondary. remote:
> GitLab: We'll help you by proxying this request to the primary: ssh://git@primary.geo/user/repo.git remote: You're pushing to a Geo secondary. We'll help you by proxying this
remote: request to the primary:
remote:
remote: ssh://git@primary.geo/user/repo.git
remote:
Everything up-to-date Everything up-to-date
``` ```
......
...@@ -21,7 +21,7 @@ module EE ...@@ -21,7 +21,7 @@ module EE
override :check_for_console_messages override :check_for_console_messages
def check_for_console_messages(cmd) def check_for_console_messages(cmd)
super.push( super.push(
*current_replication_lag_message(cmd) *current_replication_lag_message
) )
end end
...@@ -33,18 +33,6 @@ module EE ...@@ -33,18 +33,6 @@ module EE
private private
def current_replication_lag_message(cmd)
return unless upload_pack?(cmd) # git fetch / pull
return unless ::Gitlab::Database.read_only?
return unless current_replication_lag > 0
"Current replication lag: #{current_replication_lag} seconds"
end
def current_replication_lag
@current_replication_lag ||= ::Gitlab::Geo::HealthCheck.new.db_replication_lag_seconds
end
def custom_action_for?(cmd) def custom_action_for?(cmd)
return unless receive_pack?(cmd) # git push return unless receive_pack?(cmd) # git push
return unless ::Gitlab::Database.read_only? return unless ::Gitlab::Database.read_only?
...@@ -58,13 +46,21 @@ module EE ...@@ -58,13 +46,21 @@ module EE
payload = { payload = {
'action' => 'geo_proxy_to_primary', 'action' => 'geo_proxy_to_primary',
'data' => { 'data' => {
'info_message' => proxying_to_primary_message,
'api_endpoints' => custom_action_api_endpoints, 'api_endpoints' => custom_action_api_endpoints,
'primary_repo' => primary_http_repo_url 'primary_repo' => primary_http_repo_url
} }
} }
::Gitlab::GitAccessResult::CustomAction.new(payload, 'Attempting to proxy to primary.') ::Gitlab::GitAccessResult::CustomAction.new(payload, 'Attempting to proxy to primary.', messages)
end
def messages
messages = proxying_to_primary_message
lag_message = current_replication_lag_message
return messages unless lag_message
messages + ['', lag_message]
end end
def push_to_read_only_message def push_to_read_only_message
...@@ -95,7 +91,30 @@ module EE ...@@ -95,7 +91,30 @@ module EE
end end
def proxying_to_primary_message def proxying_to_primary_message
"You're pushing to a Geo secondary.\nWe'll help you by proxying this request to the primary: #{primary_ssh_url_to_repo}" # This is formatted like this to fit into the console 'box', e.g.
#
# remote:
# remote: You're pushing to a Geo secondary! We'll help you by proxying this
# remote: request to the primary:
# remote:
# remote: ssh://<user>@<host>:<port>/<group>/<repo>.git
# remote:
<<~STR.split("\n")
You're pushing to a Geo secondary! We'll help you by proxying this
request to the primary:
#{primary_ssh_url_to_repo}
STR
end
def current_replication_lag_message
return if ::Gitlab::Database.read_write? || current_replication_lag.zero?
"Current replication lag: #{current_replication_lag} seconds"
end
def current_replication_lag
@current_replication_lag ||= ::Gitlab::Geo::HealthCheck.new.db_replication_lag_seconds
end end
def custom_action_api_endpoints def custom_action_api_endpoints
......
...@@ -8,8 +8,9 @@ shared_examples 'a read-only GitLab instance' do ...@@ -8,8 +8,9 @@ shared_examples 'a read-only GitLab instance' do
end end
context 'for a Geo setup' do context 'for a Geo setup' do
let(:primary_node) { create(:geo_node, :primary, url: 'https://localhost:3000/gitlab') }
before do before do
primary_node = create(:geo_node, :primary, url: 'https://localhost:3000/gitlab')
allow(Gitlab::Geo).to receive(:primary).and_return(primary_node) allow(Gitlab::Geo).to receive(:primary).and_return(primary_node)
allow(Gitlab::Geo).to receive(:secondary_with_primary?).and_return(secondary_with_primary) allow(Gitlab::Geo).to receive(:secondary_with_primary?).and_return(secondary_with_primary)
end end
...@@ -31,12 +32,19 @@ shared_examples 'a read-only GitLab instance' do ...@@ -31,12 +32,19 @@ shared_examples 'a read-only GitLab instance' do
{ {
'action' => 'geo_proxy_to_primary', 'action' => 'geo_proxy_to_primary',
'data' => { 'data' => {
'info_message' => "You're pushing to a Geo secondary.\nWe'll help you by proxying this request to the primary: #{primary_repo_ssh_url}",
'api_endpoints' => %w{/api/v4/geo/proxy_git_push_ssh/info_refs /api/v4/geo/proxy_git_push_ssh/push}, 'api_endpoints' => %w{/api/v4/geo/proxy_git_push_ssh/info_refs /api/v4/geo/proxy_git_push_ssh/push},
'primary_repo' => primary_repo_url 'primary_repo' => primary_repo_url
} }
} }
end end
let(:console_messages) do
[
"You're pushing to a Geo secondary! We'll help you by proxying this",
"request to the primary:",
"",
" #{primary_repo_ssh_url}"
]
end
it 'attempts to proxy to the primary' do it 'attempts to proxy to the primary' do
project.add_maintainer(user) project.add_maintainer(user)
......
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