Commit f8b0a910 authored by Patrick Bajao's avatar Patrick Bajao

Add tracking to merge request lables/milestone changes

We need to track how many users change the labels and milestone for
MRs.

To get that, whenever the labels and milestone changes for a merge
request, we track the following events:

- i_code_review_user_labels_changed
- i_code_review_user_milestone_changed
parent 48e6b011
......@@ -50,6 +50,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)
track_labels_change(merge_request, old_labels)
notify_if_labels_added(merge_request, old_labels)
notify_if_mentions_added(merge_request, old_mentioned_users)
......@@ -113,6 +114,12 @@ module MergeRequests
merge_request_activity_counter.track_time_spent_changed_action(user: current_user) if old_timelogs != merge_request.timelogs
end
def track_labels_change(merge_request, old_labels)
return if Set.new(merge_request.labels) == Set.new(old_labels)
merge_request_activity_counter.track_labels_changed_action(user: current_user)
end
def notify_if_labels_added(merge_request, old_labels)
added_labels = merge_request.labels - old_labels
......@@ -191,6 +198,8 @@ module MergeRequests
return unless merge_request.previous_changes.include?('milestone_id')
merge_request_activity_counter.track_milestone_changed_action(user: current_user)
if merge_request.milestone.nil?
notification_service.async.removed_milestone_merge_request(merge_request, current_user)
else
......
---
title: Add tracking to merge request labels/milestone changes
merge_request: 55484
author:
type: other
---
name: usage_data_i_code_review_user_labels_changed
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55484
rollout_issue_url:
milestone: '13.10'
type: development
group: group::code review
default_enabled: true
---
name: usage_data_i_code_review_user_milestone_changed
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55484
rollout_issue_url:
milestone: '13.10'
type: development
group: group::code review
default_enabled: true
---
key_path: redis_hll_counters.code_review.i_code_review_user_milestone_changed_monthly
description: Count of unique users per month who changed milestone of a MR
product_section: dev
product_stage: create
product_group: group::code review
product_category: code_review
value_type: number
status: implemented
milestone: "13.10"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55484
time_frame: 28d
data_source: redis_hll
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
---
key_path: redis_hll_counters.code_review.i_code_review_user_labels_changed_monthly
description: Count of unique users per month who changed labels of a MR
product_section: dev
product_stage: create
product_group: group::code review
product_category: code_review
value_type: number
status: implemented
milestone: "13.10"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55484
time_frame: 28d
data_source: redis_hll
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
---
key_path: redis_hll_counters.code_review.i_code_review_user_milestone_changed_weekly
description: Count of unique users per week who changed milestone of a MR
product_section: dev
product_stage: create
product_group: group::code review
product_category: code_review
value_type: number
status: implemented
milestone: "13.10"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55484
time_frame: 7d
data_source: redis_hll
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
---
key_path: redis_hll_counters.code_review.i_code_review_user_labels_changed_weekly
description: Count of unique users per week who changed labels of a MR
product_section: dev
product_stage: create
product_group: group::code review
product_category: code_review
value_type: number
status: implemented
milestone: "13.10"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55484
time_frame: 7d
data_source: redis_hll
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
......@@ -8444,6 +8444,30 @@ Status: `data_available`
Tiers:
### `redis_hll_counters.code_review.i_code_review_user_labels_changed_monthly`
Count of unique users per month who changed labels of a MR
[YAML definition](https://gitlab.com/gitlab-org/gitlab/-/blob/master/config/metrics/counts_28d/20210302110607_i_code_review_user_labels_changed_monthly.yml)
Group: `group::code review`
Status: `implemented`
Tiers: `free`, `premium`, `ultimate`
### `redis_hll_counters.code_review.i_code_review_user_labels_changed_weekly`
Count of unique users per week who changed labels of a MR
[YAML definition](https://gitlab.com/gitlab-org/gitlab/-/blob/master/config/metrics/counts_7d/20210302110548_i_code_review_user_labels_changed_weekly.yml)
Group: `group::code review`
Status: `implemented`
Tiers: `free`, `premium`, `ultimate`
### `redis_hll_counters.code_review.i_code_review_user_marked_as_draft_monthly`
Missing description
......@@ -8492,6 +8516,30 @@ Status: `data_available`
Tiers:
### `redis_hll_counters.code_review.i_code_review_user_milestone_changed_monthly`
Count of unique users per month who changed milestone of a MR
[YAML definition](https://gitlab.com/gitlab-org/gitlab/-/blob/master/config/metrics/counts_28d/20210302110520_i_code_review_user_milestone_changed_monthly.yml)
Group: `group::code review`
Status: `implemented`
Tiers: `free`, `premium`, `ultimate`
### `redis_hll_counters.code_review.i_code_review_user_milestone_changed_weekly`
Count of unique users per week who changed milestone of a MR
[YAML definition](https://gitlab.com/gitlab-org/gitlab/-/blob/master/config/metrics/counts_7d/20210302110403_i_code_review_user_milestone_changed_weekly.yml)
Group: `group::code review`
Status: `implemented`
Tiers: `free`, `premium`, `ultimate`
### `redis_hll_counters.code_review.i_code_review_user_mr_discussion_locked_monthly`
Count of unique users per month who locked a MR
......
......@@ -48,7 +48,9 @@
'i_code_review_user_time_estimate_changed',
'i_code_review_user_time_spent_changed',
'i_code_review_user_assignees_changed',
'i_code_review_user_reviewers_changed'
'i_code_review_user_reviewers_changed',
'i_code_review_user_milestone_changed',
'i_code_review_user_labels_changed'
]
- name: code_review_category_monthly_active_users
operator: OR
......@@ -90,7 +92,9 @@
'i_code_review_user_time_estimate_changed',
'i_code_review_user_time_spent_changed',
'i_code_review_user_assignees_changed',
'i_code_review_user_reviewers_changed'
'i_code_review_user_reviewers_changed',
'i_code_review_user_milestone_changed',
'i_code_review_user_labels_changed'
]
- name: code_review_extension_category_monthly_active_users
operator: OR
......
......@@ -194,3 +194,13 @@
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_reviewers_changed
- name: i_code_review_user_milestone_changed
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_milestone_changed
- name: i_code_review_user_labels_changed
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_labels_changed
......@@ -42,6 +42,8 @@ module Gitlab
MR_ASSIGNEES_CHANGED_ACTION = 'i_code_review_user_assignees_changed'
MR_REVIEWERS_CHANGED_ACTION = 'i_code_review_user_reviewers_changed'
MR_INCLUDING_CI_CONFIG_ACTION = 'o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile'
MR_MILESTONE_CHANGED_ACTION = 'i_code_review_user_milestone_changed'
MR_LABELS_CHANGED_ACTION = 'i_code_review_user_labels_changed'
class << self
def track_mr_diffs_action(merge_request:)
......@@ -191,6 +193,14 @@ module Gitlab
track_unique_action_by_user(MR_INCLUDING_CI_CONFIG_ACTION, user)
end
def track_milestone_changed_action(user:)
track_unique_action_by_user(MR_MILESTONE_CHANGED_ACTION, user)
end
def track_labels_changed_action(user:)
track_unique_action_by_user(MR_LABELS_CHANGED_ACTION, user)
end
private
def track_unique_action_by_merge_request(action, merge_request)
......
......@@ -370,4 +370,20 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl
it_behaves_like 'not tracked merge request unique event'
end
end
describe '.track_milestone_changed_action' do
subject { described_class.track_milestone_changed_action(user: user) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_MILESTONE_CHANGED_ACTION }
end
end
describe '.track_labels_changed_action' do
subject { described_class.track_labels_changed_action(user: user) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_LABELS_CHANGED_ACTION }
end
end
end
......@@ -187,6 +187,24 @@ RSpec.describe MergeRequests::UpdateService, :mailer do
MergeRequests::UpdateService.new(project, user, opts).execute(merge_request)
end
it 'tracks milestone change' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_milestone_changed_action).once.with(user: user)
opts[:milestone] = milestone
MergeRequests::UpdateService.new(project, user, opts).execute(merge_request)
end
it 'track labels change' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_labels_changed_action).once.with(user: user)
opts[:label_ids] = [label2.id]
MergeRequests::UpdateService.new(project, user, opts).execute(merge_request)
end
context 'assignees' do
context 'when assignees changed' do
it 'tracks assignees changed event' 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