diff --git a/app/services/notes/create_service.rb b/app/services/notes/create_service.rb index d32d1c8ca126d34725743f61a84ff865440df271..c97ed5601699e6c0853a5b9942175bc708251956 100644 --- a/app/services/notes/create_service.rb +++ b/app/services/notes/create_service.rb @@ -112,6 +112,7 @@ def track_event(note, user) track_note_creation_usage_for_issues(note) if note.for_issue? track_note_creation_usage_for_merge_requests(note) if note.for_merge_request? track_incident_action(user, note.noteable, 'incident_comment') if note.for_issue? + track_note_creation_in_ipynb(note) if Feature.enabled?(:notes_create_service_tracking, project) Gitlab::Tracking.event('Notes::CreateService', 'execute', **tracking_data_for(note)) @@ -134,6 +135,16 @@ def track_note_creation_usage_for_issues(note) def track_note_creation_usage_for_merge_requests(note) Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter.track_create_comment_action(note: note) end + + def should_track_ipynb_notes?(note) + Feature.enabled?(:ipynbdiff_notes_tracker) && note.respond_to?(:diff_file) && note.diff_file&.ipynb? + end + + def track_note_creation_in_ipynb(note) + return unless should_track_ipynb_notes?(note) + + Gitlab::UsageDataCounters::IpynbDiffActivityCounter.note_created(note) + end end end diff --git a/config/feature_flags/development/ipynbdiff_notes_tracker.yml b/config/feature_flags/development/ipynbdiff_notes_tracker.yml new file mode 100644 index 0000000000000000000000000000000000000000..af471a3f6ee08b978691c13ad92cefadfeb9057a --- /dev/null +++ b/config/feature_flags/development/ipynbdiff_notes_tracker.yml @@ -0,0 +1,8 @@ +--- +name: ipynbdiff_notes_tracker +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 +rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/362232 +milestone: '15.0' +type: development +group: group::incubation +default_enabled: false diff --git a/config/metrics/aggregates/code_review.yml b/config/metrics/aggregates/code_review.yml index 004f155864e7bb0dade7e09c2db60094056547db..a25222b8d6bbf2e5c1cb85b3e140a6275ede55fb 100644 --- a/config/metrics/aggregates/code_review.yml +++ b/config/metrics/aggregates/code_review.yml @@ -75,6 +75,12 @@ - 'i_code_review_post_merge_submit_cherry_pick_modal' - 'i_code_review_user_jetbrains_api_request' - 'i_code_review_user_gitlab_cli_api_request' + - 'i_code_review_user_create_note_in_ipynb_diff' + - 'i_code_review_user_create_note_in_ipynb_diff_mr' + - 'i_code_review_user_create_note_in_ipynb_diff_commit' + - 'i_code_review_create_note_in_ipynb_diff' + - 'i_code_review_create_note_in_ipynb_diff_mr' + - 'i_code_review_create_note_in_ipynb_diff_commit' - name: code_review_category_monthly_active_users operator: OR source: redis @@ -140,6 +146,12 @@ - 'i_code_review_post_merge_click_cherry_pick' - 'i_code_review_post_merge_submit_revert_modal' - 'i_code_review_post_merge_submit_cherry_pick_modal' + - 'i_code_review_user_create_note_in_ipynb_diff' + - 'i_code_review_user_create_note_in_ipynb_diff_mr' + - 'i_code_review_user_create_note_in_ipynb_diff_commit' + - 'i_code_review_create_note_in_ipynb_diff' + - 'i_code_review_create_note_in_ipynb_diff_mr' + - 'i_code_review_create_note_in_ipynb_diff_commit' - name: code_review_extension_category_monthly_active_users operator: OR source: redis diff --git a/ee/config/metrics/counts_28d/20220504150641_count_notes_in_ipynb_diff_commit_monthly.yml b/ee/config/metrics/counts_28d/20220504150641_count_notes_in_ipynb_diff_commit_monthly.yml new file mode 100644 index 0000000000000000000000000000000000000000..1b81498174a573296f3fbc139e330339ce38f24a --- /dev/null +++ b/ee/config/metrics/counts_28d/20220504150641_count_notes_in_ipynb_diff_commit_monthly.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.code_review.i_code_review_count_notes_in_ipynb_diff_commit_monthly +name: "count_notes_in_ipynb_diff_commit_monthly" +description: Monthly notes on ipynb commit diffs +product_section: dev +product_stage: create +product_group: group::code review +product_category: code_review +value_type: number +status: active +milestone: "15.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 +time_frame: 28d +data_source: redis_hll +instrumentation_class: RedisHLLMetric +options: + events: + - i_code_review_create_note_in_ipynb_diff_commit +data_category: Optional +performance_indicator_type: [] +distribution: + - ce + - ee +tier: + - free + - premium + - ultimate diff --git a/ee/config/metrics/counts_28d/20220504150641_count_notes_in_ipynb_diff_monthly.yml b/ee/config/metrics/counts_28d/20220504150641_count_notes_in_ipynb_diff_monthly.yml new file mode 100644 index 0000000000000000000000000000000000000000..5786eaac2779e6f513256385add12778a5c93c7e --- /dev/null +++ b/ee/config/metrics/counts_28d/20220504150641_count_notes_in_ipynb_diff_monthly.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.code_review.i_code_review_count_notes_in_ipynb_diff_monthly +name: "count_notes_in_ipynb_diff_monthly" +description: Monthly notes on ipynb diffs +product_section: dev +product_stage: create +product_group: group::code review +product_category: code_review +value_type: number +status: active +milestone: "15.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 +time_frame: 28d +data_source: redis_hll +instrumentation_class: RedisHLLMetric +options: + events: + - i_code_review_create_note_in_ipynb_diff +data_category: Optional +performance_indicator_type: [] +distribution: + - ce + - ee +tier: + - free + - premium + - ultimate diff --git a/ee/config/metrics/counts_28d/20220504150641_count_notes_in_ipynb_diff_mr_monthly.yml b/ee/config/metrics/counts_28d/20220504150641_count_notes_in_ipynb_diff_mr_monthly.yml new file mode 100644 index 0000000000000000000000000000000000000000..c9eb507de97952f055df2cf83091c2d43819e8df --- /dev/null +++ b/ee/config/metrics/counts_28d/20220504150641_count_notes_in_ipynb_diff_mr_monthly.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.code_review.i_code_review_count_notes_in_ipynb_diff_mr_monthly +name: "count_notes_in_ipynb_diff_mr_monthly" +description: Monthly notes on ipynb MR diffs +product_section: dev +product_stage: create +product_group: group::code review +product_category: code_review +value_type: number +status: active +milestone: "15.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 +time_frame: 28d +data_source: redis_hll +instrumentation_class: RedisHLLMetric +options: + events: + - i_code_review_create_note_in_ipynb_diff_mr +data_category: Optional +performance_indicator_type: [] +distribution: + - ce + - ee +tier: + - free + - premium + - ultimate diff --git a/ee/config/metrics/counts_28d/20220504150641_count_users_with_notes_in_ipynb_diff_commit_monthly.yml b/ee/config/metrics/counts_28d/20220504150641_count_users_with_notes_in_ipynb_diff_commit_monthly.yml new file mode 100644 index 0000000000000000000000000000000000000000..bb16aa1bc9d86e8082d89042fed9168335b525c1 --- /dev/null +++ b/ee/config/metrics/counts_28d/20220504150641_count_users_with_notes_in_ipynb_diff_commit_monthly.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.code_review.i_code_review_count_users_with_notes_in_ipynb_diff_commit_monthly +name: "count_users_with_notes_in_ipynb_diff_commit_monthly" +description: Monthly unique users with notes on ipynb commit diffs +product_section: dev +product_stage: create +product_group: group::code review +product_category: code_review +value_type: number +status: active +milestone: "15.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 +time_frame: 28d +data_source: redis_hll +instrumentation_class: RedisHLLMetric +options: + events: + - i_code_review_user_create_note_in_ipynb_diff_commit +data_category: Optional +performance_indicator_type: [] +distribution: + - ce + - ee +tier: + - free + - premium + - ultimate diff --git a/ee/config/metrics/counts_28d/20220504150641_count_users_with_notes_in_ipynb_diff_monthly.yml b/ee/config/metrics/counts_28d/20220504150641_count_users_with_notes_in_ipynb_diff_monthly.yml new file mode 100644 index 0000000000000000000000000000000000000000..59c457796126281f451cf61ad2e9a4499bd5aa0d --- /dev/null +++ b/ee/config/metrics/counts_28d/20220504150641_count_users_with_notes_in_ipynb_diff_monthly.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.code_review.i_code_review_count_users_with_notes_in_ipynb_diff_monthly +name: "count_users_with_notes_in_ipynb_diff_monthly" +description: Monthly unique users with notes on ipynb diffs +product_section: dev +product_stage: create +product_group: group::code review +product_category: code_review +value_type: number +status: active +milestone: "15.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 +time_frame: 28d +data_source: redis_hll +instrumentation_class: RedisHLLMetric +options: + events: + - i_code_review_user_create_note_in_ipynb_diff +data_category: Optional +performance_indicator_type: [] +distribution: + - ce + - ee +tier: + - free + - premium + - ultimate diff --git a/ee/config/metrics/counts_28d/20220504150641_count_users_with_notes_in_ipynb_diff_mr_monthly.yml b/ee/config/metrics/counts_28d/20220504150641_count_users_with_notes_in_ipynb_diff_mr_monthly.yml new file mode 100644 index 0000000000000000000000000000000000000000..3b570cc4c2413241f531c70f5edb078ceea9b22b --- /dev/null +++ b/ee/config/metrics/counts_28d/20220504150641_count_users_with_notes_in_ipynb_diff_mr_monthly.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.code_review.i_code_review_count_users_with_notes_in_ipynb_diff_mr_monthly +name: "count_users_with_notes_in_ipynb_diff_mr_monthly" +description: Monthly unique users with notes on ipynb MR diffs +product_section: dev +product_stage: create +product_group: group::code review +product_category: code_review +value_type: number +status: active +milestone: "15.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 +time_frame: 28d +data_source: redis_hll +instrumentation_class: RedisHLLMetric +options: + events: + - i_code_review_user_create_note_in_ipynb_diff_mr +data_category: Optional +performance_indicator_type: [] +distribution: + - ce + - ee +tier: + - free + - premium + - ultimate diff --git a/ee/config/metrics/counts_7d/20220504150641_count_notes_in_ipynb_diff_commit_weekly.yml b/ee/config/metrics/counts_7d/20220504150641_count_notes_in_ipynb_diff_commit_weekly.yml new file mode 100644 index 0000000000000000000000000000000000000000..a0536294d521a5dc816a630b75ee6dea63d7a200 --- /dev/null +++ b/ee/config/metrics/counts_7d/20220504150641_count_notes_in_ipynb_diff_commit_weekly.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.code_review.i_code_review_count_notes_in_ipynb_diff_commit_weekly +name: "count_notes_in_ipynb_diff_commit_weekly" +description: Weekly notes on ipynb commit diffs +product_section: dev +product_stage: create +product_group: group::code review +product_category: code_review +value_type: number +status: active +milestone: "15.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 +time_frame: 7d +data_source: redis_hll +instrumentation_class: RedisHLLMetric +options: + events: + - i_code_review_create_note_in_ipynb_diff_commit +data_category: Optional +performance_indicator_type: [] +distribution: + - ce + - ee +tier: + - free + - premium + - ultimate diff --git a/ee/config/metrics/counts_7d/20220504150641_count_notes_in_ipynb_diff_mr_weekly.yml b/ee/config/metrics/counts_7d/20220504150641_count_notes_in_ipynb_diff_mr_weekly.yml new file mode 100644 index 0000000000000000000000000000000000000000..4057ca378ad2b3548c8fe380ed3c6f5ddb2ca6e4 --- /dev/null +++ b/ee/config/metrics/counts_7d/20220504150641_count_notes_in_ipynb_diff_mr_weekly.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.code_review.i_code_review_count_notes_in_ipynb_diff_mr_weekly +name: "count_notes_in_ipynb_diff_mr_weekly" +description: Weekly notes on ipynb MR diffs +product_section: dev +product_stage: create +product_group: group::code review +product_category: code_review +value_type: number +status: active +milestone: "15.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 +time_frame: 7d +data_source: redis_hll +instrumentation_class: RedisHLLMetric +options: + events: + - i_code_review_create_note_in_ipynb_diff_mr +data_category: Optional +performance_indicator_type: [] +distribution: + - ce + - ee +tier: + - free + - premium + - ultimate diff --git a/ee/config/metrics/counts_7d/20220504150641_count_notes_in_ipynb_diff_weekly.yml b/ee/config/metrics/counts_7d/20220504150641_count_notes_in_ipynb_diff_weekly.yml new file mode 100644 index 0000000000000000000000000000000000000000..3eda9840ec685344739543a62b5fb558f6eb7249 --- /dev/null +++ b/ee/config/metrics/counts_7d/20220504150641_count_notes_in_ipynb_diff_weekly.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.code_review.i_code_review_count_notes_in_ipynb_diff_weekly +name: "count_notes_in_ipynb_diff_weekly" +description: Weekly notes on ipynb diffs +product_section: dev +product_stage: create +product_group: group::code review +product_category: code_review +value_type: number +status: active +milestone: "15.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 +time_frame: 7d +data_source: redis_hll +instrumentation_class: RedisHLLMetric +options: + events: + - i_code_review_create_note_in_ipynb_diff +data_category: Optional +performance_indicator_type: [] +distribution: + - ce + - ee +tier: + - free + - premium + - ultimate diff --git a/ee/config/metrics/counts_7d/20220504150641_count_users_with_notes_in_ipynb_diff_commit_weekly.yml b/ee/config/metrics/counts_7d/20220504150641_count_users_with_notes_in_ipynb_diff_commit_weekly.yml new file mode 100644 index 0000000000000000000000000000000000000000..f3374a22239c02c70db6b13d14e92ee15eb1b90f --- /dev/null +++ b/ee/config/metrics/counts_7d/20220504150641_count_users_with_notes_in_ipynb_diff_commit_weekly.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.code_review.i_code_review_count_users_with_notes_in_ipynb_diff_commit_weekly +name: "count_users_with_notes_in_ipynb_diff_commit_weekly" +description: Weekly unique users with notes on ipynb commit diffs +product_section: dev +product_stage: create +product_group: group::code review +product_category: code_review +value_type: number +status: active +milestone: "15.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 +time_frame: 7d +data_source: redis_hll +instrumentation_class: RedisHLLMetric +options: + events: + - i_code_review_user_create_note_in_ipynb_diff_commit +data_category: Optional +performance_indicator_type: [] +distribution: + - ce + - ee +tier: + - free + - premium + - ultimate diff --git a/ee/config/metrics/counts_7d/20220504150641_count_users_with_notes_in_ipynb_diff_mr_weekly.yml b/ee/config/metrics/counts_7d/20220504150641_count_users_with_notes_in_ipynb_diff_mr_weekly.yml new file mode 100644 index 0000000000000000000000000000000000000000..280da75f953b203a081369e5c26e396383257e34 --- /dev/null +++ b/ee/config/metrics/counts_7d/20220504150641_count_users_with_notes_in_ipynb_diff_mr_weekly.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.code_review.i_code_review_count_users_with_notes_in_ipynb_diff_mr_weekly +name: "count_users_with_notes_in_ipynb_diff_mr_weekly" +description: Weekly unique users with notes on ipynb MR diffs +product_section: dev +product_stage: create +product_group: group::code review +product_category: code_review +value_type: number +status: active +milestone: "15.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 +time_frame: 7d +data_source: redis_hll +instrumentation_class: RedisHLLMetric +options: + events: + - i_code_review_user_create_note_in_ipynb_diff_mr +data_category: Optional +performance_indicator_type: [] +distribution: + - ce + - ee +tier: + - free + - premium + - ultimate diff --git a/ee/config/metrics/counts_7d/20220504150641_count_users_with_notes_in_ipynb_diff_weekly.yml b/ee/config/metrics/counts_7d/20220504150641_count_users_with_notes_in_ipynb_diff_weekly.yml new file mode 100644 index 0000000000000000000000000000000000000000..5b94b9aa0403643a612313897523dd42bd63de35 --- /dev/null +++ b/ee/config/metrics/counts_7d/20220504150641_count_users_with_notes_in_ipynb_diff_weekly.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.code_review.i_code_review_count_users_with_notes_in_ipynb_diff_weekly +name: "count_users_with_notes_in_ipynb_diff_weekly" +description: Weekly unique users with notes on ipynb diffs +product_section: dev +product_stage: create +product_group: group::code review +product_category: code_review +value_type: number +status: active +milestone: "15.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 +time_frame: 7d +data_source: redis_hll +instrumentation_class: RedisHLLMetric +options: + events: + - i_code_review_user_create_note_in_ipynb_diff +data_category: Optional +performance_indicator_type: [] +distribution: + - ce + - ee +tier: + - free + - premium + - ultimate diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index d21cbdf0be01d6b9d1446196c0de383f0534e993..d6ee21b93b6769a6f8f385683244299209cca569 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -386,6 +386,10 @@ def rendered strong_memoize(:rendered) { Rendered::Notebook::DiffFile.new(self) } end + def ipynb? + file_path.ends_with?('.ipynb') + end + private def diffable_by_attribute? @@ -415,10 +419,6 @@ def modified_file? new_file? || deleted_file? || content_changed? end - def ipynb? - file_path.ends_with?('.ipynb') - end - # We can't use Object#try because Blob doesn't inherit from Object, but # from BasicObject (via SimpleDelegator). def try_blobs(meth) diff --git a/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter.rb b/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter.rb new file mode 100644 index 0000000000000000000000000000000000000000..a34ae909c826a693051ed2e353faafcd12c69098 --- /dev/null +++ b/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +# noinspection RubyConstantNamingConvention +module Gitlab + module UsageDataCounters + module IpynbDiffActivityCounter + NOTE_CREATED_IN_IPYNB_DIFF_ACTION = 'i_code_review_create_note_in_ipynb_diff' + USER_CREATED_NOTE_IN_IPYNB_DIFF_ACTION = 'i_code_review_user_create_note_in_ipynb_diff' + NOTE_CREATED_IN_IPYNB_DIFF_MR_ACTION = 'i_code_review_create_note_in_ipynb_diff_mr' + USER_CREATED_NOTE_IN_IPYNB_DIFF_MR_ACTION = 'i_code_review_user_create_note_in_ipynb_diff_mr' + NOTE_CREATED_IN_IPYNB_DIFF_COMMIT_ACTION = 'i_code_review_create_note_in_ipynb_diff_commit' + USER_CREATED_NOTE_IN_IPYNB_DIFF_COMMIT_ACTION = 'i_code_review_user_create_note_in_ipynb_diff_commit' + + class << self + def note_created(note) + return unless note.for_merge_request? || note.for_commit? + + if note.for_merge_request? + track(NOTE_CREATED_IN_IPYNB_DIFF_MR_ACTION, USER_CREATED_NOTE_IN_IPYNB_DIFF_MR_ACTION, note) + else + track(NOTE_CREATED_IN_IPYNB_DIFF_COMMIT_ACTION, USER_CREATED_NOTE_IN_IPYNB_DIFF_COMMIT_ACTION, note) + end + + track(NOTE_CREATED_IN_IPYNB_DIFF_ACTION, USER_CREATED_NOTE_IN_IPYNB_DIFF_ACTION, note) + end + + private + + def track(action, per_user_action, note) + Gitlab::UsageDataCounters::HLLRedisCounter.track_usage_event(action, note.id) + Gitlab::UsageDataCounters::HLLRedisCounter.track_usage_event(per_user_action, note.author_id) + end + end + end + end +end diff --git a/lib/gitlab/usage_data_counters/known_events/code_review_events.yml b/lib/gitlab/usage_data_counters/known_events/code_review_events.yml index c91b104a0c24facd98edf1e8b325ffd0c7c5f027..e3bb3f6fef3f8c810fae786276f75ea89150b643 100644 --- a/lib/gitlab/usage_data_counters/known_events/code_review_events.yml +++ b/lib/gitlab/usage_data_counters/known_events/code_review_events.yml @@ -173,6 +173,30 @@ redis_slot: code_review category: code_review aggregation: weekly +- name: i_code_review_create_note_in_ipynb_diff + redis_slot: code_review + category: code_review + aggregation: weekly +- name: i_code_review_user_create_note_in_ipynb_diff + redis_slot: code_review + category: code_review + aggregation: weekly +- name: i_code_review_create_note_in_ipynb_diff_mr + redis_slot: code_review + category: code_review + aggregation: weekly +- name: i_code_review_user_create_note_in_ipynb_diff_mr + redis_slot: code_review + category: code_review + aggregation: weekly +- name: i_code_review_create_note_in_ipynb_diff_commit + redis_slot: code_review + category: code_review + aggregation: weekly +- name: i_code_review_user_create_note_in_ipynb_diff_commit + redis_slot: code_review + category: code_review + aggregation: weekly # Diff settings events - name: i_code_review_click_diff_view_setting redis_slot: code_review diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb index 0d7a183bb11568e6fb293cc0c38eb71ecafe154c..b7262629e0a8ebe59fa5c45128ab46fe31826a32 100644 --- a/spec/lib/gitlab/diff/file_spec.rb +++ b/spec/lib/gitlab/diff/file_spec.rb @@ -99,6 +99,22 @@ def delete_file(file_name) end end + describe '#ipynb?' do + context 'is ipynb' do + let(:commit) { project.commit("532c837") } + + it 'is true' do + expect(diff_file.ipynb?).to be_truthy + end + end + + context 'is not ipynb' do + it 'is false' do + expect(diff_file.ipynb?).to be_falsey + end + end + end + describe '#has_renderable?' do context 'file is ipynb' do let(:commit) { project.commit("532c837") } diff --git a/spec/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..60c4424d2ae04290c9724625df06ba67379223d7 --- /dev/null +++ b/spec/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter_spec.rb @@ -0,0 +1,107 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::UsageDataCounters::IpynbDiffActivityCounter, :clean_gitlab_redis_shared_state do + let(:user) { build(:user, id: 1) } + let(:for_mr) { false } + let(:for_commit) { false } + let(:first_note) { build(:note, author: user, id: 1) } + let(:second_note) { build(:note, author: user, id: 2) } + + before do + allow(first_note).to receive(:for_merge_request?).and_return(for_mr) + allow(second_note).to receive(:for_merge_request?).and_return(for_mr) + allow(first_note).to receive(:for_commit?).and_return(for_commit) + allow(second_note).to receive(:for_commit?).and_return(for_commit) + end + + subject do + described_class.note_created(first_note) + described_class.note_created(first_note) + described_class.note_created(second_note) + end + + shared_examples_for 'an action that tracks events' do + specify do + expect { 2.times { subject } } + .to change { event_count(action) }.by(2) + .and change { event_count(per_user_action) }.by(1) + end + end + + shared_examples_for 'an action that does not track events' do + specify do + expect { 2.times { subject } } + .to change { event_count(action) }.by(0) + .and change { event_count(per_user_action) }.by(0) + end + end + + describe '#track_note_created_in_ipynb_diff' do + context 'note is for commit' do + let(:for_commit) { true } + + it_behaves_like 'an action that tracks events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_ACTION} + end + + it_behaves_like 'an action that tracks events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_COMMIT_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_COMMIT_ACTION} + end + + it_behaves_like 'an action that does not track events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_MR_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_MR_ACTION} + end + end + + context 'note is for MR' do + let(:for_mr) { true } + + it_behaves_like 'an action that tracks events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_MR_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_MR_ACTION} + end + + it_behaves_like 'an action that tracks events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_ACTION} + end + + it_behaves_like 'an action that does not track events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_COMMIT_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_COMMIT_ACTION} + end + end + + context 'note is for neither MR nor Commit' do + it_behaves_like 'an action that does not track events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_ACTION} + end + + it_behaves_like 'an action that does not track events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_MR_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_MR_ACTION} + end + + it_behaves_like 'an action that does not track events' do + let(:action) {described_class::NOTE_CREATED_IN_IPYNB_DIFF_COMMIT_ACTION} + let(:per_user_action) {described_class::USER_CREATED_NOTE_IN_IPYNB_DIFF_COMMIT_ACTION} + end + end + end + + private + + def event_count(event_name) + Gitlab::UsageDataCounters::HLLRedisCounter.unique_events( + event_names: event_name, + start_date: 2.weeks.ago, + end_date: 2.weeks.from_now + ) + end +end diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb index b04101236302fa045314c0097bb36e4310319c7c..c72a9465f20f127ce6c62f71569c1c56d38fae96 100644 --- a/spec/services/notes/create_service_spec.rb +++ b/spec/services/notes/create_service_spec.rb @@ -168,7 +168,6 @@ before do project_with_repo.add_maintainer(user) end - context 'when eligible to have a note diff file' do let(:new_opts) do opts.merge(in_reply_to_discussion_id: nil, @@ -196,6 +195,39 @@ described_class.new(project_with_repo, user, new_opts).execute(skip_capture_diff_note_position: true) end end + + it 'does not track ipynb note usage data' do + expect(::Gitlab::UsageDataCounters::IpynbDiffActivityCounter).not_to receive(:note_created) + + described_class.new(project_with_repo, user, new_opts).execute + end + + context 'is ipynb file' do + before do + allow_any_instance_of(::Gitlab::Diff::File).to receive(:ipynb?).and_return(true) + stub_feature_flags(ipynbdiff_notes_tracker: false) + end + + context ':ipynbdiff_notes_tracker is off' do + it 'does not track ipynb note usage data' do + expect(::Gitlab::UsageDataCounters::IpynbDiffActivityCounter).not_to receive(:note_created) + + described_class.new(project_with_repo, user, new_opts).execute + end + end + + context ':ipynbdiff_notes_tracker is on' do + before do + stub_feature_flags(ipynbdiff_notes_tracker: true) + end + + it 'tracks ipynb diff note creation' do + expect(::Gitlab::UsageDataCounters::IpynbDiffActivityCounter).to receive(:note_created) + + described_class.new(project_with_repo, user, new_opts).execute + end + end + end end context 'when DiffNote is a reply' do