Commit 6f63f149 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '298781/add_secondary_usage_data_to_geo_node_status' into 'master'

Report data from secondary_usage_data in geo_node_status

See merge request gitlab-org/gitlab!56147
parents 70c3aec5 25964a33
......@@ -55,6 +55,10 @@ class GeoNodeStatus < ApplicationRecord
end.flatten.map(&:to_s)
end
def self.usage_data_fields
Geo::SecondaryUsageData::PAYLOAD_COUNT_FIELDS
end
RESOURCE_STATUS_FIELDS = (%w(
repository_verification_enabled
repositories_replication_enabled
......@@ -103,7 +107,7 @@ class GeoNodeStatus < ApplicationRecord
design_repositories_count
design_repositories_synced_count
design_repositories_failed_count
) + replicator_class_status_fields).freeze
) + replicator_class_status_fields + usage_data_fields).freeze
# Why are disabled classes included? See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/38959#note_402656534
def self.replicator_class_prometheus_metrics
......@@ -276,7 +280,7 @@ class GeoNodeStatus < ApplicationRecord
return if val.nil?
case attr_name
when /_count\z/ then val.to_i
when /_count(?:_weekly)?\z/ then val.to_i
when /_enabled\z/ then val.to_s == 'true'
else raise "Unhandled status attribute name format \"#{attr_name}\""
end
......@@ -480,6 +484,7 @@ class GeoNodeStatus < ApplicationRecord
load_container_registry_data
load_designs_data
load_ssf_replicable_data
load_secondary_usage_data
end
def load_repositories_data
......@@ -547,6 +552,15 @@ class GeoNodeStatus < ApplicationRecord
end
end
def load_secondary_usage_data
usage_data = Geo::SecondaryUsageData.last
return unless usage_data
self.class.usage_data_fields.each do |field|
status[field] = usage_data.payload[field]
end
end
def load_repository_check_data
if Gitlab::Geo.primary?
self.repositories_checked_count = Project.where.not(last_repository_check_at: nil).count
......
......@@ -68,6 +68,10 @@ FactoryBot.define do
GeoNodeStatus.replicator_class_status_fields.each do |field|
send(field) { rand(10000) }
end
Geo::SecondaryUsageData::PAYLOAD_COUNT_FIELDS.each do |field|
send(field) { rand(10000) }
end
end
trait :replicated_and_verified do
......
......@@ -127,6 +127,7 @@
"replication_slots_used_count",
"replication_slots_used_in_percentage",
"replication_slots_max_retained_wal_bytes",
"git_fetch_event_count_weekly",
"last_event_id",
"last_event_timestamp",
"cursor_last_event_id",
......@@ -272,6 +273,7 @@
"replication_slots_used_count": { "type": ["integer", "null"] },
"replication_slots_used_in_percentage": { "type": "string" },
"replication_slots_max_retained_wal_bytes": { "type": ["integer", "null"] },
"git_fetch_event_count_weekly": { "type": ["integer", "null"] },
"last_event_id": { "type": ["integer", "null"] },
"last_event_timestamp": { "type": ["integer", "null"] },
"cursor_last_event_id": { "type": ["integer", "null"] },
......
......@@ -1156,6 +1156,28 @@ RSpec.describe GeoNodeStatus, :geo do
end
end
context 'secondary usage data' do
shared_examples_for 'a field from secondary_usage_data' do |field|
describe '#load_secondary_usage_data' do
it 'loads the latest data from Geo::SecondaryUsageData' do
data = create(:geo_secondary_usage_data)
expect(described_class.current_node_status.status[field]).to eq(data.payload[field])
end
it 'reports nil if there is no collected data in Geo::SecondaryUsageData' do
expect(status.status[field]).to be_nil
end
end
end
described_class.usage_data_fields.each do |field|
context "##{field}" do
it_behaves_like 'a field from secondary_usage_data', field
end
end
end
context 'Replicator stats' do
where(:replicator, :model_factory, :registry_factory) do
Geo::MergeRequestDiffReplicator | :external_merge_request_diff | :geo_merge_request_diff_registry
......
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