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
public_send("#{replicator_class.replicable_name_plural}_checksummed_in_percentage") # rubocop:disable GitlabSecurity/PublicSend
end
def count_for(replicator_class)
public_send("#{replicator_class.replicable_name_plural}_count") # rubocop:disable GitlabSecurity/PublicSend
end
def storage_shards_match?
return true if geo_node.primary?
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
end
def replication_verification_complete?
success_status = [
current_node_status.repositories_synced_in_percentage,
current_node_status.repositories_checksummed_in_percentage,
current_node_status.wikis_synced_in_percentage,
current_node_status.wikis_checksummed_in_percentage,
current_node_status.lfs_objects_synced_in_percentage,
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 }
checks_status =
legacy_replication_and_verification_checks_status +
replication_and_verification_checks_status +
conditional_replication_and_verification_checks_status
checks_status.compact.all? { |percentage| percentage == 100 }
end
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|
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)
if replicator_class.verification_enabled?
status.push current_node_status.checksummed_in_percentage_for(replicator_class)
end
end
end
end
if Gitlab::Geo.repository_verification_enabled?
status.push current_node_status.repositories_verified_in_percentage
status.push current_node_status.wikis_verified_in_percentage
def conditional_replication_and_verification_checks_status
[].tap do |status|
if Gitlab::CurrentSettings.repository_checks_enabled && current_node_status.repositories_count.to_i > 0
status.push current_node_status.repositories_checked_in_percentage
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
end
if Gitlab::CurrentSettings.repository_checks_enabled
status.push current_node_status.repositories_checked_in_percentage
end
end
end
......
......@@ -3,7 +3,8 @@
require 'spec_helper'
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
build(:geo_node_status, :replicated_and_verified, geo_node: current_node)
end
......@@ -34,7 +35,7 @@ RSpec.describe Gitlab::Geo::GeoNodeStatusCheck do
end
end
context 'Replicators' do
context 'replicators' do
let(:replicators) { Gitlab::Geo.enabled_replicator_classes }
context 'replication' do
......@@ -77,7 +78,23 @@ RSpec.describe Gitlab::Geo::GeoNodeStatusCheck do
end
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
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