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

Add usage data collection to geo secondaries

- Add a cron worker to collect and update the secondary usage data table
- Add a placeholder that does the data collection
- Add a new cron to cron_manager and settings, running weekly on Sunday.

Relates to https://gitlab.com/gitlab-org/gitlab/issues/323220
parent c828bbf7
......@@ -586,6 +586,9 @@ Gitlab.ee do
Settings.cron_jobs['geo_verification_cron_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['geo_verification_cron_worker']['cron'] ||= '* * * * *'
Settings.cron_jobs['geo_verification_cron_worker']['job_class'] ||= 'Geo::VerificationCronWorker'
Settings.cron_jobs['geo_secondary_usage_data_cron_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['geo_secondary_usage_data_cron_worker']['cron'] ||= '0 0 * * 0'
Settings.cron_jobs['geo_secondary_usage_data_cron_worker']['job_class'] ||= 'Geo::SecondaryUsageDataCronWorker'
Settings.cron_jobs['geo_file_download_dispatch_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['geo_file_download_dispatch_worker']['cron'] ||= '*/1 * * * *'
Settings.cron_jobs['geo_file_download_dispatch_worker']['job_class'] ||= 'Geo::FileDownloadDispatchWorker'
......
......@@ -23,4 +23,8 @@ class Geo::SecondaryUsageData < Geo::TrackingBase
end
end
end
def self.update_metrics!
# This should go through and collect metrics
end
end
......@@ -195,6 +195,14 @@
:weight: 1
:idempotent: true
:tags: []
- :name: cronjob:geo_secondary_usage_data_cron
:feature_category: :geo_replication
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent:
:tags: []
- :name: cronjob:geo_sidekiq_cron_config
:feature_category: :geo_replication
:has_external_dependencies:
......
# frozen_string_literal: true
module Geo
class SecondaryUsageDataCronWorker # rubocop:disable Scalability/IdempotentWorker
LEASE_TIMEOUT = 24.hours.freeze
include ApplicationWorker
include CronjobQueue # rubocop:disable Scalability/CronWorkerContext
include ::Gitlab::Geo::LogHelpers
include ExclusiveLeaseGuard
feature_category :geo_replication
def perform
return unless Gitlab::Geo.secondary?
return unless Feature.enabled?(:geo_secondary_usage_data_collection)
try_obtain_lease do
SecondaryUsageData.update_metrics!
end
end
private
def lease_timeout
LEASE_TIMEOUT
end
def lease_release?
false
end
end
end
---
name: geo_secondary_usage_data_collection
introduced_by_url:
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/322628
milestone: '13.10'
type: development
group: group::geo
default_enabled: false
......@@ -21,6 +21,7 @@ module Gitlab
geo_container_repository_sync_worker
geo_repository_verification_secondary_scheduler_worker
geo_secondary_registry_consistency_worker
geo_secondary_usage_data_cron_worker
].freeze
GEO_JOBS = (COMMON_JOBS + PRIMARY_JOBS + SECONDARY_JOBS).freeze
......
......@@ -17,6 +17,7 @@ RSpec.describe Gitlab::Geo::CronManager, :geo do
geo_metrics_update_worker
geo_prune_event_log_worker
geo_verification_cron_worker
geo_secondary_usage_data_cron_worker
].freeze
def job(name)
......@@ -39,7 +40,8 @@ RSpec.describe Gitlab::Geo::CronManager, :geo do
job('geo_registry_sync_worker'),
job('geo_repository_sync_worker'),
job('geo_container_repository_sync_worker'),
job('geo_repository_verification_secondary_scheduler_worker')
job('geo_repository_verification_secondary_scheduler_worker'),
job('geo_secondary_usage_data_cron_worker')
]
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Geo::SecondaryUsageDataCronWorker, :clean_gitlab_redis_shared_state do
include ::EE::GeoHelpers
before do
allow(subject).to receive(:try_obtain_lease).and_yield
allow(Geo::SecondaryUsageData).to receive(:update_metrics!)
stub_secondary_node
end
it 'uses a cronjob queue' do
expect(subject.sidekiq_options_hash).to include(
'queue' => 'cronjob:geo_secondary_usage_data_cron',
'queue_namespace' => :cronjob
)
end
it 'does not run for primary nodes' do
allow(Gitlab::Geo).to receive(:secondary?).and_return(false)
expect(Geo::SecondaryUsageData).not_to receive(:update_metrics!)
subject.perform
end
it 'calls SecondaryUsageData update metrics when it obtains the lease' do
expect(subject).to receive(:try_obtain_lease).and_yield
expect(Geo::SecondaryUsageData).to receive(:update_metrics!)
subject.perform
end
it "does not update metrics if it doesn't obtain the lease" do
expect(subject).to receive(:try_obtain_lease).and_return(false)
expect(Geo::SecondaryUsageData).not_to receive(:update_metrics!)
subject.perform
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