diff --git a/lib/gitlab/usage_data_counters/ci_template_unique_counter.rb b/lib/gitlab/usage_data_counters/ci_template_unique_counter.rb index e0a4f879f487435d768ac486b0aadb1d7a79a721..b8a964be59a68b315159914304a1d45fe2d9dbd2 100644 --- a/lib/gitlab/usage_data_counters/ci_template_unique_counter.rb +++ b/lib/gitlab/usage_data_counters/ci_template_unique_counter.rb @@ -30,21 +30,6 @@ def expand_template_name(template_name) Gitlab::Template::GitlabCiYmlTemplate.find(template_name.chomp('.gitlab-ci.yml'))&.full_name end - def all_included_templates(template_name) - expanded_template_name = expand_template_name(template_name) - results = [expanded_template_name].tap do |result| - template = Gitlab::Template::GitlabCiYmlTemplate.find(template_name.chomp('.gitlab-ci.yml')) - data = Gitlab::Ci::Config::Yaml::Loader.new(template.content).load.content - [data[:include]].compact.flatten.each do |ci_include| - if ci_include_template = ci_include[:template] - result.concat(all_included_templates(ci_include_template)) - end - end - end - - results.uniq.sort_by { _1['name'] } - end - private def template_to_event_name(template) diff --git a/lib/tasks/gitlab/usage_data.rake b/lib/tasks/gitlab/usage_data.rake index 1cd72ee6a1be1d581f91258a7e3493302b4cf83a..09db25735d7a6a5fb6884e81642ebddf4575d7ec 100644 --- a/lib/tasks/gitlab/usage_data.rake +++ b/lib/tasks/gitlab/usage_data.rake @@ -48,39 +48,5 @@ namespace :gitlab do FileUtils.mkdir_p(path) File.write(File.join(path, 'sql_metrics_queries.json'), Gitlab::Json.pretty_generate(queries)) end - - # Events for templates included via YAML-less Auto-DevOps - def implicit_auto_devops_includes - Gitlab::UsageDataCounters::CiTemplateUniqueCounter - .all_included_templates('Auto-DevOps.gitlab-ci.yml') - .map { |template| implicit_auto_devops_event(template) } - .uniq - .sort_by { _1['name'] } - end - - # Events for templates included in a .gitlab-ci.yml using include:template - def explicit_template_includes - Gitlab::UsageDataCounters::CiTemplateUniqueCounter.ci_templates("lib/gitlab/ci/templates/").each_with_object([]) do |template, result| - expanded_template_name = Gitlab::UsageDataCounters::CiTemplateUniqueCounter.expand_template_name(template) - next unless expanded_template_name # guard against templates unavailable on FOSS - - event_name = Gitlab::UsageDataCounters::CiTemplateUniqueCounter.ci_template_event_name(expanded_template_name, :repository_source) - - result << ci_template_event(event_name) - end - end - - # rubocop:disable Gitlab/NoCodeCoverageComment - # :nocov: remove in https://gitlab.com/gitlab-org/gitlab/-/issues/299453 - def ci_template_event(event_name) - { 'name' => event_name } - end - # :nocov: - # rubocop:enable Gitlab/NoCodeCoverageComment - - def implicit_auto_devops_event(expanded_template_name) - event_name = Gitlab::UsageDataCounters::CiTemplateUniqueCounter.ci_template_event_name(expanded_template_name, :auto_devops_source) - ci_template_event(event_name) - end end end diff --git a/spec/lib/gitlab/usage_data_counters/ci_template_unique_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/ci_template_unique_counter_spec.rb index 2c9506dd498ea79d79bdc0aea5296af551eb353b..05938fa08cdf272e19569aa3b3460776daa2431d 100644 --- a/spec/lib/gitlab/usage_data_counters/ci_template_unique_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/ci_template_unique_counter_spec.rb @@ -50,18 +50,6 @@ end end - context 'with implicit includes', :snowplow do - let(:config_source) { :auto_devops_source } - - described_class.all_included_templates('Auto-DevOps.gitlab-ci.yml').each do |template_name| - context "for #{template_name}" do - let(:template_path) { Gitlab::Template::GitlabCiYmlTemplate.find(template_name.delete_suffix('.gitlab-ci.yml')).full_name } - - include_examples 'tracks template' - end - end - end - it 'expands short template names' do expect do described_class.track_unique_project_event(project: project, template: 'Dependency-Scanning.gitlab-ci.yml', config_source: :repository_source, user: user)