diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /lib/generators | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'lib/generators')
3 files changed, 88 insertions, 6 deletions
diff --git a/lib/generators/gitlab/snowplow_event_definition_generator.rb b/lib/generators/gitlab/snowplow_event_definition_generator.rb new file mode 100644 index 00000000000..497d0cd512a --- /dev/null +++ b/lib/generators/gitlab/snowplow_event_definition_generator.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +require 'rails/generators' + +module Gitlab + class SnowplowEventDefinitionGenerator < Rails::Generators::Base + CE_DIR = 'config/events' + EE_DIR = 'ee/config/events' + + source_root File.expand_path('../../../generator_templates/snowplow_event_definition', __dir__) + + desc 'Generates an event definition yml file' + + class_option :ee, type: :boolean, optional: true, default: false, desc: 'Indicates if event is for ee' + class_option :category, type: :string, optional: false, desc: 'Category of the event' + class_option :action, type: :string, optional: false, desc: 'Action of the event' + class_option :force, type: :boolean, optional: true, default: false, desc: 'Overwrite existing definition' + + def create_event_file + raise "Event definition already exists at #{file_path}" if definition_exists? && !force_definition_override? + + template "event_definition.yml", file_path, force: force_definition_override? + end + + def distributions + (ee? ? ['- ee'] : ['- ce', '- ee']).join("\n") + end + + def event_category + options[:category] + end + + def event_action + options[:action] + end + + def milestone + Gitlab::VERSION.match('(\d+\.\d+)').captures.first + end + + def ee? + options[:ee] + end + + def force_definition_override? + options[:force] + end + + private + + def definition_exists? + File.exist?(ce_file_path) || File.exist?(ee_file_path) + end + + def file_path + ee? ? ee_file_path : ce_file_path + end + + def ce_file_path + File.join(CE_DIR, file_name) + end + + def ee_file_path + File.join(EE_DIR, file_name) + end + + def file_name + "#{event_category}_#{event_action}.yml".underscore.gsub("/", "__") + end + end +end diff --git a/lib/generators/gitlab/usage_metric_definition/redis_hll_generator.rb b/lib/generators/gitlab/usage_metric_definition/redis_hll_generator.rb index d826c51a73d..e343e2dcf91 100644 --- a/lib/generators/gitlab/usage_metric_definition/redis_hll_generator.rb +++ b/lib/generators/gitlab/usage_metric_definition/redis_hll_generator.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'rails/generators' -require_relative '../usage_metric_definition_generator' module Gitlab module UsageMetricDefinition @@ -10,14 +9,24 @@ module Gitlab argument :category, type: :string, desc: "Category name" argument :event, type: :string, desc: "Event name" + class_option :ee, type: :boolean, optional: true, default: false, desc: 'Indicates if metric is for ee' def create_metrics - Gitlab::UsageMetricDefinitionGenerator.start(["#{key_path}_weekly", '--dir', '7d']) - Gitlab::UsageMetricDefinitionGenerator.start(["#{key_path}_monthly", '--dir', '28d']) + weekly_params = ["#{key_path}_weekly", '--dir', '7d'] + weekly_params << '--ee' if ee? + Gitlab::UsageMetricDefinitionGenerator.start(weekly_params) + + monthly_params = ["#{key_path}_monthly", '--dir', '28d'] + monthly_params << '--ee' if ee? + Gitlab::UsageMetricDefinitionGenerator.start(monthly_params) end private + def ee? + options[:ee] + end + def key_path "redis_hll_counters.#{category}.#{event}" end diff --git a/lib/generators/gitlab/usage_metric_definition_generator.rb b/lib/generators/gitlab/usage_metric_definition_generator.rb index cadc319a212..2d65363bf7b 100644 --- a/lib/generators/gitlab/usage_metric_definition_generator.rb +++ b/lib/generators/gitlab/usage_metric_definition_generator.rb @@ -53,9 +53,11 @@ module Gitlab end def distribution - value = ['- ce'] - value << '- ee' if ee? - value.join("\n") + (ee? ? ['- ee'] : ['- ce', '- ee']).join("\n") + end + + def tier + (ee? ? ['#- premium', '- ultimate'] : ['- free', '- premium', '- ultimate']).join("\n") end def milestone |