Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c13567bb
Commit
c13567bb
authored
Jul 04, 2020
by
Alper Akgun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set the usage ping cron based on UUID
Review comments
parent
cc29e1ba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
3 deletions
+26
-3
config/settings.rb
config/settings.rb
+4
-3
spec/config/settings_spec.rb
spec/config/settings_spec.rb
+22
-0
No files found.
config/settings.rb
View file @
c13567bb
...
...
@@ -184,14 +184,15 @@ class Settings < Settingslogic
URI
.
parse
(
url_without_path
).
host
end
# Runs at a
random time of day on a consistent
day of the week based on
# Runs at a
consistent random time of day on a
day of the week based on
# the instance UUID. This is to balance the load on the service receiving
# these pings. The sidekiq job handles temporary http failures.
def
cron_for_usage_ping
hour
=
rand
(
24
)
minute
=
rand
(
60
)
# Set a default UUID for the case when the UUID hasn't been initialized.
uuid
=
Gitlab
::
CurrentSettings
.
uuid
||
'uuid-not-set'
minute
=
Digest
::
MD5
.
hexdigest
(
uuid
+
'minute'
).
to_i
(
16
)
%
60
hour
=
Digest
::
MD5
.
hexdigest
(
uuid
+
'hour'
).
to_i
(
16
)
%
24
day_of_week
=
Digest
::
MD5
.
hexdigest
(
uuid
).
to_i
(
16
)
%
7
"
#{
minute
}
#{
hour
}
* *
#{
day_of_week
}
"
...
...
spec/config/settings_spec.rb
View file @
c13567bb
...
...
@@ -112,4 +112,26 @@ RSpec.describe Settings do
end
end
end
describe
'.cron_for_usage_ping'
do
it
'returns correct crontab for some manually calculated example'
do
allow
(
Gitlab
::
CurrentSettings
)
.
to
receive
(
:uuid
)
{
'd9e2f4e8-db1f-4e51-b03d-f427e1965c4a'
}
expect
(
described_class
.
send
(
:cron_for_usage_ping
)).
to
eq
(
'21 18 * * 4'
)
end
it
'returns min, hour, day in the valid range'
do
allow
(
Gitlab
::
CurrentSettings
)
.
to
receive
(
:uuid
)
{
SecureRandom
.
uuid
}
10
.
times
do
cron
=
described_class
.
send
(
:cron_for_usage_ping
).
split
(
/\s/
)
expect
(
cron
[
0
].
to_i
).
to
be_between
(
0
,
59
)
expect
(
cron
[
1
].
to_i
).
to
be_between
(
0
,
23
)
expect
(
cron
[
4
].
to_i
).
to
be_between
(
0
,
6
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment