summaryrefslogtreecommitdiff
path: root/lib/generators
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-06-06 00:07:52 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-06-06 00:07:52 +0000
commit7be95ced1dd3351d30008462b4cbb5edea18f3ee (patch)
tree1cab1bb8cd630898c55d1cf757293470937ed592 /lib/generators
parent37966491101fa89cc13b14af883f946deb9cc42b (diff)
downloadgitlab-ce-7be95ced1dd3351d30008462b4cbb5edea18f3ee.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/generators')
-rw-r--r--lib/generators/gitlab/usage_metric/templates/numbers_instrumentation_class.rb.template19
-rw-r--r--lib/generators/gitlab/usage_metric_generator.rb11
2 files changed, 27 insertions, 3 deletions
diff --git a/lib/generators/gitlab/usage_metric/templates/numbers_instrumentation_class.rb.template b/lib/generators/gitlab/usage_metric/templates/numbers_instrumentation_class.rb.template
new file mode 100644
index 00000000000..ef9537f970e
--- /dev/null
+++ b/lib/generators/gitlab/usage_metric/templates/numbers_instrumentation_class.rb.template
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Usage
+ module Metrics
+ module Instrumentations
+ class <%= class_name %>Metric < NumbersMetric
+ operation :<%= operation%>
+
+ data do |time_frame|
+ [
+ # Insert numbers here
+ ]
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/generators/gitlab/usage_metric_generator.rb b/lib/generators/gitlab/usage_metric_generator.rb
index 0eef6ceb539..6348d481d14 100644
--- a/lib/generators/gitlab/usage_metric_generator.rb
+++ b/lib/generators/gitlab/usage_metric_generator.rb
@@ -12,10 +12,13 @@ module Gitlab
ALLOWED_SUPERCLASSES = {
generic: 'Generic',
database: 'Database',
- redis: 'Redis'
+ redis: 'Redis',
+ numbers: 'Numbers'
}.freeze
- ALLOWED_OPERATIONS = %w(count distinct_count estimate_batch_distinct_count sum).freeze
+ ALLOWED_DATABASE_OPERATIONS = %w(count distinct_count estimate_batch_distinct_count sum).freeze
+ ALLOWED_NUMBERS_OPERATIONS = %w(add).freeze
+ ALLOWED_OPERATIONS = ALLOWED_DATABASE_OPERATIONS | ALLOWED_NUMBERS_OPERATIONS
source_root File.expand_path('usage_metric/templates', __dir__)
@@ -29,6 +32,7 @@ module Gitlab
validate!
template "database_instrumentation_class.rb.template", file_path if type == 'database'
+ template "numbers_instrumentation_class.rb.template", file_path if type == 'numbers'
template "generic_instrumentation_class.rb.template", file_path if type == 'generic'
template "instrumentation_class_spec.rb.template", spec_file_path
@@ -39,7 +43,8 @@ module Gitlab
def validate!
raise ArgumentError, "Type is required, valid options are #{ALLOWED_SUPERCLASSES.keys.join(', ')}" unless type.present?
raise ArgumentError, "Unknown type '#{type}', valid options are #{ALLOWED_SUPERCLASSES.keys.join(', ')}" if metric_superclass.nil?
- raise ArgumentError, "Unknown operation '#{operation}' valid operations are #{ALLOWED_OPERATIONS.join(', ')}" if type == 'database' && !ALLOWED_OPERATIONS.include?(operation)
+ raise ArgumentError, "Unknown operation '#{operation}' valid operations for database are #{ALLOWED_DATABASE_OPERATIONS.join(', ')}" if type == 'database' && ALLOWED_DATABASE_OPERATIONS.exclude?(operation)
+ raise ArgumentError, "Unknown operation '#{operation}' valid operations for numbers are #{ALLOWED_NUMBERS_OPERATIONS.join(', ')}" if type == 'numbers' && ALLOWED_NUMBERS_OPERATIONS.exclude?(operation)
end
def ee?