Commit 4dfe2b4d authored by Michael Kozono's avatar Michael Kozono

Merge branch '298725-gitlab-ctl-promotion-preflight-checks-incorrectly-fails-with-0' into 'master'

Fix Geo replication status for replicables with no data to sync

See merge request gitlab-org/gitlab!52253
parents 2bfd2a93 5632f414
...@@ -404,6 +404,10 @@ class GeoNodeStatus < ApplicationRecord ...@@ -404,6 +404,10 @@ class GeoNodeStatus < ApplicationRecord
public_send("#{replicator_class.replicable_name_plural}_checksummed_in_percentage") # rubocop:disable GitlabSecurity/PublicSend public_send("#{replicator_class.replicable_name_plural}_checksummed_in_percentage") # rubocop:disable GitlabSecurity/PublicSend
end end
def count_for(replicator_class)
public_send("#{replicator_class.replicable_name_plural}_count") # rubocop:disable GitlabSecurity/PublicSend
end
def storage_shards_match? def storage_shards_match?
return true if geo_node.primary? return true if geo_node.primary?
return false unless storage_configuration_digest && primary_storage_digest return false unless storage_configuration_digest && primary_storage_digest
......
---
title: Fix Geo replication and verification status for replicables with no data to
sync
merge_request: 52253
author:
type: fixed
...@@ -61,45 +61,64 @@ module Gitlab ...@@ -61,45 +61,64 @@ module Gitlab
end end
def replication_verification_complete? def replication_verification_complete?
success_status = [ checks_status =
current_node_status.repositories_synced_in_percentage, legacy_replication_and_verification_checks_status +
current_node_status.repositories_checksummed_in_percentage, replication_and_verification_checks_status +
current_node_status.wikis_synced_in_percentage, conditional_replication_and_verification_checks_status
current_node_status.wikis_checksummed_in_percentage,
current_node_status.lfs_objects_synced_in_percentage, checks_status.compact.all? { |percentage| percentage == 100 }
current_node_status.job_artifacts_synced_in_percentage,
current_node_status.attachments_synced_in_percentage,
current_node_status.replication_slots_used_in_percentage,
current_node_status.design_repositories_synced_in_percentage
] + conditional_checks_status
success_status.all? { |percentage| percentage == 100 }
end end
private private
def conditional_checks_status # rubocop:disable GitlabSecurity/PublicSend
def legacy_replication_and_verification_checks_status
replicables = [
["repositories", Gitlab::Geo.repository_verification_enabled?],
["wikis", Gitlab::Geo.repository_verification_enabled?],
["lfs_objects", false],
["job_artifacts", false],
["attachments", false],
["design_repositories", false]
]
[].tap do |status|
replicables.each do |replicable_name, verification_enabled|
next unless current_node_status.public_send("#{replicable_name}_count").to_i > 0
status.push current_node_status.public_send("#{replicable_name}_synced_in_percentage")
if verification_enabled
status.push current_node_status.public_send("#{replicable_name}_verified_in_percentage")
end
end
end
end
# rubocop:enable GitlabSecurity/PublicSend
def replication_and_verification_checks_status
[].tap do |status| [].tap do |status|
Gitlab::Geo.enabled_replicator_classes.each do |replicator_class| Gitlab::Geo.enabled_replicator_classes.each do |replicator_class|
next unless current_node_status.count_for(replicator_class).to_i > 0
status.push current_node_status.synced_in_percentage_for(replicator_class) status.push current_node_status.synced_in_percentage_for(replicator_class)
if replicator_class.verification_enabled? if replicator_class.verification_enabled?
status.push current_node_status.checksummed_in_percentage_for(replicator_class) status.push current_node_status.checksummed_in_percentage_for(replicator_class)
end end
end end
end
end
if Gitlab::Geo.repository_verification_enabled? def conditional_replication_and_verification_checks_status
status.push current_node_status.repositories_verified_in_percentage [].tap do |status|
status.push current_node_status.wikis_verified_in_percentage if Gitlab::CurrentSettings.repository_checks_enabled && current_node_status.repositories_count.to_i > 0
status.push current_node_status.repositories_checked_in_percentage
end end
if ::Geo::ContainerRepositoryRegistry.replication_enabled? if ::Geo::ContainerRepositoryRegistry.replication_enabled? && current_node_status.container_repositories_count.to_i > 0
status.push current_node_status.container_repositories_synced_in_percentage status.push current_node_status.container_repositories_synced_in_percentage
end end
if Gitlab::CurrentSettings.repository_checks_enabled
status.push current_node_status.repositories_checked_in_percentage
end
end end
end end
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::Geo::GeoNodeStatusCheck do RSpec.describe Gitlab::Geo::GeoNodeStatusCheck do
let(:current_node) { create(:geo_node) } let_it_be(:current_node) { create(:geo_node) }
let(:geo_node_status) do let(:geo_node_status) do
build(:geo_node_status, :replicated_and_verified, geo_node: current_node) build(:geo_node_status, :replicated_and_verified, geo_node: current_node)
end end
...@@ -34,7 +35,7 @@ RSpec.describe Gitlab::Geo::GeoNodeStatusCheck do ...@@ -34,7 +35,7 @@ RSpec.describe Gitlab::Geo::GeoNodeStatusCheck do
end end
end end
context 'Replicators' do context 'replicators' do
let(:replicators) { Gitlab::Geo.enabled_replicator_classes } let(:replicators) { Gitlab::Geo.enabled_replicator_classes }
context 'replication' do context 'replication' do
...@@ -77,7 +78,23 @@ RSpec.describe Gitlab::Geo::GeoNodeStatusCheck do ...@@ -77,7 +78,23 @@ RSpec.describe Gitlab::Geo::GeoNodeStatusCheck do
end end
context 'when replication is up-to-date' do context 'when replication is up-to-date' do
it 'returns true' do before do
allow(Gitlab::CurrentSettings).to receive(:repository_checks_enabled).and_return(true)
end
it 'returns true when all replicables have data to sync' do
expect(subject.replication_verification_complete?).to be_truthy
end
it 'returns true when some replicables does not have data to sync' do
geo_node_status.update!(
container_repositories_count: 0,
lfs_objects_count: 0,
package_files_count: 0,
repositories_count: 0,
wikis_count: 0
)
expect(subject.replication_verification_complete?).to be_truthy expect(subject.replication_verification_complete?).to be_truthy
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