Use tracking database as SSOT to count replicables

On a Geo secondary node the total replicables
is equal to registry table count.
parent a3a201e2
......@@ -296,9 +296,6 @@ class GeoNodeStatus < ApplicationRecord
self.version = Gitlab::VERSION
self.revision = Gitlab.revision
self.projects_count = geo_node.projects.count
self.package_files_count = Geo::PackageFileReplicator.primary_total_count
load_status_message
load_event_data
load_primary_data
......@@ -424,10 +421,8 @@ class GeoNodeStatus < ApplicationRecord
def load_primary_data
return unless Gitlab::Geo.primary?
self.lfs_objects_count = LfsObject.count
self.job_artifacts_count = Ci::JobArtifact.not_expired.count
self.attachments_count = Upload.count
self.projects_count = geo_node.projects.count
self.package_files_count = Geo::PackageFileReplicator.primary_total_count
self.replication_slots_count = geo_node.replication_slots_count
self.replication_slots_used_count = geo_node.replication_slots_used_count
self.replication_slots_max_retained_wal_bytes = geo_node.replication_slots_max_retained_wal_bytes
......@@ -450,6 +445,7 @@ class GeoNodeStatus < ApplicationRecord
end
def load_repositories_data
self.projects_count = Geo::ProjectRegistry.count
self.repositories_synced_count = Geo::ProjectRegistry.synced(:repository).count
self.repositories_failed_count = Geo::ProjectRegistry.sync_failed(:repository).count
self.wikis_synced_count = Geo::ProjectRegistry.synced(:wiki).count
......@@ -462,7 +458,7 @@ class GeoNodeStatus < ApplicationRecord
self.lfs_objects_count = lfs_objects_finder.registry_count
self.lfs_objects_synced_count = lfs_objects_finder.synced_count
self.lfs_objects_failed_count = lfs_objects_finder.failed_count
self.lfs_objects_registry_count = lfs_objects_finder.count_registry
self.lfs_objects_registry_count = lfs_objects_finder.registry_count
self.lfs_objects_synced_missing_on_primary_count = lfs_objects_finder.count_synced_missing_on_primary
end
......@@ -472,7 +468,7 @@ class GeoNodeStatus < ApplicationRecord
self.job_artifacts_count = job_artifacts_finder.registry_count
self.job_artifacts_synced_count = job_artifacts_finder.synced_count
self.job_artifacts_failed_count = job_artifacts_finder.failed_count
self.job_artifacts_registry_count = job_artifacts_finder.count_registry
self.job_artifacts_registry_count = job_artifacts_finder.registry_count
self.job_artifacts_synced_missing_on_primary_count = job_artifacts_finder.count_synced_missing_on_primary
end
......@@ -482,7 +478,7 @@ class GeoNodeStatus < ApplicationRecord
self.attachments_count = attachments_finder.registry_count
self.attachments_synced_count = attachments_finder.synced_count
self.attachments_failed_count = attachments_finder.failed_count
self.attachments_registry_count = attachments_finder.count_registry
self.attachments_registry_count = attachments_finder.registry_count
self.attachments_synced_missing_on_primary_count = attachments_finder.count_synced_missing_on_primary
end
......@@ -492,7 +488,7 @@ class GeoNodeStatus < ApplicationRecord
self.container_repositories_count = container_registry_finder.registry_count
self.container_repositories_synced_count = container_registry_finder.synced_count
self.container_repositories_failed_count = container_registry_finder.failed_count
self.container_repositories_registry_count = container_registry_finder.count_registry
self.container_repositories_registry_count = container_registry_finder.registry_count
end
def load_designs_data
......@@ -501,12 +497,13 @@ class GeoNodeStatus < ApplicationRecord
self.design_repositories_count = design_registry_finder.registry_count
self.design_repositories_synced_count = design_registry_finder.synced_count
self.design_repositories_failed_count = design_registry_finder.failed_count
self.design_repositories_registry_count = design_registry_finder.count_registry
self.design_repositories_registry_count = design_registry_finder.registry_count
end
def load_package_files_data
# return unless package_files_replication_enabled # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/221069
self.package_files_count = Geo::PackageFileReplicator.registry_count
self.package_files_registry_count = Geo::PackageFileReplicator.registry_count
self.package_files_synced_count = Geo::PackageFileReplicator.synced_count
self.package_files_failed_count = Geo::PackageFileReplicator.failed_count
......
......@@ -25,8 +25,11 @@ RSpec.describe Geo::ContainerRepositoryRegistryFinder, :geo do
end
describe '#registry_count' do
it 'returns number of container repositories' do
expect(subject.registry_count).to eq(6)
it 'returns number of container registries' do
create(:container_repository_registry, :synced, container_repository_id: container_repository_1.id)
create(:container_repository_registry, :sync_failed, container_repository_id: container_repository_3.id)
expect(subject.registry_count).to eq(2)
end
end
......@@ -49,7 +52,7 @@ RSpec.describe Geo::ContainerRepositoryRegistryFinder, :geo do
end
describe '#count_registry' do
it 'returns number of all registries' do
it 'returns number of container registries' do
create(:container_repository_registry, :synced, container_repository_id: container_repository_1.id)
create(:container_repository_registry, :sync_failed, container_repository_id: container_repository_3.id)
......
......@@ -22,14 +22,20 @@ RSpec.describe Geo::DesignRegistryFinder, :geo do
end
describe '#registry_count' do
it 'returns number of designs' do
# Two designs for the same project to assert absence of duplicates
create_list(:design, 2, project: project_1)
create(:design, project: project_2)
it 'returns number of desgin registries' do
create(:geo_design_registry, :synced, project_id: project_1.id)
create(:geo_design_registry, :sync_failed, project_id: project_2.id)
result = subject.registry_count
expect(subject.registry_count).to eq(2)
end
end
describe '#count_registry' do
it 'returns number of desgin registries' do
create(:geo_design_registry, :synced, project_id: project_1.id)
create(:geo_design_registry, :sync_failed, project_id: project_2.id)
expect(result).to eq(2)
expect(subject.count_registry).to eq(2)
end
end
......@@ -51,15 +57,6 @@ RSpec.describe Geo::DesignRegistryFinder, :geo do
end
end
describe '#count_registry' do
it 'returns number of all registries' do
create(:geo_design_registry, :synced, project_id: project_1.id)
create(:geo_design_registry, :sync_failed, project_id: project_2.id)
expect(subject.count_registry).to eq(2)
end
end
describe '#find_registry_differences' do
before_all do
create(:design, project: project_1)
......
......@@ -117,9 +117,20 @@ RSpec.describe GeoNodeStatus, :geo do
end
describe '#projects_count' do
it 'counts the number of projects' do
it 'counts the number of projects on a primary node' do
stub_current_geo_node(primary)
expect(subject.projects_count).to eq 4
end
it 'counts the number of projects on a secondary node' do
stub_current_geo_node(secondary)
create(:geo_project_registry, :synced, project: project_1)
create(:geo_project_registry, project: project_3)
expect(subject.projects_count).to eq 2
end
end
describe '#attachments_synced_count' do
......@@ -374,18 +385,14 @@ RSpec.describe GeoNodeStatus, :geo do
expect(subject.repositories_synced_in_percentage).to eq(0)
end
it 'returns the right percentage with no group restrictions' do
it 'returns the right percentage' do
create(:geo_project_registry, :synced, project: project_1)
create(:geo_project_registry, project: project_2)
create(:geo_project_registry, project: project_3)
create(:geo_project_registry, project: project_4)
expect(subject.repositories_synced_in_percentage).to be_within(0.0001).of(25)
end
it 'returns the right percentage with group restrictions' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [group])
create(:geo_project_registry, :synced, project: project_1)
expect(subject.repositories_synced_in_percentage).to be_within(0.0001).of(50)
end
end
describe '#wikis_synced_in_percentage' do
......@@ -399,18 +406,14 @@ RSpec.describe GeoNodeStatus, :geo do
expect(subject.wikis_synced_in_percentage).to eq(0)
end
it 'returns the right percentage with no group restrictions' do
it 'returns the right percentage' do
create(:geo_project_registry, :synced, project: project_1)
create(:geo_project_registry, project: project_2)
create(:geo_project_registry, project: project_3)
create(:geo_project_registry, project: project_4)
expect(subject.wikis_synced_in_percentage).to be_within(0.0001).of(25)
end
it 'returns the right percentage with group restrictions' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [group])
create(:geo_project_registry, :synced, project: project_1)
expect(subject.wikis_synced_in_percentage).to be_within(0.0001).of(50)
end
end
describe '#replication_slots_used_count' do
......@@ -583,16 +586,18 @@ RSpec.describe GeoNodeStatus, :geo do
end
describe '#container_repositories_count' do
let!(:container_1) { create(:container_repository) }
let!(:container_2) { create(:container_repository) }
let!(:container_1) { create(:container_repository_registry, :synced) }
let!(:container_2) { create(:container_repository_registry, :sync_failed) }
let!(:container_3) { create(:container_repository_registry, :sync_failed) }
let!(:container_4) { create(:container_repository) }
context 'when container repositories replication is active' do
before do
stub_geo_setting(registry_replication: { enabled: true })
end
it 'counts all the repositories' do
expect(subject.container_repositories_count).to eq(2)
it 'counts number of registries for repositories' do
expect(subject.container_repositories_count).to eq(3)
end
end
......@@ -687,10 +692,6 @@ RSpec.describe GeoNodeStatus, :geo do
end
describe '#container_repositories_synced_in_percentage' do
let!(:container_repository_1) { create(:container_repository, project: project_1) }
let!(:container_repository_2) { create(:container_repository, project: project_1) }
let!(:container_list) { create_list(:container_repository, 2, project: project_3) }
context 'when container repositories replication is active' do
before do
stub_geo_setting(registry_replication: { enabled: true })
......@@ -700,34 +701,32 @@ RSpec.describe GeoNodeStatus, :geo do
expect(subject.container_repositories_synced_in_percentage).to eq(0)
end
it 'returns the right percentage with no group restrictions' do
create(:container_repository_registry, :synced, container_repository: container_repository_1)
it 'returns the right percentage' do
create(:container_repository_registry, :synced)
create(:container_repository_registry)
create(:container_repository_registry)
create(:container_repository_registry)
expect(subject.container_repositories_synced_in_percentage).to be_within(0.0001).of(25)
end
it 'returns the right percentage with group restrictions' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [group])
create(:container_repository_registry, :synced, container_repository: container_repository_1)
expect(subject.container_repositories_synced_in_percentage).to be_within(0.0001).of(50)
end
end
it 'when container repositories replication is inactive returns 0' do
stub_geo_setting(registry_replication: { enabled: false })
create(:container_repository_registry, :synced, container_repository: container_repository_1)
create(:container_repository_registry, :synced)
expect(subject.container_repositories_synced_in_percentage).to eq(0)
end
end
describe '#design_repositories_count' do
it 'counts all the designs' do
create(:design)
create(:design)
it 'counts number of registries for repositories' do
create(:geo_design_registry, :sync_failed)
create(:geo_design_registry)
create(:geo_design_registry, :synced)
expect(subject.design_repositories_count).to eq(2)
expect(subject.design_repositories_registry_count).to eq(3)
end
end
......@@ -764,23 +763,12 @@ RSpec.describe GeoNodeStatus, :geo do
expect(subject.design_repositories_synced_in_percentage).to eq(0)
end
it 'returns the right percentage with no group restrictions' do
it 'returns the right percentage' do
create(:geo_design_registry, :synced)
create(:geo_design_registry, :sync_failed)
expect(subject.design_repositories_synced_in_percentage).to be_within(0.0001).of(50)
end
it 'returns the right percentage with group restrictions' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [group])
create(:geo_design_registry, :synced, project: project_1)
create(:geo_design_registry, :sync_failed, project: project_2)
create(:geo_design_registry, :sync_failed, project: project_3)
create(:geo_design_registry, :sync_failed, project: project_4)
expect(subject.design_repositories_synced_in_percentage).to be_within(0.0001).of(50)
end
end
describe '#repositories_verified_count' do
......@@ -1006,7 +994,9 @@ RSpec.describe GeoNodeStatus, :geo do
describe '#[]' do
it 'returns values for each attribute' do
expect(subject[:projects_count]).to eq(4)
create(:geo_project_registry, project: project_1)
expect(subject[:projects_count]).to eq(1)
expect(subject[:repositories_synced_count]).to eq(0)
end
......@@ -1264,19 +1254,19 @@ RSpec.describe GeoNodeStatus, :geo do
context 'on the secondary' do
it 'calls LfsObjectRegistryFinder#registry_count' do
expect_any_instance_of(Geo::LfsObjectRegistryFinder).to receive(:registry_count)
expect_any_instance_of(Geo::LfsObjectRegistryFinder).to receive(:registry_count).twice
subject
end
it 'calls AttachmentRegistryFinder#registry_count' do
expect_any_instance_of(Geo::AttachmentRegistryFinder).to receive(:registry_count)
expect_any_instance_of(Geo::AttachmentRegistryFinder).to receive(:registry_count).twice
subject
end
it 'calls JobArtifactRegistryFinder#registry_count' do
expect_any_instance_of(Geo::JobArtifactRegistryFinder).to receive(:registry_count)
expect_any_instance_of(Geo::JobArtifactRegistryFinder).to receive(:registry_count).twice
subject
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