BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
0483019e
Commit
0483019e
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 more usage data to EE ping' to CE
CE port of
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/735
parent
ebd5e9b4
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
192 additions
and
18 deletions
+192
-18
application_settings.js.es6
app/assets/javascripts/application_settings.js.es6
+16
-0
dispatcher.js
app/assets/javascripts/dispatcher.js
+3
-0
application_settings_controller.rb
app/controllers/admin/application_settings_controller.rb
+7
-0
_form.html.haml
app/views/admin/application_settings/_form.html.haml
+5
-3
gitlab_usage_ping_worker.rb
app/workers/gitlab_usage_ping_worker.rb
+1
-8
admin.rb
config/routes/admin.rb
+1
-0
usage_data.rb
lib/gitlab/usage_data.rb
+57
-0
application_settings_controller_spec.rb
...controllers/admin/application_settings_controller_spec.rb
+37
-0
usage_data_spec.rb
spec/lib/gitlab/usage_data_spec.rb
+65
-0
gitlab_usage_ping_worker_spec.rb
spec/workers/gitlab_usage_ping_worker_spec.rb
+0
-7
No files found.
app/assets/javascripts/application_settings.js.es6
0 → 100644
View file @
0483019e
(global => {
global.gl = global.gl || {};
gl.ApplicationSettings = function() {
var usage_data_url = $('.usage-data').data('endpoint');
$.ajax({
type: "GET",
url: usage_data_url,
dataType: "html",
success: function (html) {
$(".usage-data").html(html);
}
});
};
})(window);
app/assets/javascripts/dispatcher.js
View file @
0483019e
...
@@ -365,6 +365,9 @@ const ShortcutsBlob = require('./shortcuts_blob');
...
@@ -365,6 +365,9 @@ const ShortcutsBlob = require('./shortcuts_blob');
case
'admin'
:
case
'admin'
:
new
Admin
();
new
Admin
();
switch
(
path
[
1
])
{
switch
(
path
[
1
])
{
case
'application_settings'
:
new
gl
.
ApplicationSettings
();
break
;
case
'groups'
:
case
'groups'
:
new
UsersSelect
();
new
UsersSelect
();
break
;
break
;
...
...
app/controllers/admin/application_settings_controller.rb
View file @
0483019e
...
@@ -17,6 +17,13 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
...
@@ -17,6 +17,13 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
end
end
end
end
def
usage_data
respond_to
do
|
format
|
format
.
html
{
render
html:
Gitlab
::
Highlight
.
highlight
(
'payload.json'
,
Gitlab
::
UsageData
.
to_json
)
}
format
.
json
{
render
json:
Gitlab
::
UsageData
.
to_json
}
end
end
def
reset_runners_token
def
reset_runners_token
@application_setting
.
reset_runners_registration_token!
@application_setting
.
reset_runners_registration_token!
flash
[
:notice
]
=
'New runners registration token has been generated!'
flash
[
:notice
]
=
'New runners registration token has been generated!'
...
...
app/views/admin/application_settings/_form.html.haml
View file @
0483019e
...
@@ -492,9 +492,11 @@
...
@@ -492,9 +492,11 @@
=
f
.
label
:usage_ping_enabled
do
=
f
.
label
:usage_ping_enabled
do
=
f
.
check_box
:usage_ping_enabled
=
f
.
check_box
:usage_ping_enabled
Usage ping enabled
Usage ping enabled
.help-block
.container
Every week GitLab will report license usage back to GitLab, Inc.
.help-block
Disable this option if you do not want this to occur.
Every week GitLab will report license usage back to GitLab, Inc.
Disable this option if you do not want this to occur. This is the JSON payload that will be sent:
%pre
.usage-data.js-syntax-highlight.code.highlight
{
"data-endpoint"
=>
usage_data_admin_application_settings_path
(
format: :html
)
}
%fieldset
%fieldset
%legend
Email
%legend
Email
...
...
app/workers/gitlab_usage_ping_worker.rb
View file @
0483019e
...
@@ -15,7 +15,7 @@ class GitlabUsagePingWorker
...
@@ -15,7 +15,7 @@ class GitlabUsagePingWorker
begin
begin
HTTParty
.
post
(
url
,
HTTParty
.
post
(
url
,
body:
d
ata
.
to_json
,
body:
Gitlab
::
UsageD
ata
.
to_json
,
headers:
{
'Content-type'
=>
'application/json'
}
headers:
{
'Content-type'
=>
'application/json'
}
)
)
rescue
HTTParty
::
Error
=>
e
rescue
HTTParty
::
Error
=>
e
...
@@ -27,13 +27,6 @@ class GitlabUsagePingWorker
...
@@ -27,13 +27,6 @@ class GitlabUsagePingWorker
Gitlab
::
ExclusiveLease
.
new
(
'gitlab_usage_ping_worker:ping'
,
timeout:
LEASE_TIMEOUT
).
try_obtain
Gitlab
::
ExclusiveLease
.
new
(
'gitlab_usage_ping_worker:ping'
,
timeout:
LEASE_TIMEOUT
).
try_obtain
end
end
def
data
usage_data
=
{
version:
Gitlab
::
VERSION
,
active_user_count:
User
.
active
.
acount
}
usage_data
end
def
url
def
url
'https://version.gitlab.com/usage_data'
'https://version.gitlab.com/usage_data'
end
end
...
...
config/routes/admin.rb
View file @
0483019e
...
@@ -91,6 +91,7 @@ namespace :admin do
...
@@ -91,6 +91,7 @@ namespace :admin do
resource
:application_settings
,
only:
[
:show
,
:update
]
do
resource
:application_settings
,
only:
[
:show
,
:update
]
do
resources
:services
,
only:
[
:index
,
:edit
,
:update
]
resources
:services
,
only:
[
:index
,
:edit
,
:update
]
get
:usage_data
put
:reset_runners_token
put
:reset_runners_token
put
:reset_health_check_token
put
:reset_health_check_token
put
:clear_repository_check_states
put
:clear_repository_check_states
...
...
lib/gitlab/usage_data.rb
0 → 100644
View file @
0483019e
module
Gitlab
class
UsageData
class
<<
self
def
data
Rails
.
cache
.
fetch
(
'usage_data'
,
expires_in:
1
.
hour
)
{
uncached_data
}
end
def
uncached_data
license_usage_data
.
merge
(
system_usage_data
)
end
def
to_json
data
.
to_json
end
def
system_usage_data
{
counts:
{
boards:
Board
.
count
,
ci_builds:
::
Ci
::
Build
.
count
,
ci_pipelines:
::
Ci
::
Pipeline
.
count
,
ci_runners:
::
Ci
::
Runner
.
count
,
ci_triggers:
::
Ci
::
Trigger
.
count
,
deploy_keys:
DeployKey
.
count
,
deployments:
Deployment
.
count
,
environments:
Environment
.
count
,
groups:
Group
.
count
,
issues:
Issue
.
count
,
keys:
Key
.
count
,
labels:
Label
.
count
,
lfs_objects:
LfsObject
.
count
,
merge_requests:
MergeRequest
.
count
,
milestones:
Milestone
.
count
,
notes:
Note
.
count
,
pushes:
Event
.
code_push
.
count
,
pages_domains:
PagesDomain
.
count
,
projects:
Project
.
count
,
protected_branches:
ProtectedBranch
.
count
,
releases:
Release
.
count
,
services:
Service
.
where
(
active:
true
).
count
,
snippets:
Snippet
.
count
,
todos:
Todo
.
count
,
web_hooks:
WebHook
.
count
}
}
end
def
license_usage_data
usage_data
=
{
version:
Gitlab
::
VERSION
,
active_user_count:
User
.
active
.
count
,
recorded_at:
Time
.
now
}
usage_data
end
end
end
end
spec/controllers/admin/application_settings_controller_spec.rb
View file @
0483019e
...
@@ -3,12 +3,49 @@ require 'spec_helper'
...
@@ -3,12 +3,49 @@ require 'spec_helper'
describe
Admin
::
ApplicationSettingsController
do
describe
Admin
::
ApplicationSettingsController
do
include
StubENV
include
StubENV
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
group
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:user
)
{
create
(
:user
)}
before
do
before
do
stub_env
(
'IN_MEMORY_APPLICATION_SETTINGS'
,
'false'
)
stub_env
(
'IN_MEMORY_APPLICATION_SETTINGS'
,
'false'
)
end
end
describe
'GET #usage_data with no access'
do
before
do
sign_in
(
user
)
end
it
'returns 404'
do
get
:usage_data
,
format: :html
expect
(
response
.
status
).
to
eq
(
404
)
end
end
describe
'GET #usage_data'
do
before
do
sign_in
(
admin
)
end
it
'returns HTML data'
do
get
:usage_data
,
format: :html
expect
(
response
.
body
).
to
start_with
(
'<span'
)
expect
(
response
.
status
).
to
eq
(
200
)
end
it
'returns JSON data'
do
get
:usage_data
,
format: :json
body
=
JSON
.
parse
(
response
.
body
)
expect
(
body
[
"version"
]).
to
eq
(
Gitlab
::
VERSION
)
expect
(
body
).
to
include
(
'counts'
)
expect
(
response
.
status
).
to
eq
(
200
)
end
end
describe
'PUT #update'
do
describe
'PUT #update'
do
before
do
before
do
sign_in
(
admin
)
sign_in
(
admin
)
...
...
spec/lib/gitlab/usage_data_spec.rb
0 → 100644
View file @
0483019e
require
'spec_helper'
describe
Gitlab
::
UsageData
do
let!
(
:project
)
{
create
(
:empty_project
)
}
let!
(
:project2
)
{
create
(
:empty_project
)
}
let!
(
:board
)
{
create
(
:board
,
project:
project
)
}
describe
'#data'
do
subject
{
Gitlab
::
UsageData
.
data
}
it
"gathers usage data"
do
expect
(
subject
.
keys
).
to
match_array
(
%i(
active_user_count
counts
version
recorded_at
)
)
end
it
"gathers usage counts"
do
count_data
=
subject
[
:counts
]
expect
(
count_data
[
:boards
]).
to
eq
(
1
)
expect
(
count_data
[
:projects
]).
to
eq
(
2
)
expect
(
count_data
.
keys
).
to
match_array
(
%i(
boards
ci_builds
ci_pipelines
ci_runners
ci_triggers
deploy_keys
deployments
environments
groups
issues
keys
labels
lfs_objects
merge_requests
milestones
notes
projects
pushes
pages_domains
protected_branches
releases
services
snippets
todos
web_hooks
)
)
end
end
describe
'#license_usage_data'
do
subject
{
Gitlab
::
UsageData
.
license_usage_data
}
it
"gathers license data"
do
expect
(
subject
[
:version
]).
to
eq
(
Gitlab
::
VERSION
)
expect
(
subject
[
:active_user_count
]).
to
eq
(
User
.
active
.
count
)
expect
(
subject
[
:recorded_at
]).
to
be_a
(
Time
)
end
end
end
spec/workers/gitlab_usage_ping_worker_spec.rb
View file @
0483019e
...
@@ -3,13 +3,6 @@ require 'spec_helper'
...
@@ -3,13 +3,6 @@ require 'spec_helper'
describe
GitlabUsagePingWorker
do
describe
GitlabUsagePingWorker
do
subject
{
GitlabUsagePingWorker
.
new
}
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
it
"sends POST request"
do
stub_application_setting
(
usage_ping_enabled:
true
)
stub_application_setting
(
usage_ping_enabled:
true
)
...
...
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