Commit 4ea330e6 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '215461-geo-track-packagefile-sync-counts-in-geo-node-statuses' into 'master'

Geo: Track PackageFile sync counts in Geo node statuses

Closes #215461

See merge request gitlab-org/gitlab!33079
parents 95ae632d 5a53bd24
......@@ -366,7 +366,9 @@ Example response:
"revision": "33d33a096a",
"package_files_count": 10,
"package_files_checksummed_count": 10,
"package_files_checksum_failed_count": 0
"package_files_checksum_failed_count": 0,
"package_files_synced_count": 10,
"package_files_failed_count": 5
},
{
"geo_node_id": 2,
......@@ -437,7 +439,9 @@ Example response:
"revision": "33d33a096a",
"package_files_count": 10,
"package_files_checksummed_count": 10,
"package_files_checksum_failed_count": 0
"package_files_checksum_failed_count": 0,
"package_files_synced_count": 10,
"package_files_failed_count": 5
}
]
```
......
......@@ -74,6 +74,8 @@ class GeoNodeStatus < ApplicationRecord
package_files_count
package_files_checksummed_count
package_files_checksum_failed_count
package_files_synced_count
package_files_failed_count
).freeze
# Be sure to keep this consistent with Prometheus naming conventions
......@@ -148,7 +150,9 @@ class GeoNodeStatus < ApplicationRecord
design_repositories_registry_count: 'Number of design repositories in the registry',
package_files_count: 'Number of package files on primary',
package_files_checksummed_count: 'Number of package files checksummed on primary',
package_files_checksum_failed_count: 'Number of package files failed to checksum on primary'
package_files_checksum_failed_count: 'Number of package files failed to checksum on primary',
package_files_synced_count: 'Number of syncable package files synced on secondary',
package_files_failed_count: 'Number of syncable package files failed to sync on secondary'
}.freeze
EXPIRATION_IN_MINUTES = 10
......@@ -255,6 +259,7 @@ class GeoNodeStatus < ApplicationRecord
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
......@@ -333,6 +338,7 @@ class GeoNodeStatus < ApplicationRecord
attr_in_percentage :container_repositories_synced, :container_repositories_synced_count, :container_repositories_count
attr_in_percentage :design_repositories_synced, :design_repositories_synced_count, :design_repositories_count
attr_in_percentage :package_files_checksummed, :package_files_checksummed_count, :package_files_count
attr_in_percentage :package_files_synced, :package_files_synced_count, :package_files_count
def storage_shards_match?
return true if geo_node.primary?
......@@ -465,7 +471,6 @@ class GeoNodeStatus < ApplicationRecord
self.repositories_checksum_failed_count = repository_verification_finder.count_verification_failed_repositories
self.wikis_checksummed_count = repository_verification_finder.count_verified_wikis
self.wikis_checksum_failed_count = repository_verification_finder.count_verification_failed_wikis
self.package_files_count = Geo::PackageFileReplicator.primary_total_count
self.package_files_checksummed_count = Geo::PackageFileReplicator.checksummed_count
self.package_files_checksum_failed_count = Geo::PackageFileReplicator.checksum_failed_count
elsif Gitlab::Geo.secondary?
......@@ -477,6 +482,8 @@ class GeoNodeStatus < ApplicationRecord
self.wikis_checksum_mismatch_count = registries_for_mismatch_projects(:wiki).count
self.repositories_retrying_verification_count = registries_retrying_verification(:repository).count
self.wikis_retrying_verification_count = registries_retrying_verification(:wiki).count
self.package_files_synced_count = Geo::PackageFileReplicator.synced_count
self.package_files_failed_count = Geo::PackageFileReplicator.failed_count
end
end
......
......@@ -120,6 +120,14 @@ module Gitlab
model.count
end
def self.synced_count
registry_class.synced.count
end
def self.failed_count
registry_class.failed.count
end
# @example Given `Geo::PackageFileRegistryFinder`, this returns
# `::Geo::PackageFileReplicator`
# @example Given `Resolver::Geo::PackageFileRegistriesResolver`, this
......
......@@ -36,6 +36,8 @@ FactoryBot.define do
wikis_checksum_failed_count { 55 }
package_files_count { 585 }
package_files_checksummed_count { 585 }
package_files_failed_count { 3 }
package_files_synced_count { 585 }
package_files_checksum_failed_count { 585 }
repositories_verified_count { 501 }
repositories_verification_failed_count { 100 }
......
......@@ -129,6 +129,9 @@
"package_files_count": { "type": ["integer", "null"] },
"package_files_checksummed_count": { "type": ["integer", "null"] },
"package_files_checksum_failed_count": { "type": ["integer", "null"] },
"package_files_failed_count": { "type": ["integer", "null"] },
"package_files_synced_count": { "type": ["integer", "null"] },
"package_files_synced_in_percentage": { "type": "string" },
"package_files_checksummed_in_percentage": { "type": "string" },
"repositories_verified_count": { "type": ["integer", "null"] },
"repositories_verification_failed_count": { "type": ["integer", "null"] },
......
......@@ -1262,6 +1262,36 @@ RSpec.describe GeoNodeStatus, :geo, :geo_fdw do
end
end
describe 'package files secondary counters' do
context 'when package registries available' do
before do
create(:package_file_registry, :failed)
create(:package_file_registry, :failed)
create(:package_file_registry, :synced)
end
it 'returns the right number of failed and synced repos' do
expect(subject.package_files_failed_count).to eq(2)
expect(subject.package_files_synced_count).to eq(1)
end
it 'returns the percent of synced package files' do
expect(subject.package_files_synced_in_percentage).to be_within(0.01).of(33.33)
end
end
context 'when no package registries available' do
it 'returns 0' do
expect(subject.package_files_failed_count).to eq(0)
expect(subject.package_files_synced_count).to eq(0)
end
it 'returns 0' do
expect(subject.package_files_synced_in_percentage).to eq(0)
end
end
end
describe '#load_data_from_current_node' do
context 'on the primary' do
before do
......
......@@ -5,5 +5,7 @@ require 'spec_helper'
RSpec.describe Geo::PackageFileReplicator do
let(:model_record) { build(:package_file, :npm) }
it_behaves_like 'a blob replicator'
include_examples 'a blob replicator'
include_examples 'secondary counters', :package_file_registry
end
......@@ -19,3 +19,23 @@ RSpec.shared_examples 'a replicator' do
end
end
end
RSpec.shared_examples 'secondary counters' do |registry_factory_name|
before do
create(registry_factory_name, :synced)
create(registry_factory_name)
create(registry_factory_name, :failed)
end
describe '.synced_count' do
it 'returns the number of synced items on secondary' do
expect(described_class.synced_count).to eq(1)
end
end
describe '.failed_count' do
it 'returns the number of failed items on secondary' do
expect(described_class.failed_count).to eq(1)
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