Commit 3a8d1ddc authored by Stan Hu's avatar Stan Hu

Address review feedback for StorageShard implementation

parent 8baf165b
...@@ -78,15 +78,6 @@ class GeoNodeStatus { ...@@ -78,15 +78,6 @@ class GeoNodeStatus {
}; };
} }
static sortByStorageName(config) {
return config.sort((a, b) => a.name.localeCompare(b.name));
}
static storageConfigEquals(first, second) {
return _.isEqual(GeoNodeStatus.sortByStorageName(first),
GeoNodeStatus.sortByStorageName(second));
}
static renderSyncGraph($itemEl, syncStats) { static renderSyncGraph($itemEl, syncStats) {
const graphItems = [ const graphItems = [
{ {
...@@ -224,10 +215,9 @@ class GeoNodeStatus { ...@@ -224,10 +215,9 @@ class GeoNodeStatus {
this.$secondaryVersion.text(`${status.version} (${status.revision}) - ${versionMismatch}`); this.$secondaryVersion.text(`${status.version} (${status.revision}) - ${versionMismatch}`);
} }
if (!this.primaryStorageConfiguration || !status.storage_shards) { if (!status.storage_shards_match) {
this.$secondaryStorage.text('UNKNOWN'); this.$secondaryStorage.text('UNKNOWN');
} else if (GeoNodeStatus.storageConfigEquals( } else if (status.storage_shards_match) {
this.primaryStorageConfiguration, status.storage_shards)) {
this.$secondaryStorage.removeClass(`${storageMismatchClass}`); this.$secondaryStorage.removeClass(`${storageMismatchClass}`);
this.$secondaryStorage.text('OK'); this.$secondaryStorage.text('OK');
} else { } else {
......
...@@ -5,11 +5,10 @@ class StorageShard ...@@ -5,11 +5,10 @@ class StorageShard
include ActiveModel::Model include ActiveModel::Model
attr_accessor :name, :path, :gitaly_address, :gitaly_token attr_accessor :name, :path, :gitaly_address, :gitaly_token
attr_accessor :failure_count_threshold, :failure_reset_time, :failure_wait_time
attr_accessor :storage_timeout
validates :name, presence: true validates :name, presence: true
validates :path, presence: true validates :path, presence: true
validates :gitaly_address, presence: true
# Generates an array of StorageShard objects from the currrent storage # Generates an array of StorageShard objects from the currrent storage
# configuration using the gitlab.yml array of key/value pairs: # configuration using the gitlab.yml array of key/value pairs:
...@@ -17,10 +16,15 @@ class StorageShard ...@@ -17,10 +16,15 @@ class StorageShard
# {"default"=>{"path"=>"/home/git/repositories", ...} # {"default"=>{"path"=>"/home/git/repositories", ...}
# #
# The key is the shard name, and the values are the parameters for that shard. # The key is the shard name, and the values are the parameters for that shard.
def self.current_shards def self.all
Settings.repositories.storages.map do |name, params| Settings.repositories.storages.map do |name, params|
config = params.symbolize_keys.merge(name: name) config = params.symbolize_keys.merge(name: name)
config.slice!(allowed_params)
StorageShard.new(config) StorageShard.new(config)
end end
end end
def self.allowed_params
return %w(name path gitaly_address gitaly_token).freeze
end
end end
...@@ -8,7 +8,7 @@ class Admin::GeoNodesController < Admin::ApplicationController ...@@ -8,7 +8,7 @@ class Admin::GeoNodesController < Admin::ApplicationController
def index def index
@nodes = GeoNode.all.order(:id) @nodes = GeoNode.all.order(:id)
@node = GeoNode.new @node = GeoNode.new
@current_storage_shards = StorageShardSerializer.new.represent(StorageShard.current_shards) @current_storage_shards = StorageShardSerializer.new.represent(StorageShard.all)
unless Gitlab::Geo.license_allows? unless Gitlab::Geo.license_allows?
flash_now(:alert, 'You need a different license to enable Geo replication') flash_now(:alert, 'You need a different license to enable Geo replication')
......
...@@ -75,7 +75,7 @@ class GeoNodeStatus < ActiveRecord::Base ...@@ -75,7 +75,7 @@ class GeoNodeStatus < ActiveRecord::Base
self.lfs_objects_count = lfs_objects_finder.count_lfs_objects self.lfs_objects_count = lfs_objects_finder.count_lfs_objects
self.attachments_count = attachments_finder.count_attachments self.attachments_count = attachments_finder.count_attachments
self.last_successful_status_check_at = Time.now self.last_successful_status_check_at = Time.now
self.storage_shards = StorageShard.current_shards self.storage_shards = StorageShard.all
if Gitlab::Geo.primary? if Gitlab::Geo.primary?
self.replication_slots_count = geo_node.replication_slots_count self.replication_slots_count = geo_node.replication_slots_count
...@@ -154,6 +154,12 @@ class GeoNodeStatus < ActiveRecord::Base ...@@ -154,6 +154,12 @@ class GeoNodeStatus < ActiveRecord::Base
calc_percentage(replication_slots_count, replication_slots_used_count) calc_percentage(replication_slots_count, replication_slots_used_count)
end end
def storage_shards_match?
return unless Gitlab::Geo.primary?
storage_shards.as_json == StorageShard.all.as_json
end
def [](key) def [](key)
public_send(key) # rubocop:disable GitlabSecurity/PublicSend public_send(key) # rubocop:disable GitlabSecurity/PublicSend
end end
......
...@@ -69,6 +69,10 @@ class GeoNodeStatusEntity < Grape::Entity ...@@ -69,6 +69,10 @@ class GeoNodeStatusEntity < Grape::Entity
status.storage_shards.present? status.storage_shards.present?
end end
expose :storage_shards_match?, as: :storage_shards_match, if: -> (status, options) do
Gitlab::Geo.primary? && status.storage_shards.present?
end
private private
def namespaces def namespaces
......
...@@ -29,10 +29,7 @@ ...@@ -29,10 +29,7 @@
- if node.current? - if node.current?
.node-badge.current-node Current node .node-badge.current-node Current node
- if node.primary? - if node.primary?
- if node.current? .node-badge.primary-node Primary
.node-badge.primary-node{ data: { storage_shards: @current_storage_shards.to_json } } Primary
- else
.node-badge.primary-node
%p %p
%span.help-block Primary node %span.help-block Primary node
%p %p
......
...@@ -398,7 +398,7 @@ describe GeoNodeStatus, :geo do ...@@ -398,7 +398,7 @@ describe GeoNodeStatus, :geo do
describe '#storage_shards' do describe '#storage_shards' do
it "returns the current node's shard config" do it "returns the current node's shard config" do
expect(subject[:storage_shards].as_json).to eq(StorageShard.current_shards.as_json) expect(subject[:storage_shards].as_json).to eq(StorageShard.all.as_json)
end end
end end
......
...@@ -2,7 +2,7 @@ FactoryBot.define do ...@@ -2,7 +2,7 @@ FactoryBot.define do
factory :geo_node_status do factory :geo_node_status do
sequence(:id) sequence(:id)
geo_node geo_node
storage_shards { [{ name: 'default', path: '/tmp/test' }] } storage_shards { StorageShard.all.as_json }
trait :healthy do trait :healthy do
health nil health nil
......
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