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>2022-11-09 21:07:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-11-09 21:07:50 +0300
commit20f6a17ba2d2d5f056bda38dfe85e2a7b2a82d0b (patch)
tree1319f393750fa7a212455746273c05465d786fde /lib/gitlab/usage
parente38a99eb0725697297386dd0bb1045b1fd55493a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/usage')
-rw-r--r--lib/gitlab/usage/metrics/name_suggestion.rb30
-rw-r--r--lib/gitlab/usage/metrics/names_suggestions/relation_parsers/having_constraints.rb31
-rw-r--r--lib/gitlab/usage/metrics/names_suggestions/relation_parsers/where_constraints.rb (renamed from lib/gitlab/usage/metrics/names_suggestions/relation_parsers/constraints.rb)8
3 files changed, 57 insertions, 12 deletions
diff --git a/lib/gitlab/usage/metrics/name_suggestion.rb b/lib/gitlab/usage/metrics/name_suggestion.rb
index 238a7a51a20..44723b6f3d4 100644
--- a/lib/gitlab/usage/metrics/name_suggestion.rb
+++ b/lib/gitlab/usage/metrics/name_suggestion.rb
@@ -7,6 +7,7 @@ module Gitlab
FREE_TEXT_METRIC_NAME = "<please fill metric name>"
REDIS_EVENT_METRIC_NAME = "<please fill metric name, suggested format is: {subject}_{verb}{ing|ed}_{object} eg: users_creating_epics or merge_requests_viewed_in_single_file_mode>"
CONSTRAINTS_PROMPT_TEMPLATE = "<adjective describing: '%{constraints}'>"
+ EMPTY_CONSTRAINT = "()"
class << self
def for(operation, relation: nil, column: nil)
@@ -52,7 +53,8 @@ module Gitlab
end
arel = arel_query(relation: relation, column: arel_column, distinct: distinct)
- constraints = parse_constraints(relation: relation, arel: arel)
+ where_constraints = parse_where_constraints(relation: relation, arel: arel)
+ having_constraints = parse_having_constraints(relation: relation, arel: arel)
# In some cases due to performance reasons metrics are instrumented with joined relations
# where relation listed in FROM statement is not the one that includes counted attribute
@@ -66,23 +68,35 @@ module Gitlab
# count_environment_id_from_clusters_with_deployments
actual_source = parse_source(relation, arel_column)
- append_constraints_prompt(actual_source, [constraints], parts)
+ append_constraints_prompt(actual_source, [where_constraints], [having_constraints], parts)
parts << actual_source
- parts += process_joined_relations(actual_source, arel, relation, constraints)
+ parts += process_joined_relations(actual_source, arel, relation, where_constraints)
parts.compact.join('_').delete('"')
end
- def append_constraints_prompt(target, constraints, parts)
- applicable_constraints = constraints.select { |constraint| constraint.include?(target) }
+ def append_constraints_prompt(target, where_constraints, having_constraints, parts)
+ where_constraints.select! do |constraint|
+ constraint.include?(target)
+ end
+ having_constraints.delete(EMPTY_CONSTRAINT)
+ applicable_constraints = where_constraints + having_constraints
return unless applicable_constraints.any?
parts << CONSTRAINTS_PROMPT_TEMPLATE % { constraints: applicable_constraints.join(' AND ') }
end
- def parse_constraints(relation:, arel:)
+ def parse_where_constraints(relation:, arel:)
+ connection = relation.connection
+ ::Gitlab::Usage::Metrics::NamesSuggestions::RelationParsers::WhereConstraints
+ .new(connection)
+ .accept(arel, collector(connection))
+ .value
+ end
+
+ def parse_having_constraints(relation:, arel:)
connection = relation.connection
- ::Gitlab::Usage::Metrics::NamesSuggestions::RelationParsers::Constraints
+ ::Gitlab::Usage::Metrics::NamesSuggestions::RelationParsers::HavingConstraints
.new(connection)
.accept(arel, collector(connection))
.value
@@ -152,7 +166,7 @@ module Gitlab
subtree.each do |parent, children|
parts << "<#{conjunction}>"
join_constraints = joins.find { |join| join[:source] == parent }&.dig(:constraints)
- append_constraints_prompt(parent, [wheres, join_constraints].compact, parts)
+ append_constraints_prompt(parent, [wheres, join_constraints].compact, [], parts)
parts << parent
collect_join_parts(relations: children, joins: joins, wheres: wheres, parts: parts, conjunctions: conjunctions)
end
diff --git a/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/having_constraints.rb b/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/having_constraints.rb
new file mode 100644
index 00000000000..8dd3b1ff5c6
--- /dev/null
+++ b/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/having_constraints.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Usage
+ module Metrics
+ module NamesSuggestions
+ module RelationParsers
+ class HavingConstraints < ::Arel::Visitors::PostgreSQL
+ # rubocop:disable Naming/MethodName
+ def visit_Arel_Nodes_SelectCore(object, collector)
+ collect_nodes_for(object.havings, collector, "") || collector
+ end
+ # rubocop:enable Naming/MethodName
+
+ def quote(value)
+ value.to_s
+ end
+
+ def quote_table_name(name)
+ name.to_s
+ end
+
+ def quote_column_name(name)
+ name.to_s
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/constraints.rb b/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/where_constraints.rb
index 199395e4b20..9f829067214 100644
--- a/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/constraints.rb
+++ b/lib/gitlab/usage/metrics/names_suggestions/relation_parsers/where_constraints.rb
@@ -5,7 +5,7 @@ module Gitlab
module Metrics
module NamesSuggestions
module RelationParsers
- class Constraints < ::Arel::Visitors::PostgreSQL
+ class WhereConstraints < ::Arel::Visitors::PostgreSQL
# rubocop:disable Naming/MethodName
def visit_Arel_Nodes_SelectCore(object, collector)
collect_nodes_for(object.wheres, collector, "") || collector
@@ -13,15 +13,15 @@ module Gitlab
# rubocop:enable Naming/MethodName
def quote(value)
- "#{value}"
+ value.to_s
end
def quote_table_name(name)
- "#{name}"
+ name.to_s
end
def quote_column_name(name)
- "#{name}"
+ name.to_s
end
end
end