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
2773aa90
Commit
2773aa90
authored
May 11, 2020
by
Amparo Luna
Committed by
Douglas Barbosa Alexandre
May 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Web IDE terminal counts
parent
0f64659d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
5 deletions
+66
-5
ee/app/controllers/projects/web_ide_terminals_controller.rb
ee/app/controllers/projects/web_ide_terminals_controller.rb
+2
-0
ee/changelogs/unreleased/al-214347-web-ide-terminal-usage.yml
...hangelogs/unreleased/al-214347-web-ide-terminal-usage.yml
+5
-0
ee/spec/controllers/projects/web_ide_terminals_controller_spec.rb
...controllers/projects/web_ide_terminals_controller_spec.rb
+46
-3
lib/gitlab/usage_data_counters/web_ide_counter.rb
lib/gitlab/usage_data_counters/web_ide_counter.rb
+5
-1
spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb
spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb
+8
-1
No files found.
ee/app/controllers/projects/web_ide_terminals_controller.rb
View file @
2773aa90
...
...
@@ -37,6 +37,8 @@ class Projects::WebIdeTerminalsController < Projects::ApplicationController
current_build
=
pipeline
.
builds
.
last
if
current_build
Gitlab
::
UsageDataCounters
::
WebIdeCounter
.
increment_terminals_count
render_terminal
(
current_build
)
else
render
status: :bad_request
,
json:
pipeline
.
errors
.
full_messages
...
...
ee/changelogs/unreleased/al-214347-web-ide-terminal-usage.yml
0 → 100644
View file @
2773aa90
---
title
:
Add Web IDE terminal usage counter
merge_request
:
31158
author
:
type
:
added
ee/spec/controllers/projects/web_ide_terminals_controller_spec.rb
View file @
2773aa90
...
...
@@ -149,7 +149,7 @@ describe Projects::WebIdeTerminalsController do
}
end
context
'
access rights
'
do
context
'
when terminal job is created successfully
'
do
let
(
:build
)
{
create
(
:ci_build
,
project:
project
)
}
let
(
:pipeline
)
{
build
.
pipeline
}
...
...
@@ -157,11 +157,29 @@ describe Projects::WebIdeTerminalsController do
allow_next_instance_of
(
::
Ci
::
CreateWebIdeTerminalService
)
do
|
instance
|
allow
(
instance
).
to
receive
(
:execute
).
and_return
(
status: :success
,
pipeline:
pipeline
)
end
end
context
'access rights'
do
before
do
subject
end
it_behaves_like
'terminal access rights'
end
it
'increases the web ide terminal counter'
do
expect
(
Gitlab
::
UsageDataCounters
::
WebIdeCounter
).
to
receive
(
:increment_terminals_count
)
subject
end
end
shared_examples
'web ide terminal usage counter'
do
it
'does not increase'
,
:enable_admin_mode
do
expect
(
Gitlab
::
UsageDataCounters
::
WebIdeCounter
).
not_to
receive
(
:increment_terminals_count
)
it_behaves_like
'terminal access rights'
subject
end
end
context
'when branch does not exist'
do
...
...
@@ -173,20 +191,45 @@ describe Projects::WebIdeTerminalsController do
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
it_behaves_like
'web ide terminal usage counter'
end
context
'when there is an error creating the job'
do
let
(
:user
)
{
admin
}
it
'returns 400'
,
:enable_admin_mod
e
do
befor
e
do
allow_next_instance_of
(
::
Ci
::
CreateWebIdeTerminalService
)
do
|
instance
|
allow
(
instance
).
to
receive
(
:execute
).
and_return
(
status: :error
,
message:
'foobar'
)
end
end
it
'returns 400'
,
:enable_admin_mode
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
it_behaves_like
'web ide terminal usage counter'
end
context
'when the current build is nil'
do
let
(
:user
)
{
admin
}
before
do
allow
(
pipeline
).
to
receive
(
:builds
).
and_return
([])
allow_next_instance_of
(
::
Ci
::
CreateWebIdeTerminalService
)
do
|
instance
|
allow
(
instance
).
to
receive
(
:execute
).
and_return
(
status: :success
,
pipeline:
pipeline
)
end
end
it
'returns 400'
,
:enable_admin_mode
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
it_behaves_like
'web ide terminal usage counter'
end
end
...
...
lib/gitlab/usage_data_counters/web_ide_counter.rb
View file @
2773aa90
...
...
@@ -4,7 +4,7 @@ module Gitlab
module
UsageDataCounters
class
WebIdeCounter
extend
RedisCounter
KNOWN_EVENTS
=
%i[commits views merge_requests previews]
.
freeze
KNOWN_EVENTS
=
%i[commits views merge_requests previews
terminals
]
.
freeze
PREFIX
=
'web_ide'
class
<<
self
...
...
@@ -20,6 +20,10 @@ module Gitlab
increment
(
redis_key
(
'views'
))
end
def
increment_terminals_count
increment
(
redis_key
(
'terminals'
))
end
def
increment_previews_count
return
unless
Gitlab
::
CurrentSettings
.
web_ide_clientside_preview_enabled?
...
...
spec/lib/gitlab/usage_data_counters/web_ide_counter_spec.rb
View file @
2773aa90
...
...
@@ -26,6 +26,10 @@ describe Gitlab::UsageDataCounters::WebIdeCounter, :clean_gitlab_redis_shared_st
it_behaves_like
'counter examples'
,
'views'
end
describe
'terminals counter'
do
it_behaves_like
'counter examples'
,
'terminals'
end
describe
'previews counter'
do
let
(
:setting_enabled
)
{
true
}
...
...
@@ -56,6 +60,7 @@ describe Gitlab::UsageDataCounters::WebIdeCounter, :clean_gitlab_redis_shared_st
merge_requests
=
3
views
=
2
previews
=
4
terminals
=
1
before
do
stub_application_setting
(
web_ide_clientside_preview_enabled:
true
)
...
...
@@ -64,6 +69,7 @@ describe Gitlab::UsageDataCounters::WebIdeCounter, :clean_gitlab_redis_shared_st
merge_requests
.
times
{
described_class
.
increment_merge_requests_count
}
views
.
times
{
described_class
.
increment_views_count
}
previews
.
times
{
described_class
.
increment_previews_count
}
terminals
.
times
{
described_class
.
increment_terminals_count
}
end
it
'can report all totals'
do
...
...
@@ -71,7 +77,8 @@ describe Gitlab::UsageDataCounters::WebIdeCounter, :clean_gitlab_redis_shared_st
web_ide_commits:
commits
,
web_ide_views:
views
,
web_ide_merge_requests:
merge_requests
,
web_ide_previews:
previews
web_ide_previews:
previews
,
web_ide_terminals:
terminals
)
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