Commit 9d3bc148 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch '329889-track-total-number-of-suggestions-and-applied-suggestions' into 'master'

Resolve "Track total number of suggestions and applied suggestions"

See merge request gitlab-org/gitlab!67525
parents 68a1bbf8 08fc1ce7
......@@ -33,7 +33,7 @@ module Suggestions
.update_all(commit_id: result[:result], applied: true)
Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter
.track_apply_suggestion_action(user: current_user)
.track_apply_suggestion_action(user: current_user, suggestions: suggestion_set.suggestions)
end
def author
......
......@@ -28,7 +28,7 @@ module Suggestions
Gitlab::Database.main.bulk_insert('suggestions', rows) # rubocop:disable Gitlab/BulkInsert
end
Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter.track_add_suggestion_action(user: @note.author)
Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter.track_add_suggestion_action(note: @note)
end
end
end
---
key_path: redis_hll_counters.code_review.i_code_review_total_suggestions_added_monthly
name: "count_notes_with_suggestions_monthly"
description: Total number of monthly suggestions
product_section: dev
product_stage: create
product_group: group::code review
product_category: code_review
value_type: number
status: implemented
milestone: "14.3"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67525
time_frame: 28d
data_source: redis_hll
instrumentation_class: RedisHLLMetric
options:
events:
- i_code_review_total_suggestions_added
data_category: Optional
performance_indicator_type: []
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
---
key_path: redis_hll_counters.code_review.i_code_review_total_suggestions_applied_monthly
name: "count_notes_with_applied_suggestions_monthly"
description: Total number of monthly suggestions applied
product_section: dev
product_stage: create
product_group: group::code review
product_category: code_review
value_type: number
status: implemented
milestone: "14.3"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67525
time_frame: 28d
data_source: redis_hll
instrumentation_class: RedisHLLMetric
options:
events:
- i_code_review_total_suggestions_applied
data_category: Optional
performance_indicator_type: []
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
---
key_path: redis_hll_counters.code_review.i_code_review_total_suggestions_added_weekly
name: "count_notes_with_suggestions_weekly"
description: Total number of weekly suggestions
product_section: dev
product_stage: create
product_group: group::code review
product_category: code_review
value_type: number
status: implemented
milestone: "14.3"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67525
time_frame: 7d
data_source: redis_hll
instrumentation_class: RedisHLLMetric
options:
events:
- i_code_review_total_suggestions_added
data_category: Optional
performance_indicator_type: []
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
---
key_path: redis_hll_counters.code_review.i_code_review_total_suggestions_applied_weekly
name: "count_notes_with_applied_suggestions_weekly"
description: Total number of weekly suggestions applied
product_section: dev
product_stage: create
product_group: group::code review
product_category: code_review
value_type: number
status: implemented
milestone: "14.3"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67525
time_frame: 7d
data_source: redis_hll
instrumentation_class: RedisHLLMetric
options:
events:
- i_code_review_total_suggestions_applied
data_category: Optional
performance_indicator_type: []
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
......@@ -237,3 +237,11 @@
category: code_review
aggregation: weekly
feature_flag: diff_searching_usage_data
- name: i_code_review_total_suggestions_applied
redis_slot: code_review
category: code_review
aggregation: weekly
- name: i_code_review_total_suggestions_added
redis_slot: code_review
category: code_review
aggregation: weekly
......@@ -20,8 +20,10 @@ module Gitlab
MR_CREATE_MULTILINE_COMMENT_ACTION = 'i_code_review_user_create_multiline_mr_comment'
MR_EDIT_MULTILINE_COMMENT_ACTION = 'i_code_review_user_edit_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_APPLY_SUGGESTION_ACTION = 'i_code_review_user_apply_suggestion'
MR_USER_ADD_SUGGESTION_ACTION = 'i_code_review_user_add_suggestion'
MR_TOTAL_ADD_SUGGESTION_ACTION = 'i_code_review_total_suggestions_added'
MR_USER_APPLY_SUGGESTION_ACTION = 'i_code_review_user_apply_suggestion'
MR_TOTAL_APPLY_SUGGESTION_ACTION = 'i_code_review_total_suggestions_applied'
MR_MARKED_AS_DRAFT_ACTION = 'i_code_review_user_marked_as_draft'
MR_UNMARKED_AS_DRAFT_ACTION = 'i_code_review_user_unmarked_as_draft'
MR_RESOLVE_THREAD_ACTION = 'i_code_review_user_resolve_thread'
......@@ -112,8 +114,9 @@ module Gitlab
track_unique_action_by_user(MR_PUBLISH_REVIEW_ACTION, user)
end
def track_add_suggestion_action(user:)
track_unique_action_by_user(MR_ADD_SUGGESTION_ACTION, user)
def track_add_suggestion_action(note:)
track_unique_action_by_user(MR_USER_ADD_SUGGESTION_ACTION, note.author)
track_unique_action_by_objects(MR_TOTAL_ADD_SUGGESTION_ACTION, note.suggestions)
end
def track_marked_as_draft_action(user:)
......@@ -124,16 +127,17 @@ module Gitlab
track_unique_action_by_user(MR_UNMARKED_AS_DRAFT_ACTION, user)
end
def track_apply_suggestion_action(user:)
track_unique_action_by_user(MR_APPLY_SUGGESTION_ACTION, user)
def track_apply_suggestion_action(user:, suggestions:)
track_unique_action_by_user(MR_USER_APPLY_SUGGESTION_ACTION, user)
track_unique_action_by_objects(MR_TOTAL_APPLY_SUGGESTION_ACTION, suggestions)
end
def track_users_assigned_to_mr(users:)
track_unique_action_by_users(MR_ASSIGNED_USERS_ACTION, users)
track_unique_action_by_objects(MR_ASSIGNED_USERS_ACTION, users)
end
def track_users_review_requested(users:)
track_unique_action_by_users(MR_REVIEW_REQUESTED_USERS_ACTION, users)
track_unique_action_by_objects(MR_REVIEW_REQUESTED_USERS_ACTION, users)
end
def track_title_edit_action(user:)
......@@ -222,10 +226,10 @@ module Gitlab
track_unique_action(action, user.id)
end
def track_unique_action_by_users(action, users)
return if users.blank?
def track_unique_action_by_objects(action, objects)
return if objects.blank?
track_unique_action(action, users.map(&:id))
track_unique_action(action, objects.map(&:id))
end
def track_unique_action(action, value)
......
......@@ -15,7 +15,7 @@ RSpec.describe 'Code review events' do
code_review_events = Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category("code_review")
exceptions = %w[i_code_review_mr_diffs i_code_review_mr_single_file_diffs]
exceptions = %w[i_code_review_mr_diffs i_code_review_mr_single_file_diffs i_code_review_total_suggestions_applied i_code_review_total_suggestions_added]
code_review_aggregated_events += exceptions
expect(code_review_events - code_review_aggregated_events).to be_empty
......
......@@ -206,18 +206,32 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl
end
describe '.track_add_suggestion_action' do
subject { described_class.track_add_suggestion_action(user: user) }
subject { described_class.track_add_suggestion_action(note: note) }
before do
note.suggestions << build(:suggestion, id: 1, note: note)
end
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_USER_ADD_SUGGESTION_ACTION }
end
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_ADD_SUGGESTION_ACTION }
let(:action) { described_class::MR_TOTAL_ADD_SUGGESTION_ACTION }
end
end
describe '.track_apply_suggestion_action' do
subject { described_class.track_apply_suggestion_action(user: user) }
subject { described_class.track_apply_suggestion_action(user: user, suggestions: suggestions) }
let(:suggestions) { [build(:suggestion, id: 1, note: note)] }
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_USER_APPLY_SUGGESTION_ACTION }
end
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_APPLY_SUGGESTION_ACTION }
let(:action) { described_class::MR_TOTAL_APPLY_SUGGESTION_ACTION }
end
end
......
......@@ -79,7 +79,7 @@ RSpec.describe Suggestions::ApplyService do
it 'tracks apply suggestion event' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_apply_suggestion_action)
.with(user: user)
.with(user: user, suggestions: suggestions)
apply(suggestions)
end
......
......@@ -159,7 +159,7 @@ RSpec.describe Suggestions::CreateService do
it 'tracks add suggestion event' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_add_suggestion_action)
.with(user: note.author)
.with(note: note)
subject.execute
end
......
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