Commit 3aa4a9d2 authored by Michael Kozono's avatar Michael Kozono

Merge branch '292829-track-thread-metrics-for-a-merge-request' into 'master'

Track thread un/resolve metrics by user

See merge request gitlab-org/gitlab!52130
parents 9bd56a22 19aee6d2
...@@ -18,7 +18,7 @@ class Projects::DiscussionsController < Projects::ApplicationController ...@@ -18,7 +18,7 @@ class Projects::DiscussionsController < Projects::ApplicationController
end end
def unresolve def unresolve
discussion.unresolve! Discussions::UnresolveService.new(discussion, current_user).execute
render_discussion render_discussion
end end
......
...@@ -69,7 +69,7 @@ module Mutations ...@@ -69,7 +69,7 @@ module Mutations
end end
def unresolve!(discussion) def unresolve!(discussion)
discussion.unresolve! ::Discussions::UnresolveService.new(discussion, current_user).execute
end end
end end
end end
......
...@@ -40,7 +40,13 @@ module Discussions ...@@ -40,7 +40,13 @@ module Discussions
discussion.resolve!(current_user) discussion.resolve!(current_user)
@resolved_count += 1 @resolved_count += 1
MergeRequests::ResolvedDiscussionNotificationService.new(project, current_user).execute(merge_request) if merge_request if merge_request
Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter
.track_resolve_thread_action(user: current_user)
MergeRequests::ResolvedDiscussionNotificationService.new(project, current_user).execute(merge_request)
end
SystemNoteService.discussion_continued_in_issue(discussion, project, current_user, follow_up_issue) if follow_up_issue SystemNoteService.discussion_continued_in_issue(discussion, project, current_user, follow_up_issue) if follow_up_issue
end end
......
# frozen_string_literal: true
module Discussions
class UnresolveService < Discussions::BaseService
include Gitlab::Utils::StrongMemoize
def initialize(discussion, user)
@discussion = discussion
@user = user
super
end
def execute
@discussion.unresolve!
Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter
.track_unresolve_thread_action(user: @user)
end
end
end
---
name: usage_data_i_code_review_user_resolve_thread
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52130
rollout_issue_url:
milestone: '13.9'
type: development
group: group::code review
default_enabled: true
---
name: usage_data_i_code_review_user_unresolve_thread
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52130
rollout_issue_url:
milestone: '13.9'
type: development
group: group::code review
default_enabled: true
...@@ -138,7 +138,7 @@ module API ...@@ -138,7 +138,7 @@ module API
parent = noteable_parent(noteable) parent = noteable_parent(noteable)
::Discussions::ResolveService.new(parent, current_user, one_or_more_discussions: discussion).execute ::Discussions::ResolveService.new(parent, current_user, one_or_more_discussions: discussion).execute
else else
discussion.unresolve! ::Discussions::UnresolveService.new(discussion, current_user).execute
end end
present discussion, with: Entities::Discussion present discussion, with: Entities::Discussion
......
...@@ -476,6 +476,16 @@ ...@@ -476,6 +476,16 @@
category: code_review category: code_review
aggregation: weekly aggregation: weekly
feature_flag: usage_data_i_code_review_user_reopen_mr feature_flag: usage_data_i_code_review_user_reopen_mr
- name: i_code_review_user_resolve_thread
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_resolve_thread
- name: i_code_review_user_unresolve_thread
redis_slot: code_review
category: code_review
aggregation: weekly
feature_flag: usage_data_i_code_review_user_unresolve_thread
- name: i_code_review_user_merge_mr - name: i_code_review_user_merge_mr
redis_slot: code_review redis_slot: code_review
category: code_review category: code_review
......
...@@ -20,6 +20,8 @@ module Gitlab ...@@ -20,6 +20,8 @@ module Gitlab
MR_REMOVE_MULTILINE_COMMENT_ACTION = 'i_code_review_user_remove_multiline_mr_comment' MR_REMOVE_MULTILINE_COMMENT_ACTION = 'i_code_review_user_remove_multiline_mr_comment'
MR_ADD_SUGGESTION_ACTION = 'i_code_review_user_add_suggestion' MR_ADD_SUGGESTION_ACTION = 'i_code_review_user_add_suggestion'
MR_APPLY_SUGGESTION_ACTION = 'i_code_review_user_apply_suggestion' 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'
class << self class << self
def track_mr_diffs_action(merge_request:) def track_mr_diffs_action(merge_request:)
...@@ -47,6 +49,14 @@ module Gitlab ...@@ -47,6 +49,14 @@ module Gitlab
track_unique_action_by_user(MR_REOPEN_ACTION, user) track_unique_action_by_user(MR_REOPEN_ACTION, user)
end end
def track_resolve_thread_action(user:)
track_unique_action_by_user(MR_RESOLVE_THREAD_ACTION, user)
end
def track_unresolve_thread_action(user:)
track_unique_action_by_user(MR_UNRESOLVE_THREAD_ACTION, user)
end
def track_create_comment_action(note:) def track_create_comment_action(note:)
track_unique_action_by_user(MR_CREATE_COMMENT_ACTION, note.author) track_unique_action_by_user(MR_CREATE_COMMENT_ACTION, note.author)
track_multiline_unique_action(MR_CREATE_MULTILINE_COMMENT_ACTION, note) track_multiline_unique_action(MR_CREATE_MULTILINE_COMMENT_ACTION, note)
......
...@@ -186,6 +186,13 @@ RSpec.describe Projects::DiscussionsController do ...@@ -186,6 +186,13 @@ RSpec.describe Projects::DiscussionsController do
expect(Note.find(note.id).discussion.resolved?).to be false expect(Note.find(note.id).discussion.resolved?).to be false
end end
it "tracks thread unresolve usage data" do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_unresolve_thread_action).with(user: user)
delete :unresolve, params: request_params
end
it "returns status 200" do it "returns status 200" do
delete :unresolve, params: request_params delete :unresolve, params: request_params
......
...@@ -73,6 +73,22 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl ...@@ -73,6 +73,22 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl
end end
end end
describe '.track_resolve_thread_action' do
subject { described_class.track_resolve_thread_action(user: user) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_RESOLVE_THREAD_ACTION }
end
end
describe '.track_unresolve_thread_action' do
subject { described_class.track_unresolve_thread_action(user: user) }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_UNRESOLVE_THREAD_ACTION }
end
end
describe '.track_create_comment_action' do describe '.track_create_comment_action' do
subject { described_class.track_create_comment_action(note: note) } subject { described_class.track_create_comment_action(note: note) }
......
...@@ -24,6 +24,13 @@ RSpec.describe Discussions::ResolveService do ...@@ -24,6 +24,13 @@ RSpec.describe Discussions::ResolveService do
expect(discussion).to be_resolved expect(discussion).to be_resolved
end end
it 'tracks thread resolve usage data' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_resolve_thread_action).with(user: user)
service.execute
end
it 'executes the notification service' do it 'executes the notification service' do
expect_next_instance_of(MergeRequests::ResolvedDiscussionNotificationService) do |instance| expect_next_instance_of(MergeRequests::ResolvedDiscussionNotificationService) do |instance|
expect(instance).to receive(:execute).with(discussion.noteable) expect(instance).to receive(:execute).with(discussion.noteable)
...@@ -101,6 +108,13 @@ RSpec.describe Discussions::ResolveService do ...@@ -101,6 +108,13 @@ RSpec.describe Discussions::ResolveService do
service.execute service.execute
end end
it 'does not track thread resolve usage data' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.not_to receive(:track_resolve_thread_action).with(user: user)
service.execute
end
it 'does not schedule an auto-merge' do it 'does not schedule an auto-merge' do
expect(AutoMergeProcessWorker).not_to receive(:perform_async) expect(AutoMergeProcessWorker).not_to receive(:perform_async)
......
# frozen_string_literal: true
require "spec_helper"
RSpec.describe Discussions::UnresolveService do
describe "#execute" do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user, developer_projects: [project]) }
let_it_be(:merge_request) { create(:merge_request, :merge_when_pipeline_succeeds, source_project: project) }
let(:discussion) { create(:diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion }
let(:service) { described_class.new(discussion, user) }
before do
project.add_developer(user)
discussion.resolve!(user)
end
it "unresolves the discussion" do
service.execute
expect(discussion).not_to be_resolved
end
it "counts the unresolve event" do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_unresolve_thread_action).with(user: user)
service.execute
end
end
end
...@@ -13,6 +13,9 @@ RSpec.shared_examples 'resolvable discussions API' do |parent_type, noteable_typ ...@@ -13,6 +13,9 @@ RSpec.shared_examples 'resolvable discussions API' do |parent_type, noteable_typ
end end
it "unresolves discussion if resolved is false" do it "unresolves discussion if resolved is false" do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_unresolve_thread_action).with(user: user)
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}", user), params: { resolved: false } "discussions/#{note.discussion_id}", user), params: { resolved: false }
......
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