Geo: Rails console message display primary/secondary state incorrectly

Summary

When gitlab-rails console is executed, GitLab prints a nice message with some summary information like:

-------------------------------------------------------------------------------------
GitLab: 11.2.1-ee (df8846c)
GitLab Shell: 8.1.1
postgresql: 9.6.8
Geo enabled: yes
Geo server: secondary
-------------------------------------------------------------------------------------

The last line: Geo server: does not always reflect the correct state of the server. It consider as "secondary" any non-primary server, but a server can be in a "misconfigured/not configured" state, where there is no corresponding node to that external_url.

Steps to reproduce

  • Rename a secondary node URL in Admin > Geo Node, but doesn't change it in the /etc/gitlab.rb file for that node.
  • Run gitlab-rails console. It will print Geo server: secondary while when you execute Gitlab::Geo.secondary? it will return nil.

What is the current bug behavior?

We consider secondary when !primary, but we should check for both as there is a third state possible.

What is the expected correct behavior?

It should print: 'unknown/misconfigured'.

Possible fixes

Check if Gitlab::Geo.primary? then if it is Gitlab::Geo.secondary? and fail with unknown/misconfigured otherwise.

Edited by Gabriel Mazetto