Commit 25964a33 authored by Alex Ives's avatar Alex Ives Committed by Douglas Barbosa Alexandre

Report data from secondary_usage_data in geo_node_status

Relates to https://gitlab.com/gitlab-org/gitlab/issues/298781
parent c152931c
...@@ -55,6 +55,10 @@ class GeoNodeStatus < ApplicationRecord ...@@ -55,6 +55,10 @@ class GeoNodeStatus < ApplicationRecord
end.flatten.map(&:to_s) end.flatten.map(&:to_s)
end end
def self.usage_data_fields
Geo::SecondaryUsageData::PAYLOAD_COUNT_FIELDS
end
RESOURCE_STATUS_FIELDS = (%w( RESOURCE_STATUS_FIELDS = (%w(
repository_verification_enabled repository_verification_enabled
repositories_replication_enabled repositories_replication_enabled
...@@ -103,7 +107,7 @@ class GeoNodeStatus < ApplicationRecord ...@@ -103,7 +107,7 @@ class GeoNodeStatus < ApplicationRecord
design_repositories_count design_repositories_count
design_repositories_synced_count design_repositories_synced_count
design_repositories_failed_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 # Why are disabled classes included? See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/38959#note_402656534
def self.replicator_class_prometheus_metrics def self.replicator_class_prometheus_metrics
...@@ -276,7 +280,7 @@ class GeoNodeStatus < ApplicationRecord ...@@ -276,7 +280,7 @@ class GeoNodeStatus < ApplicationRecord
return if val.nil? return if val.nil?
case attr_name 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' when /_enabled\z/ then val.to_s == 'true'
else raise "Unhandled status attribute name format \"#{attr_name}\"" else raise "Unhandled status attribute name format \"#{attr_name}\""
end end
...@@ -480,6 +484,7 @@ class GeoNodeStatus < ApplicationRecord ...@@ -480,6 +484,7 @@ class GeoNodeStatus < ApplicationRecord
load_container_registry_data load_container_registry_data
load_designs_data load_designs_data
load_ssf_replicable_data load_ssf_replicable_data
load_secondary_usage_data
end end
def load_repositories_data def load_repositories_data
...@@ -547,6 +552,15 @@ class GeoNodeStatus < ApplicationRecord ...@@ -547,6 +552,15 @@ class GeoNodeStatus < ApplicationRecord
end end
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 def load_repository_check_data
if Gitlab::Geo.primary? if Gitlab::Geo.primary?
self.repositories_checked_count = Project.where.not(last_repository_check_at: nil).count self.repositories_checked_count = Project.where.not(last_repository_check_at: nil).count
......
...@@ -68,6 +68,10 @@ FactoryBot.define do ...@@ -68,6 +68,10 @@ FactoryBot.define do
GeoNodeStatus.replicator_class_status_fields.each do |field| GeoNodeStatus.replicator_class_status_fields.each do |field|
send(field) { rand(10000) } send(field) { rand(10000) }
end end
Geo::SecondaryUsageData::PAYLOAD_COUNT_FIELDS.each do |field|
send(field) { rand(10000) }
end
end end
trait :replicated_and_verified do trait :replicated_and_verified do
......
...@@ -127,6 +127,7 @@ ...@@ -127,6 +127,7 @@
"replication_slots_used_count", "replication_slots_used_count",
"replication_slots_used_in_percentage", "replication_slots_used_in_percentage",
"replication_slots_max_retained_wal_bytes", "replication_slots_max_retained_wal_bytes",
"git_fetch_event_count_weekly",
"last_event_id", "last_event_id",
"last_event_timestamp", "last_event_timestamp",
"cursor_last_event_id", "cursor_last_event_id",
...@@ -272,6 +273,7 @@ ...@@ -272,6 +273,7 @@
"replication_slots_used_count": { "type": ["integer", "null"] }, "replication_slots_used_count": { "type": ["integer", "null"] },
"replication_slots_used_in_percentage": { "type": "string" }, "replication_slots_used_in_percentage": { "type": "string" },
"replication_slots_max_retained_wal_bytes": { "type": ["integer", "null"] }, "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_id": { "type": ["integer", "null"] },
"last_event_timestamp": { "type": ["integer", "null"] }, "last_event_timestamp": { "type": ["integer", "null"] },
"cursor_last_event_id": { "type": ["integer", "null"] }, "cursor_last_event_id": { "type": ["integer", "null"] },
......
...@@ -1156,6 +1156,28 @@ RSpec.describe GeoNodeStatus, :geo do ...@@ -1156,6 +1156,28 @@ RSpec.describe GeoNodeStatus, :geo do
end end
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 context 'Replicator stats' do
where(:replicator, :model_factory, :registry_factory) do where(:replicator, :model_factory, :registry_factory) do
Geo::MergeRequestDiffReplicator | :external_merge_request_diff | :geo_merge_request_diff_registry 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