Commit 0726ef24 authored by Marc Shaw's avatar Marc Shaw

Track the number of users who are assigned and get requested for reviews

Issue: gitlab.com/gitlab-org/gitlab/-/issues/299087
MR: gitlab.com/gitlab-org/gitlab/-/merge_requests/52194
parent a32e201d
......@@ -109,6 +109,9 @@ module MergeRequests
create_assignee_note(merge_request, old_assignees)
notification_service.async.reassigned_merge_request(merge_request, current_user, old_assignees)
todo_service.reassigned_assignable(merge_request, current_user, old_assignees)
new_assignees = merge_request.assignees - old_assignees
merge_request_activity_counter.track_users_assigned_to_mr(users: new_assignees)
end
def handle_reviewers_change(merge_request, old_reviewers)
......@@ -117,6 +120,9 @@ module MergeRequests
notification_service.async.changed_reviewer_of_merge_request(merge_request, current_user, old_reviewers)
todo_service.reassigned_reviewable(merge_request, current_user, old_reviewers)
invalidate_cache_counts(merge_request, users: affected_reviewers.compact)
new_reviewers = merge_request.reviewers - old_reviewers
merge_request_activity_counter.track_users_review_requested(users: new_reviewers)
end
def create_branch_change_note(issuable, branch_type, old_branch, new_branch)
......
---
title: Track the number of users who are assigned and get requested for reviews
merge_request: 52194
author:
type: other
---
name: usage_data_i_code_review_user_assigned
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52194
rollout_issue_url:
milestone: '13.9'
type: development
group: group::code review
default_enabled: true
---
name: usage_data_i_code_review_user_review_requested
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52194
rollout_issue_url:
milestone: '13.9'
type: development
group: group::code review
default_enabled: true
......@@ -330,5 +330,25 @@ RSpec.describe MergeRequests::UpdateService, :mailer do
update_merge_request(title: 'Title')
end
context 'updating assignee_ids' do
it 'updates the tracking when user ids are valid' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_users_assigned_to_mr)
.with(users: [user, user2])
update_merge_request(assignee_ids: [user.id, user2.id])
end
end
context 'updating reviewers_ids' do
it 'updates the tracking when user ids are valid' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_users_review_requested)
.with(users: [user, user2])
update_merge_request(reviewer_ids: [user.id, user2.id])
end
end
end
end
......@@ -541,6 +541,16 @@
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_apply_suggestion
- name: i_code_review_user_assigned
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_assigned
- name: i_code_review_user_review_requested
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_review_requested
# Terraform
- name: p_terraform_state_api_unique_users
category: terraform
......
......@@ -22,6 +22,8 @@ module Gitlab
MR_APPLY_SUGGESTION_ACTION = 'i_code_review_user_apply_suggestion'
MR_RESOLVE_THREAD_ACTION = 'i_code_review_user_resolve_thread'
MR_UNRESOLVE_THREAD_ACTION = 'i_code_review_user_unresolve_thread'
MR_ASSIGNED_USERS_ACTION = 'i_code_review_user_assigned'
MR_REVIEW_REQUESTED_USERS_ACTION = 'i_code_review_user_review_requested'
class << self
def track_mr_diffs_action(merge_request:)
......@@ -88,6 +90,14 @@ module Gitlab
track_unique_action_by_user(MR_APPLY_SUGGESTION_ACTION, user)
end
def track_users_assigned_to_mr(users:)
track_unique_action_by_users(MR_ASSIGNED_USERS_ACTION, users)
end
def track_users_review_requested(users:)
track_unique_action_by_users(MR_REVIEW_REQUESTED_USERS_ACTION, users)
end
private
def track_unique_action_by_merge_request(action, merge_request)
......@@ -100,6 +110,12 @@ module Gitlab
track_unique_action(action, user.id)
end
def track_unique_action_by_users(action, users)
return if users.blank?
track_unique_action(action, users.map(&:id))
end
def track_unique_action(action, value)
Gitlab::UsageDataCounters::HLLRedisCounter.track_usage_event(action, value)
end
......
......@@ -180,4 +180,20 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl
let(:action) { described_class::MR_APPLY_SUGGESTION_ACTION }
end
end
describe '.track_users_assigned_to_mr' do
subject { described_class.track_users_assigned_to_mr(users: [user]) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_ASSIGNED_USERS_ACTION }
end
end
describe '.track_users_review_requested' do
subject { described_class.track_users_review_requested(users: [user]) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_REVIEW_REQUESTED_USERS_ACTION }
end
end
end
......@@ -143,7 +143,7 @@ RSpec.describe MergeRequests::UpdateService, :mailer do
let(:opts) { { reviewer_ids: [user2.id] } }
context 'when merge_request_reviewers feature is disabled' do
before(:context) do
before do
stub_feature_flags(merge_request_reviewers: false)
end
......@@ -152,6 +152,13 @@ RSpec.describe MergeRequests::UpdateService, :mailer do
expect(note).to be_nil
end
it 'does not update the tracking' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.not_to receive(:track_users_review_requested)
update_merge_request(reviewer_ids: [user.id])
end
end
context 'when merge_request_reviewers feature is enabled' do
......@@ -165,6 +172,14 @@ RSpec.describe MergeRequests::UpdateService, :mailer do
expect(note).not_to be_nil
expect(note.note).to include "requested review from #{user2.to_reference}"
end
it 'updates the tracking' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_users_review_requested)
.with(users: [user])
update_merge_request(reviewer_ids: [user.id])
end
end
end
......@@ -794,6 +809,14 @@ RSpec.describe MergeRequests::UpdateService, :mailer do
expect(merge_request.assignee_ids).to eq([user.id])
end
it 'updates the tracking when user ids are valid' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_users_assigned_to_mr)
.with(users: [user])
update_merge_request(assignee_ids: [user.id])
end
it 'does not update assignee_id when user cannot read issue' do
non_member = create(:user)
original_assignees = merge_request.assignees
......
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