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
f493c9a8
Commit
f493c9a8
authored
Jul 13, 2016
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add async task that reports EE usage every week
Closes #380
parent
1c04b072
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
2 deletions
+91
-2
app/helpers/license_helper.rb
app/helpers/license_helper.rb
+5
-0
app/views/admin/licenses/_breakdown.html.haml
app/views/admin/licenses/_breakdown.html.haml
+1
-2
app/workers/gitlab_usage_ping_worker.rb
app/workers/gitlab_usage_ping_worker.rb
+46
-0
config/initializers/1_settings.rb
config/initializers/1_settings.rb
+11
-0
spec/workers/gitlab_usage_ping_worker_spec.rb
spec/workers/gitlab_usage_ping_worker_spec.rb
+28
-0
No files found.
app/helpers/license_helper.rb
View file @
f493c9a8
...
...
@@ -3,6 +3,11 @@ module LicenseHelper
User
.
active
.
count
end
def
max_historical_user_count
date_range
=
(
Date
.
today
-
1
.
year
)
..
Date
.
today
HistoricalData
.
during
(
date_range
).
maximum
(
:active_user_count
)
||
0
end
def
license_message
(
signed_in:
signed_in?
,
is_admin:
(
current_user
&&
current_user
.
is_admin?
))
@license_message
||=
if
License
.
current
...
...
app/views/admin/licenses/_breakdown.html.haml
View file @
f493c9a8
...
...
@@ -4,8 +4,7 @@
-
else
-
licensed_users
=
'Unlimited'
-
date_range
=
(
Date
.
today
-
1
.
year
)
..
Date
.
today
-
historical
=
HistoricalData
.
during
(
date_range
).
maximum
(
:active_user_count
)
||
0
-
historical
=
max_historical_user_count
-
if
historical
&&
restricted
&&
historical
>
restricted
-
users_over_license
=
historical
-
restricted
-
else
...
...
app/workers/gitlab_usage_ping_worker.rb
0 → 100644
View file @
f493c9a8
class
GitlabUsagePingWorker
LEASE_TIMEOUT
=
86400
include
LicenseHelper
include
Sidekiq
::
Worker
include
HTTParty
# This is not guaranteed to succeed, so don't retry on failure
sidekiq_options
queue: :default
,
retry:
false
def
perform
# Multiple Sidekiq workers could run this. We should only do this at most once a day.
return
unless
try_obtain_lease
HTTParty
.
post
(
url
,
body:
data
.
to_json
,
headers:
{
'Content-type'
=>
'application/json'
}
)
end
def
try_obtain_lease
Gitlab
::
ExclusiveLease
.
new
(
'gitlab_usage_ping_worker:ping'
,
timeout:
LEASE_TIMEOUT
).
try_obtain
end
def
data
usage_data
=
{
version:
Gitlab
::
VERSION
}
usage_data
[
:active_users
]
=
current_active_user_count
license
=
License
.
current
if
license
usage_data
[
:historical_max_users
]
=
max_historical_user_count
usage_data
[
:licensee
]
=
license
.
licensee
usage_data
[
:license_user_count
]
=
license
.
user_count
usage_data
[
:license_starts_at
]
=
license
.
starts_at
usage_data
[
:license_expires_at
]
=
license
.
expires_at
usage_data
[
:license_add_ons
]
=
license
.
add_ons
usage_data
[
:recorded_at
]
=
Time
.
now
end
usage_data
end
def
url
'https://version.gitlab.com/usage_ping'
end
end
config/initializers/1_settings.rb
View file @
f493c9a8
...
...
@@ -125,6 +125,14 @@ class Settings < Settingslogic
URI
.
parse
(
url_without_path
).
host
end
# Random cron time every Sunday to load balance usage pings
def
cron_random_weekly_time
hour
=
rand
(
24
)
minute
=
rand
(
60
)
"
#{
hour
}
#{
minute
}
* * 0"
end
end
end
...
...
@@ -370,6 +378,9 @@ Settings.cron_jobs['geo_bulk_notify_worker']['job_class'] ||= 'GeoBulkNotifyWork
Settings
.
cron_jobs
[
'gitlab_remove_project_export_worker'
]
||=
Settingslogic
.
new
({})
Settings
.
cron_jobs
[
'gitlab_remove_project_export_worker'
][
'cron'
]
||=
'0 * * * *'
Settings
.
cron_jobs
[
'gitlab_remove_project_export_worker'
][
'job_class'
]
=
'GitlabRemoveProjectExportWorker'
Settings
.
cron_jobs
[
'gitlab_usage_ping_worker'
]
||=
Settingslogic
.
new
({})
Settings
.
cron_jobs
[
'gitlab_usage_ping_worker'
][
'cron'
]
||=
Settings
.
send
(
:cron_random_weekly_time
)
Settings
.
cron_jobs
[
'gitlab_usage_ping_worker'
][
'job_class'
]
=
'GitlabUsagePingWorker'
#
# GitLab Shell
...
...
spec/workers/gitlab_usage_ping_worker_spec.rb
0 → 100644
View file @
f493c9a8
require
'spec_helper'
describe
GitlabUsagePingWorker
do
subject
{
GitlabUsagePingWorker
.
new
}
it
"gathers license data"
do
data
=
subject
.
data
license
=
License
.
current
expect
(
data
[
:version
]).
to
eq
(
Gitlab
::
VERSION
)
expect
(
data
[
:licensee
]).
to
eq
(
license
.
licensee
)
expect
(
data
[
:active_users
]).
to
eq
(
User
.
active
.
count
)
expect
(
data
[
:licensee
]).
to
eq
(
license
.
licensee
)
expect
(
data
[
:license_user_count
]).
to
eq
(
license
.
user_count
)
expect
(
data
[
:license_starts_at
]).
to
eq
(
license
.
starts_at
)
expect
(
data
[
:license_expires_at
]).
to
eq
(
license
.
expires_at
)
expect
(
data
[
:license_add_ons
]).
to
eq
(
license
.
add_ons
)
expect
(
data
[
:recorded_at
]).
to
be_a
(
Time
)
end
it
"sends POST request"
do
stub_request
(
:post
,
"https://version.gitlab.com/usage_ping"
).
to_return
(
status:
200
,
body:
''
,
headers:
{})
expect
(
subject
).
to
receive
(
:try_obtain_lease
).
and_return
(
true
)
expect
(
subject
.
perform
.
response
.
code
.
to_i
).
to
eq
(
200
)
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