Commit a82c4514 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'mk/add-geo-node-name-to-check-task' into 'master'

Geo: Check for a current node in `rake gitlab:geo:check`

Closes #13352

See merge request gitlab-org/gitlab!22436
parents 11a1dc12 dda4a255
---
title: 'Geo: Check current node in gitlab:geo:check Rake task'
merge_request: 22436
author:
type: added
...@@ -51,6 +51,7 @@ Checking Geo ... ...@@ -51,6 +51,7 @@ Checking Geo ...
GitLab Geo is available ... yes GitLab Geo is available ... yes
GitLab Geo is enabled ... yes GitLab Geo is enabled ... yes
This machine's Geo node name matches a database record ... yes, found a secondary node named "Shanghai"
GitLab Geo secondary database is correctly configured ... yes GitLab Geo secondary database is correctly configured ... yes
Database replication enabled? ... yes Database replication enabled? ... yes
Database replication working? ... yes Database replication working? ... yes
...@@ -115,34 +116,36 @@ Any **secondary** nodes should point only to read-only instances. ...@@ -115,34 +116,36 @@ Any **secondary** nodes should point only to read-only instances.
#### Can Geo detect the current node correctly? #### Can Geo detect the current node correctly?
Geo finds the current machine's name in `/etc/gitlab/gitlab.rb` by: Geo finds the current machine's Geo node name in `/etc/gitlab/gitlab.rb` by:
- Using the `gitlab_rails['geo_node_name']` setting. - Using the `gitlab_rails['geo_node_name']` setting.
- If that is not defined, using the `external_url` setting. - If that is not defined, using the `external_url` setting.
To get a machine's name, run:
```sh
sudo gitlab-rails runner "puts GeoNode.current_node_name"
```
This name is used to look up the node with the same **Name** in This name is used to look up the node with the same **Name** in
**Admin Area > Geo**. **Admin Area > Geo**.
To check if current machine is correctly finding its node: To check if the current machine has a node name that matches a node in the
database, run the check task:
```sh ```sh
sudo gitlab-rails runner "puts Gitlab::Geo.current_node.inspect" sudo gitlab-rake gitlab:geo:check
``` ```
and expect something like: It displays the current machine's node name and whether the matching database
record is a **primary** or **secondary** node.
```ruby ```
#<GeoNode id: 2, schema: "https", host: "gitlab.example.com", port: 443, relative_url_root: "", primary: false, ...> This machine's Geo node name matches a database record ... yes, found a secondary node named "Shanghai"
``` ```
By running the command above, `primary` should be `true` when executed in ```
the **primary** node, and `false` on any **secondary** node. This machine's Geo node name matches a database record ... no
Try fixing it:
You could add or update a Geo node database record, setting the name to "https://example.com/".
Or you could set this machine's Geo node name to match the name of an existing database record: "London", "Shanghai"
For more information see:
doc/administration/geo/replication/troubleshooting.md#can-geo-detect-the-current-node-correctly
```
## Fixing errors found when running the Geo check rake task ## Fixing errors found when running the Geo check rake task
......
# frozen_string_literal: true
module SystemCheck
module Geo
class CurrentNodeCheck < SystemCheck::BaseCheck
set_name "This machine's Geo node name matches a database record"
# Overriding so we can output current node name and what record it matches, in case either is unexpected
def self.check_pass
node_type = Gitlab::Geo.primary? ? 'primary' : 'secondary'
"yes, found a #{node_type} node named \"#{GeoNode.current_node_name}\""
end
def check?
GeoNode.current_node.present?
end
def show_error
configured_name = GeoNode.current_node_name
db_names = GeoNode.all.map(&:name)
try_fixing_it(
"You could add or update a Geo node database record, setting the name to match this machine's Geo node name \"#{configured_name}\".",
"Or you could set this machine's Geo node name to match the name of an existing database record: \"#{db_names.join('", "')}\""
)
for_more_information('doc/administration/geo/replication/troubleshooting.md#can-geo-detect-the-current-node-correctly')
end
end
end
end
...@@ -20,6 +20,7 @@ module SystemCheck ...@@ -20,6 +20,7 @@ module SystemCheck
[ [
SystemCheck::Geo::LicenseCheck, SystemCheck::Geo::LicenseCheck,
SystemCheck::Geo::EnabledCheck, SystemCheck::Geo::EnabledCheck,
SystemCheck::Geo::CurrentNodeCheck,
SystemCheck::Geo::HTTPCloneEnabledCheck, SystemCheck::Geo::HTTPCloneEnabledCheck,
SystemCheck::Geo::ClocksSynchronizationCheck, SystemCheck::Geo::ClocksSynchronizationCheck,
SystemCheck::App::GitUserDefaultSSHConfigCheck, SystemCheck::App::GitUserDefaultSSHConfigCheck,
......
# frozen_string_literal: true
require 'spec_helper'
require 'rake_helper'
describe SystemCheck::Geo::CurrentNodeCheck, :geo do
describe '#check?' do
context 'when the current machine has a matching GeoNode' do
it 'returns true' do
create(:geo_node, :primary, name: GeoNode.current_node_name)
expect(subject.check?).to be_truthy
end
end
context 'when the current machine does not have a matching GeoNode' do
it 'returns false' do
expect(GeoNode).to receive(:current_node_name).and_return('Foo')
expect(subject.check?).to be_falsey
end
end
end
describe '.check_pass' do
it 'outputs additional helpful info' do
allow(GeoNode).to receive(:current_node_name).and_return('Foo')
create(:geo_node, :primary, name: GeoNode.current_node_name)
expect(described_class.check_pass).to eq('yes, found a primary node named "Foo"')
end
end
end
...@@ -9,6 +9,7 @@ describe SystemCheck::RakeTask::GeoTask do ...@@ -9,6 +9,7 @@ describe SystemCheck::RakeTask::GeoTask do
[ [
SystemCheck::Geo::LicenseCheck, SystemCheck::Geo::LicenseCheck,
SystemCheck::Geo::EnabledCheck, SystemCheck::Geo::EnabledCheck,
SystemCheck::Geo::CurrentNodeCheck,
SystemCheck::Geo::HTTPCloneEnabledCheck, SystemCheck::Geo::HTTPCloneEnabledCheck,
SystemCheck::Geo::ClocksSynchronizationCheck, SystemCheck::Geo::ClocksSynchronizationCheck,
SystemCheck::App::GitUserDefaultSSHConfigCheck, SystemCheck::App::GitUserDefaultSSHConfigCheck,
......
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