From 970a032d32b79839753dc06991782aa8d8148b4a Mon Sep 17 00:00:00 2001 From: Eduardo Bonet Date: Tue, 3 May 2022 16:23:17 +0200 Subject: [PATCH 1/6] Adds tracking for Ipynb notes Tracks notes left on Ipynb notes either for commits or mrs --- app/services/notes/create_service.rb | 5 + config/metrics/aggregates/code_review.yml | 12 ++ ...unt_notes_in_ipynb_diff_commit_monthly.yml | 27 +++++ ...0641_count_notes_in_ipynb_diff_monthly.yml | 27 +++++ ...1_count_notes_in_ipynb_diff_mr_monthly.yml | 27 +++++ ...ith_notes_in_ipynb_diff_commit_monthly.yml | 27 +++++ ...users_with_notes_in_ipynb_diff_monthly.yml | 27 +++++ ...rs_with_notes_in_ipynb_diff_mr_monthly.yml | 27 +++++ ...0641_ipynb_diff_mr_notes_count_monthly.yml | 27 +++++ ...with_ipynb_diff_mr_notes_count_monthly.yml | 27 +++++ ...ount_notes_in_ipynb_diff_commit_weekly.yml | 27 +++++ ...41_count_notes_in_ipynb_diff_mr_weekly.yml | 27 +++++ ...50641_count_notes_in_ipynb_diff_weekly.yml | 27 +++++ ...with_notes_in_ipynb_diff_commit_weekly.yml | 27 +++++ ...ers_with_notes_in_ipynb_diff_mr_weekly.yml | 27 +++++ ..._users_with_notes_in_ipynb_diff_weekly.yml | 27 +++++ lib/gitlab/diff/file.rb | 8 +- .../ipynb_diff_activity_counter.rb | 37 ++++++ .../known_events/code_review_events.yml | 24 ++++ .../ipynb_diff_activity_counter_spec.rb | 107 ++++++++++++++++++ 20 files changed, 567 insertions(+), 4 deletions(-) create mode 100644 ee/config/metrics/counts_28d/20220504150641_count_notes_in_ipynb_diff_commit_monthly.yml create mode 100644 ee/config/metrics/counts_28d/20220504150641_count_notes_in_ipynb_diff_monthly.yml create mode 100644 ee/config/metrics/counts_28d/20220504150641_count_notes_in_ipynb_diff_mr_monthly.yml create mode 100644 ee/config/metrics/counts_28d/20220504150641_count_users_with_notes_in_ipynb_diff_commit_monthly.yml create mode 100644 ee/config/metrics/counts_28d/20220504150641_count_users_with_notes_in_ipynb_diff_monthly.yml create mode 100644 ee/config/metrics/counts_28d/20220504150641_count_users_with_notes_in_ipynb_diff_mr_monthly.yml create mode 100644 ee/config/metrics/counts_28d/20220504150641_ipynb_diff_mr_notes_count_monthly.yml create mode 100644 ee/config/metrics/counts_28d/20220504150641_users_with_ipynb_diff_mr_notes_count_monthly.yml create mode 100644 ee/config/metrics/counts_7d/20220504150641_count_notes_in_ipynb_diff_commit_weekly.yml create mode 100644 ee/config/metrics/counts_7d/20220504150641_count_notes_in_ipynb_diff_mr_weekly.yml create mode 100644 ee/config/metrics/counts_7d/20220504150641_count_notes_in_ipynb_diff_weekly.yml create mode 100644 ee/config/metrics/counts_7d/20220504150641_count_users_with_notes_in_ipynb_diff_commit_weekly.yml create mode 100644 ee/config/metrics/counts_7d/20220504150641_count_users_with_notes_in_ipynb_diff_mr_weekly.yml create mode 100644 ee/config/metrics/counts_7d/20220504150641_count_users_with_notes_in_ipynb_diff_weekly.yml create mode 100644 lib/gitlab/usage_data_counters/ipynb_diff_activity_counter.rb create mode 100644 spec/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter_spec.rb diff --git a/app/services/notes/create_service.rb b/app/services/notes/create_service.rb index d32d1c8ca126d3..f122e016c7dff4 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 note.respond_to?(:diff_file) && note.diff_file&.ipynb? if Feature.enabled?(:notes_create_service_tracking, project) Gitlab::Tracking.event('Notes::CreateService', 'execute', **tracking_data_for(note)) @@ -134,6 +135,10 @@ 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 track_note_creation_in_ipynb(note) + Gitlab::UsageDataCounters::IpynbDiffActivityCounter.track_note_created_in_ipynb_diff(note) + end end end diff --git a/config/metrics/aggregates/code_review.yml b/config/metrics/aggregates/code_review.yml index 004f155864e7bb..a25222b8d6bbf2 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 00000000000000..9df4840d82e495 --- /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: implemented +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 \ No newline at end of file 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 00000000000000..a21258076f35a0 --- /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: implemented +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 \ No newline at end of file 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 00000000000000..ef2c41ce15d408 --- /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: implemented +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 \ No newline at end of file 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 00000000000000..24086ce6300b49 --- /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: implemented +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 \ No newline at end of file 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 00000000000000..a3a058f911fc29 --- /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: implemented +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 \ No newline at end of file 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 00000000000000..a37f2d566fc868 --- /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: implemented +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 \ No newline at end of file diff --git a/ee/config/metrics/counts_28d/20220504150641_ipynb_diff_mr_notes_count_monthly.yml b/ee/config/metrics/counts_28d/20220504150641_ipynb_diff_mr_notes_count_monthly.yml new file mode 100644 index 00000000000000..e1e61cb9e8931b --- /dev/null +++ b/ee/config/metrics/counts_28d/20220504150641_ipynb_diff_mr_notes_count_monthly.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.code_review.i_code_review_ipynb_diff_mr_notes_count_monthly +name: "count_notes_on_ipynb_mr_monthly" +description: Monthly total of notes left on ipynb MRs +product_section: dev +product_stage: create +product_group: group::code review +product_category: code_review +value_type: number +status: implemented +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_ipynb_diff_mr_note_count +data_category: Optional +performance_indicator_type: [] +distribution: + - ce + - ee +tier: + - free + - premium + - ultimate diff --git a/ee/config/metrics/counts_28d/20220504150641_users_with_ipynb_diff_mr_notes_count_monthly.yml b/ee/config/metrics/counts_28d/20220504150641_users_with_ipynb_diff_mr_notes_count_monthly.yml new file mode 100644 index 00000000000000..b77d8732c432bc --- /dev/null +++ b/ee/config/metrics/counts_28d/20220504150641_users_with_ipynb_diff_mr_notes_count_monthly.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.code_review.i_code_review_users_with_ipynb_diff_mr_notes_count_monthly +name: "count_users_with_notes_on_ipynb_mr_monthly" +description: Monthly total of users that left notes on ipynb MRs +product_section: dev +product_stage: create +product_group: group::code review +product_category: code_review +value_type: number +status: implemented +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_ipynb_diff_mr_note_count +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 00000000000000..979a2d3b2c7482 --- /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: implemented +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 \ No newline at end of file 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 00000000000000..40fa398066d177 --- /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: implemented +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 \ No newline at end of file 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 00000000000000..3a43053b68a50f --- /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: implemented +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 \ No newline at end of file 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 00000000000000..05e854ae7767a1 --- /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: implemented +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 \ No newline at end of file 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 00000000000000..1d5e75b81bb47e --- /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: implemented +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 \ No newline at end of file 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 00000000000000..32f64ef2d2fdf7 --- /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: implemented +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 \ No newline at end of file diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index d21cbdf0be01d6..d6ee21b93b6769 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 00000000000000..7bf55756bb78aa --- /dev/null +++ b/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +# noinspection RubyClassMethodNamingConvention +# 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 track_note_created_in_ipynb_diff(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 c91b104a0c24fa..e3bb3f6fef3f8c 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/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 00000000000000..45ee84808d55db --- /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.track_note_created_in_ipynb_diff(first_note) + described_class.track_note_created_in_ipynb_diff(first_note) + described_class.track_note_created_in_ipynb_diff(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 -- GitLab From c2112a31334840bcf3661ec24bd2362887d66d72 Mon Sep 17 00:00:00 2001 From: Eduardo Bonet Date: Wed, 11 May 2022 10:18:26 +0200 Subject: [PATCH 2/6] Adds tests --- spec/services/notes/create_service_spec.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb index b04101236302fa..1b4ab93f119edd 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,21 @@ 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(:track_note_created_in_ipynb_diff) + + described_class.new(project_with_repo, user, new_opts).execute + end + + context 'is ipynb file' do + it 'tracks ipynb diff note creation' do + allow_any_instance_of(::Gitlab::Diff::File).to receive(:ipynb?).and_return(true) + expect(::Gitlab::UsageDataCounters::IpynbDiffActivityCounter).to receive(:track_note_created_in_ipynb_diff) + + described_class.new(project_with_repo, user, new_opts).execute(skip_capture_diff_note_position: true) + end + end end context 'when DiffNote is a reply' do -- GitLab From 24f719f88e2c41c61eded40b24aa4fd43c3b0c33 Mon Sep 17 00:00:00 2001 From: Eduardo Bonet Date: Thu, 12 May 2022 10:54:21 +0200 Subject: [PATCH 3/6] Fixes wrong metric definitions --- ...unt_notes_in_ipynb_diff_commit_monthly.yml | 4 +-- ...0641_count_notes_in_ipynb_diff_monthly.yml | 4 +-- ...1_count_notes_in_ipynb_diff_mr_monthly.yml | 4 +-- ...ith_notes_in_ipynb_diff_commit_monthly.yml | 4 +-- ...users_with_notes_in_ipynb_diff_monthly.yml | 4 +-- ...rs_with_notes_in_ipynb_diff_mr_monthly.yml | 4 +-- ...0641_ipynb_diff_mr_notes_count_monthly.yml | 27 ------------------- ...with_ipynb_diff_mr_notes_count_monthly.yml | 27 ------------------- ...ount_notes_in_ipynb_diff_commit_weekly.yml | 4 +-- ...41_count_notes_in_ipynb_diff_mr_weekly.yml | 4 +-- ...50641_count_notes_in_ipynb_diff_weekly.yml | 4 +-- ...with_notes_in_ipynb_diff_commit_weekly.yml | 4 +-- ...ers_with_notes_in_ipynb_diff_mr_weekly.yml | 4 +-- ..._users_with_notes_in_ipynb_diff_weekly.yml | 4 +-- 14 files changed, 24 insertions(+), 78 deletions(-) delete mode 100644 ee/config/metrics/counts_28d/20220504150641_ipynb_diff_mr_notes_count_monthly.yml delete mode 100644 ee/config/metrics/counts_28d/20220504150641_users_with_ipynb_diff_mr_notes_count_monthly.yml 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 index 9df4840d82e495..1b81498174a573 100644 --- 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 @@ -7,7 +7,7 @@ product_stage: create product_group: group::code review product_category: code_review value_type: number -status: implemented +status: active milestone: "15.0" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 time_frame: 28d @@ -24,4 +24,4 @@ distribution: tier: - free - premium - - ultimate \ No newline at end of file + - 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 index a21258076f35a0..5786eaac2779e6 100644 --- 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 @@ -7,7 +7,7 @@ product_stage: create product_group: group::code review product_category: code_review value_type: number -status: implemented +status: active milestone: "15.0" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 time_frame: 28d @@ -24,4 +24,4 @@ distribution: tier: - free - premium - - ultimate \ No newline at end of file + - 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 index ef2c41ce15d408..c9eb507de97952 100644 --- 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 @@ -7,7 +7,7 @@ product_stage: create product_group: group::code review product_category: code_review value_type: number -status: implemented +status: active milestone: "15.0" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 time_frame: 28d @@ -24,4 +24,4 @@ distribution: tier: - free - premium - - ultimate \ No newline at end of file + - 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 index 24086ce6300b49..bb16aa1bc9d86e 100644 --- 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 @@ -7,7 +7,7 @@ product_stage: create product_group: group::code review product_category: code_review value_type: number -status: implemented +status: active milestone: "15.0" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 time_frame: 28d @@ -24,4 +24,4 @@ distribution: tier: - free - premium - - ultimate \ No newline at end of file + - 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 index a3a058f911fc29..59c45779612628 100644 --- 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 @@ -7,7 +7,7 @@ product_stage: create product_group: group::code review product_category: code_review value_type: number -status: implemented +status: active milestone: "15.0" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 time_frame: 28d @@ -24,4 +24,4 @@ distribution: tier: - free - premium - - ultimate \ No newline at end of file + - 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 index a37f2d566fc868..3b570cc4c24132 100644 --- 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 @@ -7,7 +7,7 @@ product_stage: create product_group: group::code review product_category: code_review value_type: number -status: implemented +status: active milestone: "15.0" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 time_frame: 28d @@ -24,4 +24,4 @@ distribution: tier: - free - premium - - ultimate \ No newline at end of file + - ultimate diff --git a/ee/config/metrics/counts_28d/20220504150641_ipynb_diff_mr_notes_count_monthly.yml b/ee/config/metrics/counts_28d/20220504150641_ipynb_diff_mr_notes_count_monthly.yml deleted file mode 100644 index e1e61cb9e8931b..00000000000000 --- a/ee/config/metrics/counts_28d/20220504150641_ipynb_diff_mr_notes_count_monthly.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -key_path: redis_hll_counters.code_review.i_code_review_ipynb_diff_mr_notes_count_monthly -name: "count_notes_on_ipynb_mr_monthly" -description: Monthly total of notes left on ipynb MRs -product_section: dev -product_stage: create -product_group: group::code review -product_category: code_review -value_type: number -status: implemented -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_ipynb_diff_mr_note_count -data_category: Optional -performance_indicator_type: [] -distribution: - - ce - - ee -tier: - - free - - premium - - ultimate diff --git a/ee/config/metrics/counts_28d/20220504150641_users_with_ipynb_diff_mr_notes_count_monthly.yml b/ee/config/metrics/counts_28d/20220504150641_users_with_ipynb_diff_mr_notes_count_monthly.yml deleted file mode 100644 index b77d8732c432bc..00000000000000 --- a/ee/config/metrics/counts_28d/20220504150641_users_with_ipynb_diff_mr_notes_count_monthly.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -key_path: redis_hll_counters.code_review.i_code_review_users_with_ipynb_diff_mr_notes_count_monthly -name: "count_users_with_notes_on_ipynb_mr_monthly" -description: Monthly total of users that left notes on ipynb MRs -product_section: dev -product_stage: create -product_group: group::code review -product_category: code_review -value_type: number -status: implemented -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_ipynb_diff_mr_note_count -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 index 979a2d3b2c7482..a0536294d521a5 100644 --- 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 @@ -7,7 +7,7 @@ product_stage: create product_group: group::code review product_category: code_review value_type: number -status: implemented +status: active milestone: "15.0" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 time_frame: 7d @@ -24,4 +24,4 @@ distribution: tier: - free - premium - - ultimate \ No newline at end of file + - 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 index 40fa398066d177..4057ca378ad2b3 100644 --- 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 @@ -7,7 +7,7 @@ product_stage: create product_group: group::code review product_category: code_review value_type: number -status: implemented +status: active milestone: "15.0" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 time_frame: 7d @@ -24,4 +24,4 @@ distribution: tier: - free - premium - - ultimate \ No newline at end of file + - 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 index 3a43053b68a50f..3eda9840ec6853 100644 --- 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 @@ -7,7 +7,7 @@ product_stage: create product_group: group::code review product_category: code_review value_type: number -status: implemented +status: active milestone: "15.0" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 time_frame: 7d @@ -24,4 +24,4 @@ distribution: tier: - free - premium - - ultimate \ No newline at end of file + - 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 index 05e854ae7767a1..f3374a22239c02 100644 --- 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 @@ -7,7 +7,7 @@ product_stage: create product_group: group::code review product_category: code_review value_type: number -status: implemented +status: active milestone: "15.0" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 time_frame: 7d @@ -24,4 +24,4 @@ distribution: tier: - free - premium - - ultimate \ No newline at end of file + - 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 index 1d5e75b81bb47e..280da75f953b20 100644 --- 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 @@ -7,7 +7,7 @@ product_stage: create product_group: group::code review product_category: code_review value_type: number -status: implemented +status: active milestone: "15.0" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 time_frame: 7d @@ -24,4 +24,4 @@ distribution: tier: - free - premium - - ultimate \ No newline at end of file + - 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 index 32f64ef2d2fdf7..5b94b9aa040364 100644 --- 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 @@ -7,7 +7,7 @@ product_stage: create product_group: group::code review product_category: code_review value_type: number -status: implemented +status: active milestone: "15.0" introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85398 time_frame: 7d @@ -24,4 +24,4 @@ distribution: tier: - free - premium - - ultimate \ No newline at end of file + - ultimate -- GitLab From 1aa1ea32f339d17089b7aea839bd2b5b0d0a40ff Mon Sep 17 00:00:00 2001 From: Eduardo Bonet Date: Thu, 12 May 2022 11:00:42 +0200 Subject: [PATCH 4/6] Renames method to remove noinspection --- app/services/notes/create_service.rb | 2 +- .../usage_data_counters/ipynb_diff_activity_counter.rb | 5 ++--- .../usage_data_counters/ipynb_diff_activity_counter_spec.rb | 6 +++--- spec/services/notes/create_service_spec.rb | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/services/notes/create_service.rb b/app/services/notes/create_service.rb index f122e016c7dff4..20dd7ad4c63819 100644 --- a/app/services/notes/create_service.rb +++ b/app/services/notes/create_service.rb @@ -137,7 +137,7 @@ def track_note_creation_usage_for_merge_requests(note) end def track_note_creation_in_ipynb(note) - Gitlab::UsageDataCounters::IpynbDiffActivityCounter.track_note_created_in_ipynb_diff(note) + Gitlab::UsageDataCounters::IpynbDiffActivityCounter.note_created(note) end end end diff --git a/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter.rb b/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter.rb index 7bf55756bb78aa..a34ae909c826a6 100644 --- a/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter.rb +++ b/lib/gitlab/usage_data_counters/ipynb_diff_activity_counter.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -# noinspection RubyClassMethodNamingConvention # noinspection RubyConstantNamingConvention module Gitlab module UsageDataCounters @@ -13,7 +12,7 @@ module IpynbDiffActivityCounter USER_CREATED_NOTE_IN_IPYNB_DIFF_COMMIT_ACTION = 'i_code_review_user_create_note_in_ipynb_diff_commit' class << self - def track_note_created_in_ipynb_diff(note) + def note_created(note) return unless note.for_merge_request? || note.for_commit? if note.for_merge_request? @@ -29,7 +28,7 @@ def track_note_created_in_ipynb_diff(note) 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) + Gitlab::UsageDataCounters::HLLRedisCounter.track_usage_event(per_user_action, note.author_id) end end end 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 index 45ee84808d55db..60c4424d2ae042 100644 --- 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 @@ -17,9 +17,9 @@ end subject do - described_class.track_note_created_in_ipynb_diff(first_note) - described_class.track_note_created_in_ipynb_diff(first_note) - described_class.track_note_created_in_ipynb_diff(second_note) + 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 diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb index 1b4ab93f119edd..335c2c0ded10d3 100644 --- a/spec/services/notes/create_service_spec.rb +++ b/spec/services/notes/create_service_spec.rb @@ -197,7 +197,7 @@ end it 'does not track ipynb note usage data' do - expect(::Gitlab::UsageDataCounters::IpynbDiffActivityCounter).not_to receive(:track_note_created_in_ipynb_diff) + expect(::Gitlab::UsageDataCounters::IpynbDiffActivityCounter).not_to receive(:note_created) described_class.new(project_with_repo, user, new_opts).execute end @@ -205,7 +205,7 @@ context 'is ipynb file' do it 'tracks ipynb diff note creation' do allow_any_instance_of(::Gitlab::Diff::File).to receive(:ipynb?).and_return(true) - expect(::Gitlab::UsageDataCounters::IpynbDiffActivityCounter).to receive(:track_note_created_in_ipynb_diff) + expect(::Gitlab::UsageDataCounters::IpynbDiffActivityCounter).to receive(:note_created) described_class.new(project_with_repo, user, new_opts).execute(skip_capture_diff_note_position: true) end -- GitLab From 0c76b2c48d57a6f0aab110afa1e4fb82b421451d Mon Sep 17 00:00:00 2001 From: Eduardo Bonet Date: Thu, 12 May 2022 14:32:02 +0200 Subject: [PATCH 5/6] Adds feature flag :ipynbdiff_notes_tracker --- app/services/notes/create_service.rb | 8 ++++++- .../development/ipynbdiff_notes_tracker.yml | 8 +++++++ spec/services/notes/create_service_spec.rb | 24 ++++++++++++++++--- 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 config/feature_flags/development/ipynbdiff_notes_tracker.yml diff --git a/app/services/notes/create_service.rb b/app/services/notes/create_service.rb index 20dd7ad4c63819..c97ed5601699e6 100644 --- a/app/services/notes/create_service.rb +++ b/app/services/notes/create_service.rb @@ -112,7 +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 note.respond_to?(:diff_file) && note.diff_file&.ipynb? + track_note_creation_in_ipynb(note) if Feature.enabled?(:notes_create_service_tracking, project) Gitlab::Tracking.event('Notes::CreateService', 'execute', **tracking_data_for(note)) @@ -136,7 +136,13 @@ 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 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 00000000000000..af471a3f6ee08b --- /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/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb index 335c2c0ded10d3..c72a9465f20f12 100644 --- a/spec/services/notes/create_service_spec.rb +++ b/spec/services/notes/create_service_spec.rb @@ -203,11 +203,29 @@ end context 'is ipynb file' do - it 'tracks ipynb diff note creation' do + before do allow_any_instance_of(::Gitlab::Diff::File).to receive(:ipynb?).and_return(true) - expect(::Gitlab::UsageDataCounters::IpynbDiffActivityCounter).to receive(:note_created) + stub_feature_flags(ipynbdiff_notes_tracker: false) + end - described_class.new(project_with_repo, user, new_opts).execute(skip_capture_diff_note_position: true) + 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 -- GitLab From 6be28c19214427423ff7d1c6fb84e37870fdb6f2 Mon Sep 17 00:00:00 2001 From: Eduardo Bonet Date: Fri, 13 May 2022 09:18:32 +0200 Subject: [PATCH 6/6] Adds tests for ipynb? --- spec/lib/gitlab/diff/file_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb index 0d7a183bb11568..b7262629e0a8eb 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") } -- GitLab