Commit 258d2f2e authored by Matija Čupić's avatar Matija Čupić

Track all CI template inclusions

Changelog: other
parent c6e9a0f8
---
name: track_all_ci_template_inclusions
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/69204
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/339684
milestone: '14.3'
type: development
group: group::pipeline authoring
default_enabled: false
...@@ -28,12 +28,24 @@ module Gitlab::UsageDataCounters ...@@ -28,12 +28,24 @@ module Gitlab::UsageDataCounters
private private
def unique_project_event(template, config_source) def unique_project_event(template, config_source)
if name = TEMPLATE_TO_EVENT[template] if TEMPLATE_TO_EVENT[template]
prefix = 'implicit_' if config_source.to_s == 'auto_devops_source' template_inclusion_name(config_source, TEMPLATE_TO_EVENT[template])
end
"p_#{REDIS_SLOT}_#{prefix}#{name}" if Feature.enabled?(:track_all_ci_template_inclusions)
template_inclusion_name(config_source, template_to_event(template))
end end
end end
def template_inclusion_name(config_source, name)
prefix = 'implicit_' if config_source.to_s == 'auto_devops_source'
"p_#{REDIS_SLOT}_#{prefix}#{name}"
end
def template_to_event(template)
File.basename(template, '.gitlab-ci.yml').underscore
end
end end
end end
end end
...@@ -77,13 +77,37 @@ RSpec.describe Gitlab::UsageDataCounters::CiTemplateUniqueCounter do ...@@ -77,13 +77,37 @@ RSpec.describe Gitlab::UsageDataCounters::CiTemplateUniqueCounter do
let(:project_id) { 1 } let(:project_id) { 1 }
let(:config_source) { :repository_source } let(:config_source) { :repository_source }
Dir.glob(File.join('lib', 'gitlab', 'ci', 'templates', '**'), base: Rails.root) do |template| Dir.glob('**/*.gitlab-ci.yml', base: Rails.root.join('lib/gitlab/ci/templates')) do |template|
next if described_class::TEMPLATE_TO_EVENT.key?(template) next if described_class::TEMPLATE_TO_EVENT.key?(template)
it "does not track #{template}" do it 'has an event defined' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to(receive(:track_event)) expect do
described_class.track_unique_project_event(project_id: project_id, template: described_class.send(:template_to_event, template), config_source: config_source)
end.not_to raise_error
end
described_class.track_unique_project_event(project_id: project_id, template: template, config_source: config_source) context 'when feature flag is disabled' do
before do
stub_feature_flags(track_all_ci_template_inclusions: false)
end
it "does not track #{template}" do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to(receive(:track_event))
described_class.track_unique_project_event(project_id: project_id, template: template, config_source: config_source)
end
end
context 'when feature flag is enabled' do
before do
stub_feature_flags(track_all_ci_template_inclusions: true)
end
it "tracks #{template}" do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).to(receive(:track_event)).with("p_ci_templates_#{File.basename(template, '.gitlab-ci.yml').underscore}", values: project_id)
described_class.track_unique_project_event(project_id: project_id, template: template, config_source: config_source)
end
end end
end end
end 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