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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
ebd5e9b4
Commit
ebd5e9b4
authored
Apr 05, 2017
by
Sean McGivern
Committed by
Rémy Coutable
Apr 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port 'Add EE usage ping' to CE
CE port of
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/557
parent
c3bb21ff
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
100 additions
and
1 deletion
+100
-1
app/controllers/admin/application_settings_controller.rb
app/controllers/admin/application_settings_controller.rb
+1
-0
app/models/application_setting.rb
app/models/application_setting.rb
+2
-1
app/views/admin/application_settings/_form.html.haml
app/views/admin/application_settings/_form.html.haml
+9
-0
app/workers/gitlab_usage_ping_worker.rb
app/workers/gitlab_usage_ping_worker.rb
+40
-0
config/initializers/1_settings.rb
config/initializers/1_settings.rb
+11
-0
db/migrate/20160713222618_add_usage_ping_to_application_settings.rb
.../20160713222618_add_usage_ping_to_application_settings.rb
+7
-0
db/schema.rb
db/schema.rb
+1
-0
spec/workers/gitlab_usage_ping_worker_spec.rb
spec/workers/gitlab_usage_ping_worker_spec.rb
+29
-0
No files found.
app/controllers/admin/application_settings_controller.rb
View file @
ebd5e9b4
...
@@ -135,6 +135,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
...
@@ -135,6 +135,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
:version_check_enabled
,
:version_check_enabled
,
:terminal_max_session_time
,
:terminal_max_session_time
,
:polling_interval_multiplier
,
:polling_interval_multiplier
,
:usage_ping_enabled
,
disabled_oauth_sign_in_sources:
[],
disabled_oauth_sign_in_sources:
[],
import_sources:
[],
import_sources:
[],
...
...
app/models/application_setting.rb
View file @
ebd5e9b4
...
@@ -238,7 +238,8 @@ class ApplicationSetting < ActiveRecord::Base
...
@@ -238,7 +238,8 @@ class ApplicationSetting < ActiveRecord::Base
terminal_max_session_time:
0
,
terminal_max_session_time:
0
,
two_factor_grace_period:
48
,
two_factor_grace_period:
48
,
user_default_external:
false
,
user_default_external:
false
,
polling_interval_multiplier:
1
polling_interval_multiplier:
1
,
usage_ping_enabled:
true
}
}
end
end
...
...
app/views/admin/application_settings/_form.html.haml
View file @
ebd5e9b4
...
@@ -486,6 +486,15 @@
...
@@ -486,6 +486,15 @@
Version check enabled
Version check enabled
.help-block
.help-block
Let GitLab inform you when an update is available.
Let GitLab inform you when an update is available.
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
=
f
.
label
:usage_ping_enabled
do
=
f
.
check_box
:usage_ping_enabled
Usage ping enabled
.help-block
Every week GitLab will report license usage back to GitLab, Inc.
Disable this option if you do not want this to occur.
%fieldset
%fieldset
%legend
Email
%legend
Email
...
...
app/workers/gitlab_usage_ping_worker.rb
0 → 100644
View file @
ebd5e9b4
class
GitlabUsagePingWorker
LEASE_TIMEOUT
=
86400
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
return
unless
current_application_settings
.
usage_ping_enabled
# Multiple Sidekiq workers could run this. We should only do this at most once a day.
return
unless
try_obtain_lease
begin
HTTParty
.
post
(
url
,
body:
data
.
to_json
,
headers:
{
'Content-type'
=>
'application/json'
}
)
rescue
HTTParty
::
Error
=>
e
Rails
.
logger
.
info
"Unable to contact GitLab, Inc.:
#{
e
}
"
end
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
,
active_user_count:
User
.
active
.
acount
}
usage_data
end
def
url
'https://version.gitlab.com/usage_data'
end
end
config/initializers/1_settings.rb
View file @
ebd5e9b4
...
@@ -110,6 +110,14 @@ class Settings < Settingslogic
...
@@ -110,6 +110,14 @@ class Settings < Settingslogic
URI
.
parse
(
url_without_path
).
host
URI
.
parse
(
url_without_path
).
host
end
end
# Random cron time every Sunday to load balance usage pings
def
cron_random_weekly_time
hour
=
rand
(
24
)
minute
=
rand
(
60
)
"
#{
minute
}
#{
hour
}
* * 0"
end
end
end
end
end
...
@@ -355,6 +363,9 @@ Settings.cron_jobs['remove_unreferenced_lfs_objects_worker']['job_class'] = 'Rem
...
@@ -355,6 +363,9 @@ Settings.cron_jobs['remove_unreferenced_lfs_objects_worker']['job_class'] = 'Rem
Settings
.
cron_jobs
[
'stuck_import_jobs_worker'
]
||=
Settingslogic
.
new
({})
Settings
.
cron_jobs
[
'stuck_import_jobs_worker'
]
||=
Settingslogic
.
new
({})
Settings
.
cron_jobs
[
'stuck_import_jobs_worker'
][
'cron'
]
||=
'15 * * * *'
Settings
.
cron_jobs
[
'stuck_import_jobs_worker'
][
'cron'
]
||=
'15 * * * *'
Settings
.
cron_jobs
[
'stuck_import_jobs_worker'
][
'job_class'
]
=
'StuckImportJobsWorker'
Settings
.
cron_jobs
[
'stuck_import_jobs_worker'
][
'job_class'
]
=
'StuckImportJobsWorker'
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
# GitLab Shell
...
...
db/migrate/20160713222618_add_usage_ping_to_application_settings.rb
0 → 100644
View file @
ebd5e9b4
class
AddUsagePingToApplicationSettings
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
def
change
add_column
:application_settings
,
:usage_ping_enabled
,
:boolean
,
default:
true
,
null:
false
end
end
db/schema.rb
View file @
ebd5e9b4
...
@@ -116,6 +116,7 @@ ActiveRecord::Schema.define(version: 20170408033905) do
...
@@ -116,6 +116,7 @@ ActiveRecord::Schema.define(version: 20170408033905) do
t
.
integer
"unique_ips_limit_time_window"
t
.
integer
"unique_ips_limit_time_window"
t
.
boolean
"unique_ips_limit_enabled"
,
default:
false
,
null:
false
t
.
boolean
"unique_ips_limit_enabled"
,
default:
false
,
null:
false
t
.
decimal
"polling_interval_multiplier"
,
default:
1.0
,
null:
false
t
.
decimal
"polling_interval_multiplier"
,
default:
1.0
,
null:
false
t
.
boolean
"usage_ping_enabled"
,
default:
true
,
null:
false
end
end
create_table
"audit_events"
,
force: :cascade
do
|
t
|
create_table
"audit_events"
,
force: :cascade
do
|
t
|
...
...
spec/workers/gitlab_usage_ping_worker_spec.rb
0 → 100644
View file @
ebd5e9b4
require
'spec_helper'
describe
GitlabUsagePingWorker
do
subject
{
GitlabUsagePingWorker
.
new
}
it
"gathers license data"
do
data
=
subject
.
data
expect
(
data
[
:version
]).
to
eq
(
Gitlab
::
VERSION
)
expect
(
data
[
:active_user_count
]).
to
eq
(
User
.
active
.
count
)
end
it
"sends POST request"
do
stub_application_setting
(
usage_ping_enabled:
true
)
stub_request
(
:post
,
"https://version.gitlab.com/usage_data"
).
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
it
"does not run if usage ping is disabled"
do
stub_application_setting
(
usage_ping_enabled:
false
)
expect
(
subject
).
not_to
receive
(
:try_obtain_lease
)
expect
(
subject
).
not_to
receive
(
:perform
)
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