diff options
Diffstat (limited to 'lib/gitlab/usage_data_counters/ci_template_unique_counter.rb')
-rw-r--r-- | lib/gitlab/usage_data_counters/ci_template_unique_counter.rb | 24 |
1 files changed, 15 insertions, 9 deletions
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 c9106d7c6b8..e5a50c92329 100644 --- a/lib/gitlab/usage_data_counters/ci_template_unique_counter.rb +++ b/lib/gitlab/usage_data_counters/ci_template_unique_counter.rb @@ -3,6 +3,7 @@ module Gitlab::UsageDataCounters class CiTemplateUniqueCounter REDIS_SLOT = 'ci_templates' + KNOWN_EVENTS_FILE_PATH = File.expand_path('known_events/ci_templates.yml', __dir__) # NOTE: Events originating from implicit Auto DevOps pipelines get prefixed with `implicit_` TEMPLATE_TO_EVENT = { @@ -20,19 +21,24 @@ module Gitlab::UsageDataCounters class << self def track_unique_project_event(project_id:, template:, config_source:) - if event = unique_project_event(template, config_source) - Gitlab::UsageDataCounters::HLLRedisCounter.track_event(event, values: project_id) - end + Gitlab::UsageDataCounters::HLLRedisCounter.track_event(ci_template_event_name(template, config_source), values: project_id) end - private + def ci_templates(relative_base = 'lib/gitlab/ci/templates') + Dir.glob('**/*.gitlab-ci.yml', base: Rails.root.join(relative_base)) + end + + def ci_template_event_name(template_name, config_source) + prefix = 'implicit_' if config_source.to_s == 'auto_devops_source' + template_event_name = TEMPLATE_TO_EVENT[template_name] || template_to_event_name(template_name) - def unique_project_event(template, config_source) - if name = TEMPLATE_TO_EVENT[template] - prefix = 'implicit_' if config_source.to_s == 'auto_devops_source' + "p_#{REDIS_SLOT}_#{prefix}#{template_event_name}" + end + + private - "p_#{REDIS_SLOT}_#{prefix}#{name}" - end + def template_to_event_name(template) + ActiveSupport::Inflector.parameterize(template.chomp('.gitlab-ci.yml'), separator: '_').underscore end end end |