Commit e6969c07 authored by Furkan Ayhan's avatar Furkan Ayhan Committed by Kerri Miller

Implement tracking number of unique users pushing MRs for CI config

When a user pushes changes including the CI config, we track it
using RedisHLL.
Event name: o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile
Feature flag:
usage_data_o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile
parent a0a90afc
......@@ -1863,6 +1863,12 @@ class MergeRequest < ApplicationRecord
}
end
def includes_ci_config?
return false unless diff_stats
diff_stats.map(&:path).include?(project.ci_config_path_or_default)
end
private
def missing_report_error(report_type)
......
......@@ -4,7 +4,10 @@ module MergeRequests
class AfterCreateService < MergeRequests::BaseService
def execute(merge_request)
event_service.open_mr(merge_request, current_user)
merge_request_activity_counter.track_create_mr_action(user: current_user)
merge_request_activity_counter.track_mr_including_ci_config(user: current_user, merge_request: merge_request)
notification_service.new_merge_request(merge_request, current_user)
create_pipeline_for(merge_request, current_user)
......
......@@ -44,6 +44,7 @@ module MergeRequests
notify_about_push(mr)
mark_mr_as_draft_from_commits(mr)
execute_mr_web_hooks(mr)
merge_request_activity_counter.track_mr_including_ci_config(user: mr.author, merge_request: mr)
end
true
......
---
name: usage_data_o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/54707
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/322166
milestone: '13.10'
type: development
group: group::pipeline authoring
default_enabled: false
---
key_path: redis_hll_counters.pipeline_authoring.o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile_monthly
description: Monthly unique user count having merge requests which contains the CI config file
product_section: ops
product_stage: verify
product_group: group::pipeline authoring
product_category: pipeline_authoring
value_type: number
status: implemented
milestone: "13.10"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/54707
time_frame: 28d
data_source: redis_hll
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
---
key_path: redis_hll_counters.pipeline_authoring.o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile_weekly
description: Weekly unique user count having merge requests which contains the CI config file
product_section: ops
product_stage: verify
product_group: group::pipeline authoring
product_category: pipeline_authoring
value_type: number
status: implemented
milestone: "13.10"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/54707
time_frame: 7d
data_source: redis_hll
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
......@@ -10796,6 +10796,30 @@ Status: `data_available`
Tiers:
### `redis_hll_counters.pipeline_authoring.o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile_monthly`
Monthly unique user count having merge requests which contains the CI config file
[YAML definition](https://gitlab.com/gitlab-org/gitlab/-/blob/master/config/metrics/counts_28d/20210301144228_o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile_monthly.yml)
Group: `group::pipeline authoring`
Status: `implemented`
Tiers: `free`, `premium`, `ultimate`
### `redis_hll_counters.pipeline_authoring.o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile_weekly`
Weekly unique user count having merge requests which contains the CI config file
[YAML definition](https://gitlab.com/gitlab-org/gitlab/-/blob/master/config/metrics/counts_7d/20210301144209_o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile_weekly.yml)
Group: `group::pipeline authoring`
Status: `implemented`
Tiers: `free`, `premium`, `ultimate`
### `redis_hll_counters.quickactions.i_quickactions_approve_monthly`
Missing description
......
......@@ -440,3 +440,8 @@
redis_slot: pipeline_authoring
aggregation: weekly
feature_flag: usage_data_unique_users_committing_ciconfigfile
- name: o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile
category: pipeline_authoring
redis_slot: pipeline_authoring
aggregation: weekly
feature_flag: usage_data_o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile
......@@ -41,6 +41,7 @@ module Gitlab
MR_TIME_SPENT_CHANGED_ACTION = 'i_code_review_user_time_spent_changed'
MR_ASSIGNEES_CHANGED_ACTION = 'i_code_review_user_assignees_changed'
MR_REVIEWERS_CHANGED_ACTION = 'i_code_review_user_reviewers_changed'
MR_INCLUDING_CI_CONFIG_ACTION = 'o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile'
class << self
def track_mr_diffs_action(merge_request:)
......@@ -183,6 +184,13 @@ module Gitlab
track_unique_action_by_user(MR_REVIEWERS_CHANGED_ACTION, user)
end
def track_mr_including_ci_config(user:, merge_request:)
return unless Feature.enabled?(:usage_data_o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile, user, default_enabled: :yaml)
return unless merge_request.includes_ci_config?
track_unique_action_by_user(MR_INCLUDING_CI_CONFIG_ACTION, user)
end
private
def track_unique_action_by_merge_request(action, merge_request)
......
......@@ -21,6 +21,14 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl
end
end
shared_examples_for 'not tracked merge request unique event' do
specify do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event)
subject
end
end
describe '.track_mr_diffs_action' do
subject { described_class.track_mr_diffs_action(merge_request: merge_request) }
......@@ -332,4 +340,34 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl
let(:action) { described_class::MR_REVIEWERS_CHANGED_ACTION }
end
end
describe '.track_mr_including_ci_config' do
subject { described_class.track_mr_including_ci_config(user: user, merge_request: merge_request) }
context 'when merge request includes a ci config change' do
before do
allow(merge_request).to receive(:diff_stats).and_return([double(path: 'abc.txt'), double(path: '.gitlab-ci.yml')])
end
it_behaves_like 'a tracked merge request unique event' do
let(:action) { described_class::MR_INCLUDING_CI_CONFIG_ACTION }
end
context 'when FF usage_data_o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile is disabled' do
before do
stub_feature_flags(usage_data_o_pipeline_authoring_unique_users_pushing_mr_ciconfigfile: false)
end
it_behaves_like 'not tracked merge request unique event'
end
end
context 'when merge request does not include any ci config change' do
before do
allow(merge_request).to receive(:diff_stats).and_return([double(path: 'abc.txt'), double(path: 'abc.xyz')])
end
it_behaves_like 'not tracked merge request unique event'
end
end
end
......@@ -1353,7 +1353,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
let(:categories) { ::Gitlab::UsageDataCounters::HLLRedisCounter.categories }
let(:ineligible_total_categories) do
%w[source_code ci_secrets_management incident_management_alerts snippets terraform pipeline_authoring]
%w[source_code ci_secrets_management incident_management_alerts snippets terraform]
end
it 'has all known_events' do
......
......@@ -4856,4 +4856,33 @@ RSpec.describe MergeRequest, factory_default: :keep do
end
end
end
describe '#includes_ci_config?' do
let(:merge_request) { build(:merge_request) }
let(:project) { merge_request.project }
subject(:result) { merge_request.includes_ci_config? }
before do
allow(merge_request).to receive(:diff_stats).and_return(diff_stats)
end
context 'when diff_stats is nil' do
let(:diff_stats) {}
it { is_expected.to eq(false) }
end
context 'when diff_stats does not include the ci config path of the project' do
let(:diff_stats) { [double(path: 'abc.txt')] }
it { is_expected.to eq(false) }
end
context 'when diff_stats includes the ci config path of the project' do
let(:diff_stats) { [double(path: '.gitlab-ci.yml')] }
it { is_expected.to eq(true) }
end
end
end
......@@ -32,6 +32,10 @@ RSpec.describe MergeRequests::AfterCreateService do
.to receive(:track_create_mr_action)
.with(user: merge_request.author)
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_mr_including_ci_config)
.with(user: merge_request.author, merge_request: merge_request)
execute_service
end
......
......@@ -170,6 +170,18 @@ RSpec.describe MergeRequests::RefreshService do
.not_to change { @merge_request.reload.merge_request_diff }
end
end
it 'calls the merge request activity counter' do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_mr_including_ci_config)
.with(user: @merge_request.author, merge_request: @merge_request)
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_mr_including_ci_config)
.with(user: @another_merge_request.author, merge_request: @another_merge_request)
refresh_service.execute(@oldrev, @newrev, 'refs/heads/master')
end
end
context 'when pipeline exists for the source branch' do
......
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