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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 12:08:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 12:08:42 +0300
commitb76ae638462ab0f673e5915986070518dd3f9ad3 (patch)
treebdab0533383b52873be0ec0eb4d3c66598ff8b91 /lib/generators
parent434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff)
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'lib/generators')
-rw-r--r--lib/generators/gitlab/usage_metric/templates/database_instrumentation_class.rb.template17
-rw-r--r--lib/generators/gitlab/usage_metric/templates/generic_instrumentation_class.rb.template (renamed from lib/generators/gitlab/usage_metric/templates/instrumentation_class.rb.template)5
-rw-r--r--lib/generators/gitlab/usage_metric_generator.rb (renamed from lib/generators/gitlab/usage_metric/usage_metric_generator.rb)16
-rw-r--r--lib/generators/post_deployment_migration/post_deployment_migration_generator.rb (renamed from lib/generators/rails/post_deployment_migration/post_deployment_migration_generator.rb)2
4 files changed, 34 insertions, 6 deletions
diff --git a/lib/generators/gitlab/usage_metric/templates/database_instrumentation_class.rb.template b/lib/generators/gitlab/usage_metric/templates/database_instrumentation_class.rb.template
new file mode 100644
index 00000000000..74b1ed69a5c
--- /dev/null
+++ b/lib/generators/gitlab/usage_metric/templates/database_instrumentation_class.rb.template
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Usage
+ module Metrics
+ module Instrumentations
+ class <%= class_name %>Metric < DatabaseMetric
+ operation :<%= operation%>
+
+ relation do
+ # Insert ActiveRecord relation here
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/generators/gitlab/usage_metric/templates/instrumentation_class.rb.template b/lib/generators/gitlab/usage_metric/templates/generic_instrumentation_class.rb.template
index 603b6f3bc8a..fa6c18a289c 100644
--- a/lib/generators/gitlab/usage_metric/templates/instrumentation_class.rb.template
+++ b/lib/generators/gitlab/usage_metric/templates/generic_instrumentation_class.rb.template
@@ -4,8 +4,9 @@ module Gitlab
module Usage
module Metrics
module Instrumentations
- class <%= class_name %>Metric < <%= metric_superclass %>Metric
- def value
+ class <%= class_name %>Metric < GenericMetric
+ value do
+ # Insert metric code logic here
end
end
end
diff --git a/lib/generators/gitlab/usage_metric/usage_metric_generator.rb b/lib/generators/gitlab/usage_metric_generator.rb
index f7125fdc911..c0fdcf21f20 100644
--- a/lib/generators/gitlab/usage_metric/usage_metric_generator.rb
+++ b/lib/generators/gitlab/usage_metric_generator.rb
@@ -12,20 +12,25 @@ module Gitlab
ALLOWED_SUPERCLASSES = {
generic: 'Generic',
database: 'Database',
- redis_hll: 'RedisHLL'
+ redis: 'Redis'
}.freeze
- source_root File.expand_path('templates', __dir__)
+ ALLOWED_OPERATIONS = %w(count distinct_count estimate_batch_distinct_count).freeze
+
+ source_root File.expand_path('usage_metric/templates', __dir__)
class_option :ee, type: :boolean, optional: true, default: false, desc: 'Indicates if instrumentation is for EE'
class_option :type, type: :string, desc: "Metric type, must be one of: #{ALLOWED_SUPERCLASSES.keys.join(', ')}"
+ class_option :operation, type: :string, desc: "Metric operation, must be one of: #{ALLOWED_OPERATIONS.join(', ')}"
argument :class_name, type: :string, desc: 'Instrumentation class name, e.g.: CountIssues'
def create_class_files
validate!
- template "instrumentation_class.rb.template", file_path
+ template "database_instrumentation_class.rb.template", file_path if type == 'database'
+ template "generic_instrumentation_class.rb.template", file_path if type == 'generic'
+
template "instrumentation_class_spec.rb.template", spec_file_path
end
@@ -34,6 +39,7 @@ 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)
end
def ee?
@@ -44,6 +50,10 @@ module Gitlab
options[:type]
end
+ def operation
+ options[:operation]
+ end
+
def file_path
dir = ee? ? EE_DIR : CE_DIR
diff --git a/lib/generators/rails/post_deployment_migration/post_deployment_migration_generator.rb b/lib/generators/post_deployment_migration/post_deployment_migration_generator.rb
index 568104cb30b..66ee0e2440f 100644
--- a/lib/generators/rails/post_deployment_migration/post_deployment_migration_generator.rb
+++ b/lib/generators/post_deployment_migration/post_deployment_migration_generator.rb
@@ -2,7 +2,7 @@
require 'rails/generators'
-module Rails
+module PostDeploymentMigration
class PostDeploymentMigrationGenerator < Rails::Generators::NamedBase
def create_migration_file
timestamp = Time.now.utc.strftime('%Y%m%d%H%M%S')