Commit 2b5d1fab authored by Michael Kozono's avatar Michael Kozono

Use Name to identify Geo nodes

Instead of URL. This frees up URL so it doesn’t have to match the
gitlab.rb external_url, which frees up external_url so it doesn’t have
to be unique.
parent 58d8c963
...@@ -71,9 +71,9 @@ class GeoNode < ApplicationRecord ...@@ -71,9 +71,9 @@ class GeoNode < ApplicationRecord
end end
def current_node def current_node
return unless column_names.include?('url') return unless column_names.include?('name')
GeoNode.find_by(url: current_node_url) GeoNode.find_by(name: current_node_name)
end end
def primary_node def primary_node
...@@ -111,7 +111,7 @@ class GeoNode < ApplicationRecord ...@@ -111,7 +111,7 @@ class GeoNode < ApplicationRecord
end end
def current? def current?
self.class.current_node_url == url self.class.current_node_name == name
end end
def secondary? def secondary?
...@@ -279,7 +279,7 @@ class GeoNode < ApplicationRecord ...@@ -279,7 +279,7 @@ class GeoNode < ApplicationRecord
# Prevent locking yourself out # Prevent locking yourself out
def check_not_adding_primary_as_secondary def check_not_adding_primary_as_secondary
if url == self.class.current_node_url if name == self.class.current_node_name
errors.add(:base, 'Current node must be the primary node or you will be locking yourself out') errors.add(:base, 'Current node must be the primary node or you will be locking yourself out')
end end
end end
......
...@@ -70,7 +70,16 @@ module Geo ...@@ -70,7 +70,16 @@ module Geo
end end
def metric_labels(node) def metric_labels(node)
{ url: node.url } labels = { name: node.name }
# Installations that existed before 11.11 were using the `url` label. This
# line preserves continuity of metrics.
#
# This can be removed in 12.0+ since there will have been at least one
# release worth of data labeled with `name`.
labels[:url] = node.name
labels
end end
def prometheus_enabled? def prometheus_enabled?
......
...@@ -6,8 +6,8 @@ module Gitlab ...@@ -6,8 +6,8 @@ module Gitlab
extend self extend self
def set_primary_geo_node def set_primary_geo_node
node = GeoNode.new(primary: true, url: GeoNode.current_node_url) node = GeoNode.new(primary: true, name: GeoNode.current_node_name, url: GeoNode.current_node_url)
$stdout.puts "Saving primary Geo node with URL #{node.url} ..." $stdout.puts "Saving primary Geo node with name #{node.name} and URL #{node.url} ..."
node.save node.save
if node.persisted? if node.persisted?
......
...@@ -217,7 +217,8 @@ namespace :geo do ...@@ -217,7 +217,8 @@ namespace :geo do
end end
puts puts
puts GeoNode.current_node_url puts "Name: #{GeoNode.current_node_name}"
puts "URL: #{GeoNode.current_node_url}"
puts '-----------------------------------------------------'.color(:yellow) puts '-----------------------------------------------------'.color(:yellow)
unless Gitlab::Database.postgresql_minimum_supported_version? unless Gitlab::Database.postgresql_minimum_supported_version?
......
...@@ -9,6 +9,7 @@ FactoryBot.define do ...@@ -9,6 +9,7 @@ FactoryBot.define do
uri.to_s uri.to_s
end end
name { url }
primary false primary false
......
...@@ -3,6 +3,7 @@ require 'spec_helper' ...@@ -3,6 +3,7 @@ require 'spec_helper'
describe Gitlab::Geo::GeoTasks do describe Gitlab::Geo::GeoTasks do
describe '.set_primary_geo_node' do describe '.set_primary_geo_node' do
before do before do
allow(GeoNode).to receive(:current_node_name).and_return('https://primary.geo.example.com')
allow(GeoNode).to receive(:current_node_url).and_return('https://primary.geo.example.com') allow(GeoNode).to receive(:current_node_url).and_return('https://primary.geo.example.com')
end end
......
...@@ -323,13 +323,13 @@ describe GeoNode, :geo, type: :model do ...@@ -323,13 +323,13 @@ describe GeoNode, :geo, type: :model do
describe '#current?' do describe '#current?' do
it 'returns true when node is the current node' do it 'returns true when node is the current node' do
node = described_class.new(url: described_class.current_node_url) node = described_class.new(name: described_class.current_node_name)
expect(node.current?).to be_truthy expect(node.current?).to be_truthy
end end
it 'returns false when node is not the current node' do it 'returns false when node is not the current node' do
node = described_class.new(url: 'http://another.node.com:8080/foo') node = described_class.new(name: 'some other node')
expect(node.current?).to be_falsy expect(node.current?).to be_falsy
end end
......
...@@ -116,9 +116,10 @@ describe Geo::MetricsUpdateService, :geo, :prometheus do ...@@ -116,9 +116,10 @@ describe Geo::MetricsUpdateService, :geo, :prometheus do
expect(Gitlab::Metrics.registry.get(:geo_db_replication_lag_seconds).values.count).to eq(2) expect(Gitlab::Metrics.registry.get(:geo_db_replication_lag_seconds).values.count).to eq(2)
expect(Gitlab::Metrics.registry.get(:geo_repositories).values.count).to eq(3) expect(Gitlab::Metrics.registry.get(:geo_repositories).values.count).to eq(3)
expect(Gitlab::Metrics.registry.get(:geo_repositories).get({ url: secondary.url })).to eq(10)
expect(Gitlab::Metrics.registry.get(:geo_repositories).get({ url: another_secondary.url })).to eq(10) expect(Gitlab::Metrics.registry.get(:geo_repositories).get({ name: secondary.name, url: secondary.name })).to eq(10)
expect(Gitlab::Metrics.registry.get(:geo_repositories).get({ url: primary.url })).to eq(10) expect(Gitlab::Metrics.registry.get(:geo_repositories).get({ name: another_secondary.name, url: another_secondary.name })).to eq(10)
expect(Gitlab::Metrics.registry.get(:geo_repositories).get({ name: primary.name, url: primary.name })).to eq(10)
end end
it 'updates the GeoNodeStatus entry' do it 'updates the GeoNodeStatus entry' do
...@@ -202,7 +203,7 @@ describe Geo::MetricsUpdateService, :geo, :prometheus do ...@@ -202,7 +203,7 @@ describe Geo::MetricsUpdateService, :geo, :prometheus do
end end
def metric_value(metric_name) def metric_value(metric_name)
Gitlab::Metrics.registry.get(metric_name)&.get({ url: secondary.url }) Gitlab::Metrics.registry.get(metric_name)&.get({ name: secondary.name, url: secondary.name })
end end
end end
end end
......
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