Class: Gitlab::UsageMetricDefinitionGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/gitlab/usage_metric_definition_generator.rb

Defined Under Namespace

Classes: Directory

Constant Summary collapse

TIME_FRAME_DIRS =
[
  Directory.new('counts_7d',  '7d',   'number'),
  Directory.new('counts_28d', '28d',  'number'),
  Directory.new('counts_all', 'all',  'number'),
  Directory.new('settings',   'none', 'boolean'),
  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

Instance Method Summary collapse

Instance Method Details

#class_nameObject



79
80
81
# File 'lib/generators/gitlab/usage_metric_definition_generator.rb', line 79

def class_name
  options[:class_name]
end

#create_metric_fileObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/generators/gitlab/usage_metric_definition_generator.rb', line 45

def create_metric_file
  say("This generator is DEPRECATED. For event based metrics use Internal Events tracking framework instead.")
  # rubocop: disable Gitlab/DocumentationLinks/HardcodedUrl -- links for developers, not users
  say("https://docs.gitlab.com/ee/development/internal_analytics/internal_event_instrumentation/quick_start.html")

  say("If you need to implement Database, Prometheus or custom metrics, see")
  say("https://docs.gitlab.com/ee/development/internal_analytics/metrics/metrics_instrumentation.html")
  # rubocop: enable Gitlab/DocumentationLinks/HardcodedUrl
  desc = ask("Would you like to continue anyway? y/N") || 'n'
  return unless desc.casecmp('y') == 0

  validate!

  key_paths.each do |key_path|
    template "metric_definition.yml", file_path(key_path), key_path
  end
end

#milestoneObject



75
76
77
# File 'lib/generators/gitlab/usage_metric_definition_generator.rb', line 75

def milestone
  Gitlab::VERSION.match('(\d+\.\d+)').captures.first
end

#tierObject



71
72
73
# File 'lib/generators/gitlab/usage_metric_definition_generator.rb', line 71

def tier
  (ee? ? ['#- premium', '- ultimate'] : ['- free', '- premium', '- ultimate']).join("\n")
end

#time_frameObject



63
64
65
# File 'lib/generators/gitlab/usage_metric_definition_generator.rb', line 63

def time_frame
  directory&.time_frame
end

#value_typeObject



67
68
69
# File 'lib/generators/gitlab/usage_metric_definition_generator.rb', line 67

def value_type
  directory&.value_type
end