Commit 509b35ce authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '229918-track-time-tracking-events' into 'master'

Track issue time tracking events in usage ping

See merge request gitlab-org/gitlab!44404
parents 15205430 0ac6daed
...@@ -16,6 +16,8 @@ module SystemNotes ...@@ -16,6 +16,8 @@ module SystemNotes
def change_due_date(due_date) def change_due_date(due_date)
body = due_date ? "changed due date to #{due_date.to_s(:long)}" : 'removed 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')) create_note(NoteSummary.new(noteable, project, author, body, action: 'due_date'))
end end
...@@ -38,6 +40,8 @@ module SystemNotes ...@@ -38,6 +40,8 @@ module SystemNotes
"changed time estimate to #{parsed_time}" "changed time estimate to #{parsed_time}"
end 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')) create_note(NoteSummary.new(noteable, project, author, body, action: 'time_tracking'))
end end
...@@ -67,7 +71,15 @@ module SystemNotes ...@@ -67,7 +71,15 @@ module SystemNotes
body = text_parts.join(' ') body = text_parts.join(' ')
end 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')) create_note(NoteSummary.new(noteable, project, author, body, action: 'time_tracking'))
end end
private
def issue_activity_counter
Gitlab::UsageDataCounters::IssueActivityUniqueCounter
end
end end
end end
---
title: Track issue time tracking events in usage ping
merge_request: 44404
author:
type: other
...@@ -30,6 +30,9 @@ module Gitlab ...@@ -30,6 +30,9 @@ module Gitlab
ISSUE_DESIGNS_ADDED = 'g_project_management_issue_designs_added' ISSUE_DESIGNS_ADDED = 'g_project_management_issue_designs_added'
ISSUE_DESIGNS_MODIFIED = 'g_project_management_issue_designs_modified' ISSUE_DESIGNS_MODIFIED = 'g_project_management_issue_designs_modified'
ISSUE_DESIGNS_REMOVED = 'g_project_management_issue_designs_removed' 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 class << self
def track_issue_created_action(author:, time: Time.zone.now) def track_issue_created_action(author:, time: Time.zone.now)
...@@ -132,6 +135,18 @@ module Gitlab ...@@ -132,6 +135,18 @@ module Gitlab
track_unique_action(ISSUE_DESIGNS_REMOVED, author, time) track_unique_action(ISSUE_DESIGNS_REMOVED, author, time)
end 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 private
def track_unique_action(action, author, time) def track_unique_action(action, author, time)
......
...@@ -291,3 +291,15 @@ ...@@ -291,3 +291,15 @@
category: issues_edit category: issues_edit
redis_slot: project_management redis_slot: project_management
aggregation: daily 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
...@@ -262,6 +262,36 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git ...@@ -262,6 +262,36 @@ RSpec.describe Gitlab::UsageDataCounters::IssueActivityUniqueCounter, :clean_git
end end
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 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_title_changed_action(author: user1)
described_class.track_issue_description_changed_action(author: user1) described_class.track_issue_description_changed_action(author: user1)
......
...@@ -6,13 +6,14 @@ RSpec.describe ::SystemNotes::TimeTrackingService do ...@@ -6,13 +6,14 @@ RSpec.describe ::SystemNotes::TimeTrackingService do
let_it_be(:author) { create(:user) } let_it_be(:author) { create(:user) }
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let(:noteable) { create(:issue, project: project) }
describe '#change_due_date' do describe '#change_due_date' do
subject { described_class.new(noteable: noteable, project: project, author: author).change_due_date(due_date) } subject { described_class.new(noteable: noteable, project: project, author: author).change_due_date(due_date) }
let(:due_date) { Date.today } 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 note with overridable created_at'
it_behaves_like 'a system note' do it_behaves_like 'a system note' do
...@@ -32,11 +33,31 @@ RSpec.describe ::SystemNotes::TimeTrackingService do ...@@ -32,11 +33,31 @@ RSpec.describe ::SystemNotes::TimeTrackingService do
expect(subject.note).to eq 'removed due date' expect(subject.note).to eq 'removed due date'
end end
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 end
describe '.change_time_estimate' do describe '#change_time_estimate' do
subject { described_class.new(noteable: noteable, project: project, author: author).change_time_estimate } 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 it_behaves_like 'a system note' do
let(:action) { 'time_tracking' } let(:action) { 'time_tracking' }
end end
...@@ -66,23 +87,37 @@ RSpec.describe ::SystemNotes::TimeTrackingService do ...@@ -66,23 +87,37 @@ RSpec.describe ::SystemNotes::TimeTrackingService do
expect(subject.note).to eq "removed time estimate" expect(subject.note).to eq "removed time estimate"
end end
end end
end
describe '.change_time_spent' do it 'tracks the issue event in usage ping' do
# We need a custom noteable in order to the shared examples to be green. expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_time_estimate_changed_action).with(author: author)
let(:noteable) do
mr = create(:merge_request, source_project: project) subject
mr.spend_time(duration: 360000, user_id: author.id) end
mr.save!
mr
end end
subject do context 'when noteable is a merge request' do
described_class.new(noteable: noteable, project: project, author: author).change_time_spent 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
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 it_behaves_like 'a system note' do
let(:action) { 'time_tracking' } let(:action) { 'time_tracking' }
before do
spend_time!(277200)
end
end end
context 'when time was added' do context 'when time was added' do
...@@ -91,10 +126,10 @@ RSpec.describe ::SystemNotes::TimeTrackingService do ...@@ -91,10 +126,10 @@ RSpec.describe ::SystemNotes::TimeTrackingService do
expect(subject.note).to eq "added 1w 4d 5h of time spent" expect(subject.note).to eq "added 1w 4d 5h of time spent"
end end
end
context 'when time was subtracted' do context 'when time was subtracted' do
it 'sets the note text' do it 'sets the note text' do
spend_time!(360000)
spend_time!(-277200) spend_time!(-277200)
expect(subject.note).to eq "subtracted 1w 4d 5h of time spent" expect(subject.note).to eq "subtracted 1w 4d 5h of time spent"
...@@ -121,9 +156,31 @@ RSpec.describe ::SystemNotes::TimeTrackingService do ...@@ -121,9 +156,31 @@ RSpec.describe ::SystemNotes::TimeTrackingService do
end end
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) def spend_time!(seconds)
noteable.spend_time(duration: seconds, user_id: author.id) noteable.spend_time(duration: seconds, user_id: author.id)
noteable.save! noteable.save!
end end
end end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment