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
0ac6daed
Commit
0ac6daed
authored
Oct 06, 2020
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track issue time tracking events in usage ping
This tracks changes to due date, time estimate, and time spent
parent
7d523a37
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
203 additions
and
72 deletions
+203
-72
app/services/system_notes/time_tracking_service.rb
app/services/system_notes/time_tracking_service.rb
+12
-0
changelogs/unreleased/229918-track-time-tracking-events.yml
changelogs/unreleased/229918-track-time-tracking-events.yml
+5
-0
lib/gitlab/usage_data_counters/issue_activity_unique_counter.rb
...tlab/usage_data_counters/issue_activity_unique_counter.rb
+15
-0
lib/gitlab/usage_data_counters/known_events.yml
lib/gitlab/usage_data_counters/known_events.yml
+12
-0
spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb
...usage_data_counters/issue_activity_unique_counter_spec.rb
+30
-0
spec/services/system_notes/time_tracking_service_spec.rb
spec/services/system_notes/time_tracking_service_spec.rb
+129
-72
No files found.
app/services/system_notes/time_tracking_service.rb
View file @
0ac6daed
...
...
@@ -16,6 +16,8 @@ module SystemNotes
def
change_due_date
(
due_date
)
body
=
due_date
?
"changed due date to
#{
due_date
.
to_s
(
:long
)
}
"
:
'removed due date'
issue_activity_counter
.
track_issue_due_date_changed_action
(
author:
author
)
if
noteable
.
is_a?
(
Issue
)
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'due_date'
))
end
...
...
@@ -38,6 +40,8 @@ module SystemNotes
"changed time estimate to
#{
parsed_time
}
"
end
issue_activity_counter
.
track_issue_time_estimate_changed_action
(
author:
author
)
if
noteable
.
is_a?
(
Issue
)
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'time_tracking'
))
end
...
...
@@ -67,7 +71,15 @@ module SystemNotes
body
=
text_parts
.
join
(
' '
)
end
issue_activity_counter
.
track_issue_time_spent_changed_action
(
author:
author
)
if
noteable
.
is_a?
(
Issue
)
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'time_tracking'
))
end
private
def
issue_activity_counter
Gitlab
::
UsageDataCounters
::
IssueActivityUniqueCounter
end
end
end
changelogs/unreleased/229918-track-time-tracking-events.yml
0 → 100644
View file @
0ac6daed
---
title
:
Track issue time tracking events in usage ping
merge_request
:
44404
author
:
type
:
other
lib/gitlab/usage_data_counters/issue_activity_unique_counter.rb
View file @
0ac6daed
...
...
@@ -30,6 +30,9 @@ module Gitlab
ISSUE_DESIGNS_ADDED
=
'g_project_management_issue_designs_added'
ISSUE_DESIGNS_MODIFIED
=
'g_project_management_issue_designs_modified'
ISSUE_DESIGNS_REMOVED
=
'g_project_management_issue_designs_removed'
ISSUE_DUE_DATE_CHANGED
=
'g_project_management_issue_due_date_changed'
ISSUE_TIME_ESTIMATE_CHANGED
=
'g_project_management_issue_time_estimate_changed'
ISSUE_TIME_SPENT_CHANGED
=
'g_project_management_issue_time_spent_changed'
class
<<
self
def
track_issue_created_action
(
author
:,
time:
Time
.
zone
.
now
)
...
...
@@ -132,6 +135,18 @@ module Gitlab
track_unique_action
(
ISSUE_DESIGNS_REMOVED
,
author
,
time
)
end
def
track_issue_due_date_changed_action
(
author
:,
time:
Time
.
zone
.
now
)
track_unique_action
(
ISSUE_DUE_DATE_CHANGED
,
author
,
time
)
end
def
track_issue_time_estimate_changed_action
(
author
:,
time:
Time
.
zone
.
now
)
track_unique_action
(
ISSUE_TIME_ESTIMATE_CHANGED
,
author
,
time
)
end
def
track_issue_time_spent_changed_action
(
author
:,
time:
Time
.
zone
.
now
)
track_unique_action
(
ISSUE_TIME_SPENT_CHANGED
,
author
,
time
)
end
private
def
track_unique_action
(
action
,
author
,
time
)
...
...
lib/gitlab/usage_data_counters/known_events.yml
View file @
0ac6daed
...
...
@@ -291,3 +291,15 @@
category
:
issues_edit
redis_slot
:
project_management
aggregation
:
daily
-
name
:
g_project_management_issue_due_date_changed
category
:
issues_edit
redis_slot
:
project_management
aggregation
:
daily
-
name
:
g_project_management_issue_time_estimate_changed
category
:
issues_edit
redis_slot
:
project_management
aggregation
:
daily
-
name
:
g_project_management_issue_time_spent_changed
category
:
issues_edit
redis_slot
:
project_management
aggregation
:
daily
spec/lib/gitlab/usage_data_counters/issue_activity_unique_counter_spec.rb
View file @
0ac6daed
...
...
@@ -262,6 +262,36 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end
end
context
'for Issue due date changed actions'
do
it_behaves_like
'tracks and counts action'
do
let
(
:action
)
{
described_class
::
ISSUE_DUE_DATE_CHANGED
}
def
track_action
(
params
)
described_class
.
track_issue_due_date_changed_action
(
**
params
)
end
end
end
context
'for Issue time estimate changed actions'
do
it_behaves_like
'tracks and counts action'
do
let
(
:action
)
{
described_class
::
ISSUE_TIME_ESTIMATE_CHANGED
}
def
track_action
(
params
)
described_class
.
track_issue_time_estimate_changed_action
(
**
params
)
end
end
end
context
'for Issue time spent changed actions'
do
it_behaves_like
'tracks and counts action'
do
let
(
:action
)
{
described_class
::
ISSUE_TIME_SPENT_CHANGED
}
def
track_action
(
params
)
described_class
.
track_issue_time_spent_changed_action
(
**
params
)
end
end
end
it
'can return the count of actions per user deduplicated'
,
:aggregate_failures
do
described_class
.
track_issue_title_changed_action
(
author:
user1
)
described_class
.
track_issue_description_changed_action
(
author:
user1
)
...
...
spec/services/system_notes/time_tracking_service_spec.rb
View file @
0ac6daed
...
...
@@ -6,13 +6,14 @@ RSpec.describe ::SystemNotes::TimeTrackingService do
let_it_be
(
:author
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:noteable
)
{
create
(
:issue
,
project:
project
)
}
describe
'#change_due_date'
do
subject
{
described_class
.
new
(
noteable:
noteable
,
project:
project
,
author:
author
).
change_due_date
(
due_date
)
}
let
(
:due_date
)
{
Date
.
today
}
context
'when noteable is an issue'
do
let_it_be
(
:noteable
)
{
create
(
:issue
,
project:
project
)
}
it_behaves_like
'a note with overridable created_at'
it_behaves_like
'a system note'
do
...
...
@@ -32,11 +33,31 @@ RSpec.describe ::SystemNotes::TimeTrackingService do
expect
(
subject
.
note
).
to
eq
'removed due date'
end
end
it
'tracks the issue event in usage ping'
do
expect
(
Gitlab
::
UsageDataCounters
::
IssueActivityUniqueCounter
).
to
receive
(
:track_issue_due_date_changed_action
).
with
(
author:
author
)
subject
end
end
context
'when noteable is a merge request'
do
let_it_be
(
:noteable
)
{
create
(
:merge_request
,
source_project:
project
)
}
it
'does not track the issue event in usage ping'
do
expect
(
Gitlab
::
UsageDataCounters
::
IssueActivityUniqueCounter
).
not_to
receive
(
:track_issue_due_date_changed_action
).
with
(
author:
author
)
subject
end
end
end
describe
'
.
change_time_estimate'
do
describe
'
#
change_time_estimate'
do
subject
{
described_class
.
new
(
noteable:
noteable
,
project:
project
,
author:
author
).
change_time_estimate
}
context
'when noteable is an issue'
do
let_it_be
(
:noteable
,
reload:
true
)
{
create
(
:issue
,
project:
project
)
}
it_behaves_like
'a system note'
do
let
(
:action
)
{
'time_tracking'
}
end
...
...
@@ -66,23 +87,37 @@ RSpec.describe ::SystemNotes::TimeTrackingService do
expect
(
subject
.
note
).
to
eq
"removed time estimate"
end
end
end
describe
'.change_time_spent'
do
# We need a custom noteable in order to the shared examples to be green.
let
(
:noteable
)
do
mr
=
create
(
:merge_request
,
source_project:
project
)
mr
.
spend_time
(
duration:
360000
,
user_id:
author
.
id
)
mr
.
save!
mr
it
'tracks the issue event in usage ping'
do
expect
(
Gitlab
::
UsageDataCounters
::
IssueActivityUniqueCounter
).
to
receive
(
:track_issue_time_estimate_changed_action
).
with
(
author:
author
)
subject
end
end
subject
do
described_class
.
new
(
noteable:
noteable
,
project:
project
,
author:
author
).
change_time_spent
context
'when noteable is a merge request'
do
let_it_be
(
:noteable
)
{
create
(
:merge_request
,
source_project:
project
)
}
it
'does not track the issue event in usage ping'
do
expect
(
Gitlab
::
UsageDataCounters
::
IssueActivityUniqueCounter
).
not_to
receive
(
:track_issue_time_estimate_changed_action
).
with
(
author:
author
)
subject
end
end
end
describe
'#change_time_spent'
do
subject
{
described_class
.
new
(
noteable:
noteable
,
project:
project
,
author:
author
).
change_time_spent
}
context
'when noteable is an issue'
do
let_it_be
(
:noteable
,
reload:
true
)
{
create
(
:issue
,
project:
project
)
}
it_behaves_like
'a system note'
do
let
(
:action
)
{
'time_tracking'
}
before
do
spend_time!
(
277200
)
end
end
context
'when time was added'
do
...
...
@@ -91,10 +126,10 @@ RSpec.describe ::SystemNotes::TimeTrackingService do
expect
(
subject
.
note
).
to
eq
"added 1w 4d 5h of time spent"
end
end
context
'when time was subtracted'
do
it
'sets the note text'
do
spend_time!
(
360000
)
spend_time!
(
-
277200
)
expect
(
subject
.
note
).
to
eq
"subtracted 1w 4d 5h of time spent"
...
...
@@ -121,9 +156,31 @@ RSpec.describe ::SystemNotes::TimeTrackingService do
end
end
it
'tracks the issue event in usage ping'
do
expect
(
Gitlab
::
UsageDataCounters
::
IssueActivityUniqueCounter
).
to
receive
(
:track_issue_time_spent_changed_action
).
with
(
author:
author
)
spend_time!
(
277200
)
subject
end
end
context
'when noteable is a merge request'
do
let_it_be
(
:noteable
)
{
create
(
:merge_request
,
source_project:
project
)
}
it
'does not track the issue event in usage ping'
do
expect
(
Gitlab
::
UsageDataCounters
::
IssueActivityUniqueCounter
).
not_to
receive
(
:track_issue_time_estimate_changed_action
).
with
(
author:
author
)
spend_time!
(
277200
)
subject
end
end
def
spend_time!
(
seconds
)
noteable
.
spend_time
(
duration:
seconds
,
user_id:
author
.
id
)
noteable
.
save!
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