2021-01-11 06:10:29 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab::UsageDataCounters
|
|
|
|
class CiTemplateUniqueCounter
|
2021-03-23 15:09:28 +00:00
|
|
|
REDIS_SLOT = 'ci_templates'
|
2021-01-11 06:10:29 +00:00
|
|
|
|
2021-02-15 12:09:29 +00:00
|
|
|
# NOTE: Events originating from implicit Auto DevOps pipelines get prefixed with `implicit_`
|
2021-01-11 06:10:29 +00:00
|
|
|
TEMPLATE_TO_EVENT = {
|
2021-02-09 18:09:59 +00:00
|
|
|
'5-Minute-Production-App.gitlab-ci.yml' => '5_min_production_app',
|
2021-01-11 06:10:29 +00:00
|
|
|
'Auto-DevOps.gitlab-ci.yml' => 'auto_devops',
|
|
|
|
'AWS/CF-Provision-and-Deploy-EC2.gitlab-ci.yml' => 'aws_cf_deploy_ec2',
|
|
|
|
'AWS/Deploy-ECS.gitlab-ci.yml' => 'aws_deploy_ecs',
|
|
|
|
'Jobs/Build.gitlab-ci.yml' => 'auto_devops_build',
|
|
|
|
'Jobs/Deploy.gitlab-ci.yml' => 'auto_devops_deploy',
|
|
|
|
'Jobs/Deploy.latest.gitlab-ci.yml' => 'auto_devops_deploy_latest',
|
|
|
|
'Security/SAST.gitlab-ci.yml' => 'security_sast',
|
|
|
|
'Security/Secret-Detection.gitlab-ci.yml' => 'security_secret_detection',
|
|
|
|
'Terraform/Base.latest.gitlab-ci.yml' => 'terraform_base_latest'
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
class << self
|
2021-02-15 12:09:29 +00:00
|
|
|
def track_unique_project_event(project_id:, template:, config_source:)
|
|
|
|
if event = unique_project_event(template, config_source)
|
2021-01-11 06:10:29 +00:00
|
|
|
Gitlab::UsageDataCounters::HLLRedisCounter.track_event(event, values: project_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-02-15 12:09:29 +00:00
|
|
|
def unique_project_event(template, config_source)
|
2021-01-11 06:10:29 +00:00
|
|
|
if name = TEMPLATE_TO_EVENT[template]
|
2021-02-15 12:09:29 +00:00
|
|
|
prefix = 'implicit_' if config_source.to_s == 'auto_devops_source'
|
|
|
|
|
|
|
|
"p_#{REDIS_SLOT}_#{prefix}#{name}"
|
2021-01-11 06:10:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|