Merge branch 'bjk/usage_ping' into 'master'
Update usage ping cron behavior See merge request gitlab-org/gitlab-ce!30842
This commit is contained in:
commit
0067ea312c
3 changed files with 20 additions and 5 deletions
|
@ -6,10 +6,16 @@ class GitlabUsagePingWorker
|
||||||
include ApplicationWorker
|
include ApplicationWorker
|
||||||
include CronjobQueue
|
include CronjobQueue
|
||||||
|
|
||||||
|
# Retry for up to approximately three hours then give up.
|
||||||
|
sidekiq_options retry: 10, dead: false
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
# Multiple Sidekiq workers could run this. We should only do this at most once a day.
|
# Multiple Sidekiq workers could run this. We should only do this at most once a day.
|
||||||
return unless try_obtain_lease
|
return unless try_obtain_lease
|
||||||
|
|
||||||
|
# Splay the request over a minute to avoid thundering herd problems.
|
||||||
|
sleep(rand(0.0..60.0).round(3))
|
||||||
|
|
||||||
SubmitUsagePingService.new.execute
|
SubmitUsagePingService.new.execute
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
5
changelogs/unreleased/bjk-usage_ping.yml
Normal file
5
changelogs/unreleased/bjk-usage_ping.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Update usage ping cron behavior
|
||||||
|
merge_request: 30842
|
||||||
|
author:
|
||||||
|
type: performance
|
|
@ -1,4 +1,5 @@
|
||||||
require 'settingslogic'
|
require 'settingslogic'
|
||||||
|
require 'digest/md5'
|
||||||
|
|
||||||
# We can not use `Rails.root` here, as this file might be loaded without the
|
# We can not use `Rails.root` here, as this file might be loaded without the
|
||||||
# full Rails environment being loaded. We can not use `require_relative` either,
|
# full Rails environment being loaded. We can not use `require_relative` either,
|
||||||
|
@ -170,14 +171,17 @@ class Settings < Settingslogic
|
||||||
URI.parse(url_without_path).host
|
URI.parse(url_without_path).host
|
||||||
end
|
end
|
||||||
|
|
||||||
# Runs every minute in a random ten-minute period on Sundays, to balance the
|
# Runs at a random time of day on a consistent day of the week based on
|
||||||
# load on the server receiving these pings. The usage ping is safe to run
|
# the instance UUID. This is to balance the load on the service receiving
|
||||||
# multiple times because of a 24 hour exclusive lock.
|
# these pings. The sidekiq job handles temporary http failures.
|
||||||
def cron_for_usage_ping
|
def cron_for_usage_ping
|
||||||
hour = rand(24)
|
hour = rand(24)
|
||||||
minute = rand(6)
|
minute = rand(60)
|
||||||
|
# Set a default UUID for the case when the UUID hasn't been initialized.
|
||||||
|
uuid = Gitlab::CurrentSettings.uuid || 'uuid-not-set'
|
||||||
|
day_of_week = Digest::MD5.hexdigest(uuid).to_i(16) % 7
|
||||||
|
|
||||||
"#{minute}0-#{minute}9 #{hour} * * 0"
|
"#{minute} #{hour} * * #{day_of_week}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue