Commit 9c4e1472 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '323220/secondary_usage_data_background_worker' into 'master'

Add usage data collection to geo secondaries [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!55701
parents 5e29c446 3c427ad6
...@@ -586,6 +586,9 @@ Gitlab.ee do ...@@ -586,6 +586,9 @@ Gitlab.ee do
Settings.cron_jobs['geo_verification_cron_worker'] ||= Settingslogic.new({}) Settings.cron_jobs['geo_verification_cron_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['geo_verification_cron_worker']['cron'] ||= '* * * * *' Settings.cron_jobs['geo_verification_cron_worker']['cron'] ||= '* * * * *'
Settings.cron_jobs['geo_verification_cron_worker']['job_class'] ||= 'Geo::VerificationCronWorker' 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'] ||= Settingslogic.new({})
Settings.cron_jobs['geo_file_download_dispatch_worker']['cron'] ||= '*/1 * * * *' Settings.cron_jobs['geo_file_download_dispatch_worker']['cron'] ||= '*/1 * * * *'
Settings.cron_jobs['geo_file_download_dispatch_worker']['job_class'] ||= 'Geo::FileDownloadDispatchWorker' Settings.cron_jobs['geo_file_download_dispatch_worker']['job_class'] ||= 'Geo::FileDownloadDispatchWorker'
......
...@@ -23,4 +23,8 @@ class Geo::SecondaryUsageData < Geo::TrackingBase ...@@ -23,4 +23,8 @@ class Geo::SecondaryUsageData < Geo::TrackingBase
end end
end end
end end
def self.update_metrics!
# This should go through and collect metrics
end
end end
...@@ -195,6 +195,14 @@ ...@@ -195,6 +195,14 @@
:weight: 1 :weight: 1
:idempotent: true :idempotent: true
:tags: [] :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 - :name: cronjob:geo_sidekiq_cron_config
:feature_category: :geo_replication :feature_category: :geo_replication
:has_external_dependencies: :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 ...@@ -21,6 +21,7 @@ module Gitlab
geo_container_repository_sync_worker geo_container_repository_sync_worker
geo_repository_verification_secondary_scheduler_worker geo_repository_verification_secondary_scheduler_worker
geo_secondary_registry_consistency_worker geo_secondary_registry_consistency_worker
geo_secondary_usage_data_cron_worker
].freeze ].freeze
GEO_JOBS = (COMMON_JOBS + PRIMARY_JOBS + SECONDARY_JOBS).freeze GEO_JOBS = (COMMON_JOBS + PRIMARY_JOBS + SECONDARY_JOBS).freeze
......
...@@ -17,6 +17,7 @@ RSpec.describe Gitlab::Geo::CronManager, :geo do ...@@ -17,6 +17,7 @@ RSpec.describe Gitlab::Geo::CronManager, :geo do
geo_metrics_update_worker geo_metrics_update_worker
geo_prune_event_log_worker geo_prune_event_log_worker
geo_verification_cron_worker geo_verification_cron_worker
geo_secondary_usage_data_cron_worker
].freeze ].freeze
def job(name) def job(name)
...@@ -39,7 +40,8 @@ RSpec.describe Gitlab::Geo::CronManager, :geo do ...@@ -39,7 +40,8 @@ RSpec.describe Gitlab::Geo::CronManager, :geo do
job('geo_registry_sync_worker'), job('geo_registry_sync_worker'),
job('geo_repository_sync_worker'), job('geo_repository_sync_worker'),
job('geo_container_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 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