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
end
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
def primary_node
......@@ -111,7 +111,7 @@ class GeoNode < ApplicationRecord
end
def current?
self.class.current_node_url == url
self.class.current_node_name == name
end
def secondary?
......@@ -279,7 +279,7 @@ class GeoNode < ApplicationRecord
# Prevent locking yourself out
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')
end
end
......
......@@ -70,7 +70,16 @@ module Geo
end
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
def prometheus_enabled?
......
......@@ -6,8 +6,8 @@ module Gitlab
extend self
def set_primary_geo_node
node = GeoNode.new(primary: true, url: GeoNode.current_node_url)
$stdout.puts "Saving primary Geo node with URL #{node.url} ..."
node = GeoNode.new(primary: true, name: GeoNode.current_node_name, url: GeoNode.current_node_url)
$stdout.puts "Saving primary Geo node with name #{node.name} and URL #{node.url} ..."
node.save
if node.persisted?
......
......@@ -217,7 +217,8 @@ namespace :geo do
end
puts
puts GeoNode.current_node_url
puts "Name: #{GeoNode.current_node_name}"
puts "URL: #{GeoNode.current_node_url}"
puts '-----------------------------------------------------'.color(:yellow)
unless Gitlab::Database.postgresql_minimum_supported_version?
......
......@@ -9,6 +9,7 @@ FactoryBot.define do
uri.to_s
end
name { url }
primary false
......
......@@ -3,6 +3,7 @@ require 'spec_helper'
describe Gitlab::Geo::GeoTasks do
describe '.set_primary_geo_node' 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')
end
......
......@@ -323,13 +323,13 @@ describe GeoNode, :geo, type: :model do
describe '#current?' 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
end
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
end
......
......@@ -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_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({ url: primary.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({ 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
it 'updates the GeoNodeStatus entry' do
......@@ -202,7 +203,7 @@ describe Geo::MetricsUpdateService, :geo, :prometheus do
end
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
......
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