Commit e3a02506 authored by Patrick Bajao's avatar Patrick Bajao

Track usage pings when MR gets locked/unlocked

We need to track how many users locks/unlocks a merge request.

To get that, whenever the `discussion_locked` gets toggled for a
merge request, we track the following events:

- i_code_review_user_mr_discussion_locked
- i_code_review_user_mr_discussion_unlocked
parent 37814a05
......@@ -47,6 +47,7 @@ module MergeRequests
handle_draft_status_change(merge_request, changed_fields)
track_title_and_desc_edits(changed_fields)
track_discussion_lock_toggle(merge_request, changed_fields)
notify_if_labels_added(merge_request, old_labels)
notify_if_mentions_added(merge_request, old_mentioned_users)
......@@ -95,6 +96,16 @@ module MergeRequests
end
end
def track_discussion_lock_toggle(merge_request, changed_fields)
return unless changed_fields.include?('discussion_locked')
if merge_request.discussion_locked
merge_request_activity_counter.track_discussion_locked_action(user: current_user)
else
merge_request_activity_counter.track_discussion_unlocked_action(user: current_user)
end
end
def notify_if_labels_added(merge_request, old_labels)
added_labels = merge_request.labels - old_labels
......
---
title: Track usage pings when MR gets locked/unlocked
merge_request: 55069
author:
type: other
---
name: usage_data_i_code_review_user_mr_discussion_locked
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55069
rollout_issue_url:
milestone: '13.10'
type: development
group: group::code review
default_enabled: true
---
name: usage_data_i_code_review_user_mr_discussion_unlocked
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55069
rollout_issue_url:
milestone: '13.10'
type: development
group: group::code review
default_enabled: true
......@@ -42,7 +42,9 @@
'i_code_review_user_approval_rule_edited',
'i_code_review_user_vs_code_api_request',
'i_code_review_user_toggled_task_item_status',
'i_code_review_user_create_mr_from_issue'
'i_code_review_user_create_mr_from_issue',
'i_code_review_user_mr_discussion_locked',
'i_code_review_user_mr_discussion_unlocked'
]
- name: code_review_category_monthly_active_users
operator: OR
......@@ -78,7 +80,9 @@
'i_code_review_user_approval_rule_deleted',
'i_code_review_user_approval_rule_edited',
'i_code_review_user_toggled_task_item_status',
'i_code_review_user_create_mr_from_issue'
'i_code_review_user_create_mr_from_issue',
'i_code_review_user_mr_discussion_locked',
'i_code_review_user_mr_discussion_unlocked'
]
- name: code_review_extension_category_monthly_active_users
operator: OR
......
......@@ -164,3 +164,13 @@
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_create_mr_from_issue
- name: i_code_review_user_mr_discussion_locked
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_mr_discussion_locked
- name: i_code_review_user_mr_discussion_unlocked
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_mr_discussion_unlocked
......@@ -35,6 +35,8 @@ module Gitlab
MR_EDIT_MR_TITLE_ACTION = 'i_code_review_edit_mr_title'
MR_EDIT_MR_DESC_ACTION = 'i_code_review_edit_mr_desc'
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'
class << self
def track_mr_diffs_action(merge_request:)
......@@ -153,6 +155,14 @@ module Gitlab
track_unique_action_by_user(MR_CREATE_FROM_ISSUE_ACTION, user)
end
def track_discussion_locked_action(user:)
track_unique_action_by_user(MR_DISCUSSION_LOCKED_ACTION, user)
end
def track_discussion_unlocked_action(user:)
track_unique_action_by_user(MR_DISCUSSION_UNLOCKED_ACTION, user)
end
private
def track_unique_action_by_merge_request(action, merge_request)
......
......@@ -284,4 +284,20 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl
let(:action) { described_class::MR_CREATE_FROM_ISSUE_ACTION }
end
end
describe '.track_discussion_locked_action' do
subject { described_class.track_discussion_locked_action(user: user) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_DISCUSSION_LOCKED_ACTION }
end
end
describe '.track_discussion_unlocked_action' do
subject { described_class.track_discussion_unlocked_action(user: user) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_DISCUSSION_UNLOCKED_ACTION }
end
end
end
......@@ -117,6 +117,28 @@ RSpec.describe MergeRequests::UpdateService, :mailer do
MergeRequests::UpdateService.new(project, user, opts).execute(draft_merge_request)
end
it 'tracks discussion locking' do
merge_request.update!(discussion_locked: false)
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_discussion_locked_action).once.with(user: user)
opts[:discussion_locked] = true
MergeRequests::UpdateService.new(project, user, opts).execute(merge_request)
end
it 'tracks dicussion unlocking' do
merge_request.update!(discussion_locked: true)
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_discussion_unlocked_action).once.with(user: user)
opts[:discussion_locked] = false
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