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

Add geo node status metrics to usage ping

- Add all node status metrics to usage ping under key
  geo_node_usage as an array
- Add scope that returns active geo secondaries
- Add :secondary trait to geo_node factory

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/273133
parent 95d9395d
......@@ -31,6 +31,8 @@ class GeoNodeStatus < ApplicationRecord
alias_attribute :last_event_timestamp, :last_event_date_timestamp
alias_attribute :cursor_last_event_timestamp, :cursor_last_event_date_timestamp
scope :for_active_secondaries, -> { joins(:geo_node).merge(GeoNode.secondary_nodes.where(enabled: true)) }
def self.status_fields_for(replicable_class)
{
"#{replicable_class.replicable_name_plural}_count".to_sym => "Number of #{replicable_class.replicable_title_plural} on the primary",
......
---
title: Add Geo node status metrics to usage ping
merge_request: 53665
author:
type: added
......@@ -289,7 +289,25 @@ module EE
application_id: GeoNode.secondary_nodes.select(:oauth_application_id)
),
:resource_owner_id
)
),
# rubocop: disable UsageData/LargeTable
# These fields are pre-calculated on the secondary for transmission and storage on the primary.
# This will end up as an array of hashes with the data from GeoNodeStatus, see
# https://docs.gitlab.com/ee/api/geo_nodes.html#retrieve-status-about-a-specific-geo-node for what
# that inner hash may contain
# For Example:
# geo_node_usage: [
# {
# repositories_count: 10,
# repositories_synced_count: 5,
# repositories_failed_count: 0,
# ... other geo node status fields
# }
# ]
geo_node_usage: GeoNodeStatus.for_active_secondaries.map do |node|
GeoNodeStatus::RESOURCE_STATUS_FIELDS.map { |field| [field, node[field]] }.to_h
end
# rubocop: enable UsageData/LargeTable
})
end
......
......@@ -19,6 +19,10 @@ FactoryBot.define do
sync_object_storage { false }
end
trait :secondary do
primary { false }
end
trait :local_storage_only do
sync_object_storage { false }
end
......
......@@ -379,14 +379,39 @@ RSpec.describe Gitlab::UsageData do
expect(described_class.usage_activity_by_stage_enablement({})).to eq({})
end
it 'excludes data outside of the date range' do
create_list(:geo_node, 2).each do |node|
for_defined_days_back do
create(:oauth_access_grant, application: node.oauth_application)
context 'geo enabled' do
before do
create_list(:geo_node, 2, :secondary).each do |node|
for_defined_days_back do
create(:oauth_access_grant, application: node.oauth_application)
end
end
create(:geo_node, :secondary, enabled: false)
create(:geo_node, :primary)
GeoNode.all.each do |node|
create(:geo_node_status, geo_node: node)
end
end
subject do
described_class.usage_activity_by_stage_enablement(described_class.last_28_days_time_period)
end
expect(described_class.usage_activity_by_stage_enablement(described_class.last_28_days_time_period)).to eq(geo_secondary_web_oauth_users: 2)
it 'excludes data outside of the date range' do
expect(subject).to include(geo_secondary_web_oauth_users: 2)
end
context 'node status fields' do
it 'only includes active secondary nodes' do
expect(subject[:geo_node_usage].size).to eq(2)
end
it 'includes all resource status fields' do
expect(subject[:geo_node_usage].first.keys).to eq(GeoNodeStatus::RESOURCE_STATUS_FIELDS)
end
end
end
end
......
......@@ -7,7 +7,7 @@ RSpec.describe GeoNodeStatus, :geo do
using RSpec::Parameterized::TableSyntax
let!(:primary) { create(:geo_node, :primary) }
let!(:secondary) { create(:geo_node) }
let!(:secondary) { create(:geo_node, :secondary) }
let_it_be(:group) { create(:group) }
let_it_be(:project_1) { create(:project, group: group) }
......@@ -46,6 +46,16 @@ RSpec.describe GeoNodeStatus, :geo do
end
end
describe '#for_active_secondaries' do
it 'excludes primaries and disabled nodes' do
create(:geo_node_status, geo_node: primary)
create(:geo_node_status, geo_node: create(:geo_node, :secondary, enabled: false))
enabled_secondary_status = create(:geo_node_status, geo_node: create(:geo_node, :secondary, enabled: true))
expect(described_class.for_active_secondaries).to match_array([enabled_secondary_status])
end
end
describe '#healthy?' do
context 'when health is blank' do
it 'returns true' do
......
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