From f64a639bcfa1fc2bc89ca7db268f594306edfd7c Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 16 Mar 2021 18:18:33 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-10-stable-ee --- .../gitlab/usage_metric_definition_generator.rb | 28 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'lib/generators') diff --git a/lib/generators/gitlab/usage_metric_definition_generator.rb b/lib/generators/gitlab/usage_metric_definition_generator.rb index d3fac4c74f3..7a01050ed0c 100644 --- a/lib/generators/gitlab/usage_metric_definition_generator.rb +++ b/lib/generators/gitlab/usage_metric_definition_generator.rb @@ -18,6 +18,9 @@ module Gitlab Directory.new('license', 'none', 'string') ].freeze + TOP_LEVEL_DIR = 'config' + TOP_LEVEL_DIR_EE = 'ee' + VALID_INPUT_DIRS = (TIME_FRAME_DIRS.flat_map { |d| [d.name, d.time_frame] } - %w(none)).freeze source_root File.expand_path('../../../generator_templates/usage_metric_definition', __dir__) @@ -56,15 +59,22 @@ module Gitlab private + def metric_name_suggestion + return unless Feature.enabled?(:product_intelligence_metrics_names_suggestions, default_enabled: :yaml) + + "\nname: #{Usage::Metrics::NamesSuggestions::Generator.generate(key_path)}" + end + def file_path - path = File.join('config', 'metrics', directory&.name, "#{file_name}.yml") - path = File.join('ee', path) if ee? + path = File.join(TOP_LEVEL_DIR, 'metrics', directory&.name, "#{file_name}.yml") + path = File.join(TOP_LEVEL_DIR_EE, path) if ee? path end def validate! raise "--dir option is required" unless input_dir.present? raise "Invalid dir #{input_dir}, allowed options are #{VALID_INPUT_DIRS.join(', ')}" unless directory.present? + raise "Metric definition with key path '#{key_path}' already exists" if metric_definition_exists? end def ee? @@ -79,11 +89,23 @@ module Gitlab # # 20210201124931_g_project_management_issue_title_changed_weekly.yml def file_name - "#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_#{key_path.split('.').last}" + "#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_#{metric_name}" end def directory @directory ||= TIME_FRAME_DIRS.find { |d| d.match?(input_dir) } end + + def metric_name + key_path.split('.').last + end + + def metric_definitions + @definitions ||= Gitlab::Usage::MetricDefinition.definitions + end + + def metric_definition_exists? + metric_definitions[key_path].present? + end end end -- cgit v1.2.1