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:
```bash
$ git push
> GitLab: You're pushing to a Geo secondary.
> GitLab: We'll help you by proxying this request to the primary: ssh://git@primary.geo/user/repo.git
remote:
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
```
......
......@@ -21,7 +21,7 @@ module EE
override :check_for_console_messages
def check_for_console_messages(cmd)
super.push(
*current_replication_lag_message(cmd)
*current_replication_lag_message
)
end
......@@ -33,18 +33,6 @@ module EE
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)
return unless receive_pack?(cmd) # git push
return unless ::Gitlab::Database.read_only?
......@@ -58,13 +46,21 @@ module EE
payload = {
'action' => 'geo_proxy_to_primary',
'data' => {
'info_message' => proxying_to_primary_message,
'api_endpoints' => custom_action_api_endpoints,
'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
def push_to_read_only_message
......@@ -95,7 +91,30 @@ module EE
end
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
def custom_action_api_endpoints
......
......@@ -8,8 +8,9 @@ shared_examples 'a read-only GitLab instance' do
end
context 'for a Geo setup' do
let(:primary_node) { create(:geo_node, :primary, url: 'https://localhost:3000/gitlab') }
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(:secondary_with_primary?).and_return(secondary_with_primary)
end
......@@ -31,12 +32,19 @@ shared_examples 'a read-only GitLab instance' do
{
'action' => 'geo_proxy_to_primary',
'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},
'primary_repo' => primary_repo_url
}
}
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
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