Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ci_template_unique_counter.rb « usage_data_counters « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c9106d7c6b859c48621d225dda03831de4d99478 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

module Gitlab::UsageDataCounters
  class CiTemplateUniqueCounter
    REDIS_SLOT = 'ci_templates'

    # NOTE: Events originating from implicit Auto DevOps pipelines get prefixed with `implicit_`
    TEMPLATE_TO_EVENT = {
      '5-Minute-Production-App.gitlab-ci.yml' => '5_min_production_app',
      '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
      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
      end

      private

      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}#{name}"
        end
      end
    end
  end
end