Commit f125b2ac authored by Patrick Bajao's avatar Patrick Bajao

Add tracking to merge request time estimate/spent changes

We need to track how many users change the time estimate and spent
for MRs.

To get that, whenever the time estimate and spent changes for
a merge request, we track the following events:
- i_code_review_user_time_estimate_changed
- i_code_review_user_time_spent_changed
parent e5df1467
......@@ -31,6 +31,7 @@ module MergeRequests
old_mentioned_users = old_associations.fetch(:mentioned_users, [])
old_assignees = old_associations.fetch(:assignees, [])
old_reviewers = old_associations.fetch(:reviewers, [])
old_timelogs = old_associations.fetch(:timelogs, [])
changed_fields = merge_request.previous_changes.keys
resolve_todos(merge_request, old_labels, old_assignees, old_reviewers)
......@@ -48,6 +49,7 @@ module MergeRequests
track_title_and_desc_edits(changed_fields)
track_discussion_lock_toggle(merge_request, changed_fields)
track_time_estimate_and_spend_edits(merge_request, old_timelogs, changed_fields)
notify_if_labels_added(merge_request, old_labels)
notify_if_mentions_added(merge_request, old_mentioned_users)
......@@ -106,6 +108,11 @@ module MergeRequests
end
end
def track_time_estimate_and_spend_edits(merge_request, old_timelogs, changed_fields)
merge_request_activity_counter.track_time_estimate_changed_action(user: current_user) if changed_fields.include?('time_estimate')
merge_request_activity_counter.track_time_spent_changed_action(user: current_user) if old_timelogs != merge_request.timelogs
end
def notify_if_labels_added(merge_request, old_labels)
added_labels = merge_request.labels - old_labels
......
---
title: Add tracking to merge request time estimate/spent changes
merge_request: 55046
author:
type: other
---
name: usage_data_i_code_review_user_time_estimate_changed
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55046
rollout_issue_url:
milestone: '13.10'
type: development
group: group::code review
default_enabled: true
---
name: usage_data_i_code_review_user_time_spent_changed
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55046
rollout_issue_url:
milestone: '13.10'
type: development
group: group::code review
default_enabled: true
......@@ -44,7 +44,9 @@
'i_code_review_user_toggled_task_item_status',
'i_code_review_user_create_mr_from_issue',
'i_code_review_user_mr_discussion_locked',
'i_code_review_user_mr_discussion_unlocked'
'i_code_review_user_mr_discussion_unlocked',
'i_code_review_user_time_estimate_changed',
'i_code_review_user_time_spent_changed'
]
- name: code_review_category_monthly_active_users
operator: OR
......@@ -82,7 +84,9 @@
'i_code_review_user_toggled_task_item_status',
'i_code_review_user_create_mr_from_issue',
'i_code_review_user_mr_discussion_locked',
'i_code_review_user_mr_discussion_unlocked'
'i_code_review_user_mr_discussion_unlocked',
'i_code_review_user_time_estimate_changed',
'i_code_review_user_time_spent_changed'
]
- name: code_review_extension_category_monthly_active_users
operator: OR
......
......@@ -174,3 +174,13 @@
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_mr_discussion_unlocked
- name: i_code_review_user_time_estimate_changed
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_time_estimate_changed
- name: i_code_review_user_time_spent_changed
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_time_spent_changed
......@@ -37,6 +37,8 @@ module Gitlab
MR_CREATE_FROM_ISSUE_ACTION = 'i_code_review_user_create_mr_from_issue'
MR_DISCUSSION_LOCKED_ACTION = 'i_code_review_user_mr_discussion_locked'
MR_DISCUSSION_UNLOCKED_ACTION = 'i_code_review_user_mr_discussion_unlocked'
MR_TIME_ESTIMATE_CHANGED_ACTION = 'i_code_review_user_time_estimate_changed'
MR_TIME_SPENT_CHANGED_ACTION = 'i_code_review_user_time_spent_changed'
class << self
def track_mr_diffs_action(merge_request:)
......@@ -163,6 +165,14 @@ module Gitlab
track_unique_action_by_user(MR_DISCUSSION_UNLOCKED_ACTION, user)
end
def track_time_estimate_changed_action(user:)
track_unique_action_by_user(MR_TIME_ESTIMATE_CHANGED_ACTION, user)
end
def track_time_spent_changed_action(user:)
track_unique_action_by_user(MR_TIME_SPENT_CHANGED_ACTION, user)
end
private
def track_unique_action_by_merge_request(action, merge_request)
......
......@@ -300,4 +300,20 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl
let(:action) { described_class::MR_DISCUSSION_UNLOCKED_ACTION }
end
end
describe '.track_time_estimate_changed_action' do
subject { described_class.track_time_estimate_changed_action(user: user) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_TIME_ESTIMATE_CHANGED_ACTION }
end
end
describe '.track_time_spent_changed_action' do
subject { described_class.track_time_spent_changed_action(user: user) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_TIME_SPENT_CHANGED_ACTION }
end
end
end
......@@ -169,6 +169,23 @@ RSpec.describe MergeRequests::UpdateService, :mailer do
end
end
end
it 'tracks time estimate and spend time changes' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_time_estimate_changed_action).once.with(user: user)
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_time_spent_changed_action).once.with(user: user)
opts[:time_estimate] = 86400
opts[:spend_time] = {
duration: 3600,
user_id: user.id,
spent_at: Date.parse('2021-02-24')
}
MergeRequests::UpdateService.new(project, user, opts).execute(merge_request)
end
end
context 'updating milestone' do
......
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