Commit f78ebcbd authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '292827-track-action-metrics-for-a-merge-request' into 'master'

Resolve "Track action metrics for a merge request"

See merge request gitlab-org/gitlab!50654
parents 473cf7c5 4b368cc6
......@@ -4,6 +4,7 @@ module MergeRequests
class AfterCreateService < MergeRequests::BaseService
def execute(merge_request)
event_service.open_mr(merge_request, current_user)
merge_request_activity_counter.track_create_mr_action(user: current_user)
notification_service.new_merge_request(merge_request, current_user)
create_pipeline_for(merge_request, current_user)
......
......@@ -52,6 +52,10 @@ module MergeRequests
"#<#{self.class} #{merge_request.to_reference(full: true)}>"
end
def merge_request_activity_counter
Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter
end
private
def enqueue_jira_connect_messages_for(merge_request)
......
......@@ -13,6 +13,7 @@ module MergeRequests
if merge_request.close
create_event(merge_request)
merge_request_activity_counter.track_close_mr_action(user: current_user)
create_note(merge_request)
notification_service.async.close_mr(merge_request, current_user)
todo_service.close_merge_request(merge_request, current_user)
......
......@@ -15,6 +15,7 @@ module MergeRequests
todo_service.merge_merge_request(merge_request, current_user)
create_event(merge_request)
create_note(merge_request)
merge_request_activity_counter.track_merge_mr_action(user: current_user)
notification_service.merge_mr(merge_request, current_user)
execute_hooks(merge_request, 'merge')
invalidate_cache_counts(merge_request, users: merge_request.assignees)
......
......@@ -8,6 +8,7 @@ module MergeRequests
if merge_request.reopen
create_event(merge_request)
create_note(merge_request, 'reopened')
merge_request_activity_counter.track_reopen_mr_action(user: current_user)
notification_service.async.reopen_mr(merge_request, current_user)
execute_hooks(merge_request, 'reopen')
merge_request.reload_diff(current_user)
......
---
title: Add metrics to creating, closing, reopening and merging merge requests
merge_request: 50654
author:
type: other
---
name: usage_data_i_code_review_user_close_mr
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50654
rollout_issue_url:
milestone: '13.8'
type: development
group: group::code review
default_enabled: true
---
name: usage_data_i_code_review_user_create_mr
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50654
rollout_issue_url:
milestone: '13.8'
type: development
group: group::code review
default_enabled: true
---
name: usage_data_i_code_review_user_merge_mr
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50654
rollout_issue_url:
milestone: '13.8'
type: development
group: group::code review
default_enabled: true
---
name: usage_data_i_code_review_user_reopen_mr
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50654
rollout_issue_url:
milestone: '13.8'
type: development
group: group::code review
default_enabled: true
......@@ -425,6 +425,7 @@
redis_slot: snippets
aggregation: weekly
feature_flag: usage_data_i_snippets_show
# Merge request counters
- name: i_code_review_mr_diffs
redis_slot: code_review
category: code_review
......@@ -440,6 +441,26 @@
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_mr_single_file_diffs
- name: i_code_review_user_create_mr
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_create_mr
- name: i_code_review_user_close_mr
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_close_mr
- name: i_code_review_user_reopen_mr
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_reopen_mr
- name: i_code_review_user_merge_mr
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_merge_mr
# Terraform
- name: p_terraform_state_api_unique_users
category: terraform
......
......@@ -6,6 +6,10 @@ module Gitlab
MR_DIFFS_ACTION = 'i_code_review_mr_diffs'
MR_DIFFS_SINGLE_FILE_ACTION = 'i_code_review_mr_single_file_diffs'
MR_DIFFS_USER_SINGLE_FILE_ACTION = 'i_code_review_user_single_file_diffs'
MR_CREATE_ACTION = 'i_code_review_user_create_mr'
MR_CLOSE_ACTION = 'i_code_review_user_close_mr'
MR_REOPEN_ACTION = 'i_code_review_user_reopen_mr'
MR_MERGE_ACTION = 'i_code_review_user_merge_mr'
class << self
def track_mr_diffs_action(merge_request:)
......@@ -17,6 +21,22 @@ module Gitlab
track_unique_action_by_user(MR_DIFFS_USER_SINGLE_FILE_ACTION, user)
end
def track_create_mr_action(user:)
track_unique_action_by_user(MR_CREATE_ACTION, user)
end
def track_close_mr_action(user:)
track_unique_action_by_user(MR_CLOSE_ACTION, user)
end
def track_merge_mr_action(user:)
track_unique_action_by_user(MR_MERGE_ACTION, user)
end
def track_reopen_mr_action(user:)
track_unique_action_by_user(MR_REOPEN_ACTION, user)
end
private
def track_unique_action_by_merge_request(action, merge_request)
......
......@@ -39,4 +39,36 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl
let(:action) { described_class::MR_DIFFS_USER_SINGLE_FILE_ACTION }
end
end
describe '.track_create_mr_action' do
subject { described_class.track_create_mr_action(user: user) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_CREATE_ACTION }
end
end
describe '.track_close_mr_action' do
subject { described_class.track_close_mr_action(user: user) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_CLOSE_ACTION }
end
end
describe '.track_merge_mr_action' do
subject { described_class.track_merge_mr_action(user: user) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_MERGE_ACTION }
end
end
describe '.track_reopen_mr_action' do
subject { described_class.track_reopen_mr_action(user: user) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_REOPEN_ACTION }
end
end
end
......@@ -27,6 +27,14 @@ RSpec.describe MergeRequests::AfterCreateService do
execute_service
end
it 'calls the merge request activity counter' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_create_mr_action)
.with(user: merge_request.author)
execute_service
end
it 'creates a new merge request notification' do
expect(notification_service)
.to receive(:new_merge_request).with(merge_request, merge_request.author)
......
......@@ -75,6 +75,14 @@ RSpec.describe MergeRequests::CloseService do
described_class.new(project, user, {}).execute(merge_request)
end
it 'calls the merge request activity counter' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_close_mr_action)
.with(user: user)
described_class.new(project, user, {}).execute(merge_request)
end
it 'refreshes the number of open merge requests for a valid MR', :use_clean_rails_memory_store_caching do
service = described_class.new(project, user, {})
......
......@@ -37,6 +37,14 @@ RSpec.describe MergeRequests::PostMergeService do
subject
end
it 'calls the merge request activity counter' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_merge_mr_action)
.with(user: user)
subject
end
it 'deletes non-latest diffs' do
diff_removal_service = instance_double(MergeRequests::DeleteNonLatestDiffsService, execute: nil)
......
......@@ -80,6 +80,14 @@ RSpec.describe MergeRequests::ReopenService do
described_class.new(project, user, {}).execute(merge_request)
end
it 'calls the merge request activity counter' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_reopen_mr_action)
.with(user: user)
described_class.new(project, user, {}).execute(merge_request)
end
it 'refreshes the number of open merge requests for a valid MR' do
service = described_class.new(project, user, {})
......
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