Class: Gitlab::UsageDataCounters::CiTemplateUniqueCounter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/usage_data_counters/ci_template_unique_counter.rb

Constant Summary collapse

REDIS_SLOT =
'ci_templates'
KNOWN_EVENTS_FILE_PATH =
File.expand_path('known_events/ci_templates.yml', __dir__)

Class Method Summary collapse

Class Method Details

.ci_template_event_name(template_name, config_source) ⇒ Object


27
28
29
30
31
# File 'lib/gitlab/usage_data_counters/ci_template_unique_counter.rb', line 27

def ci_template_event_name(template_name, config_source)
  prefix = 'implicit_' if config_source.to_s == 'auto_devops_source'

  "p_#{REDIS_SLOT}_#{prefix}#{template_to_event_name(template_name)}"
end

.ci_templates(relative_base = 'lib/gitlab/ci/templates') ⇒ Object


23
24
25
# File 'lib/gitlab/usage_data_counters/ci_template_unique_counter.rb', line 23

def ci_templates(relative_base = 'lib/gitlab/ci/templates')
  Dir.glob('**/*.gitlab-ci.yml', base: Rails.root.join(relative_base))
end

.expand_template_name(template_name) ⇒ Object


33
34
35
# File 'lib/gitlab/usage_data_counters/ci_template_unique_counter.rb', line 33

def expand_template_name(template_name)
  Gitlab::Template::GitlabCiYmlTemplate.find(template_name.chomp('.gitlab-ci.yml'))&.full_name
end

.track_unique_project_event(project:, template:, config_source:, user:) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gitlab/usage_data_counters/ci_template_unique_counter.rb', line 9

def track_unique_project_event(project:, template:, config_source:, user:)
  expanded_template_name = expand_template_name(template)
  return unless expanded_template_name

  Gitlab::UsageDataCounters::HLLRedisCounter.track_event(
    ci_template_event_name(expanded_template_name, config_source), values: project.id
  )

  namespace = project.namespace
  if Feature.enabled?(:route_hll_to_snowplow, namespace)
    Gitlab::Tracking.event(name, 'ci_templates_unique', namespace: namespace, user: user, project: project)
  end
end