Commit b6db5a1e authored by Sean McGivern's avatar Sean McGivern

Allow querying queues by name

parent 189f707a
......@@ -109,6 +109,9 @@ attributes](https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/workers/all_q
latency, which also means that its jobs should run quickly. For example, the
`authorized_projects` queue is used to refresh user permissions, and is
latency sensitive.
- `name` - the queue name. The other attributes are typically more useful as
they are more general, but this is available in case a particular queue needs
to be selected.
- `resource_boundary` - if the worker is bound by `cpu`, `memory`, or
`unknown`. For example, the `project_export` queue is memory bound as it has
to load data in memory before saving it for export.
......
......@@ -23,6 +23,14 @@ module Gitlab
QUERY_CONCATENATE_OPERATOR = '|'
QUERY_TERM_REGEX = %r{^(\w+)(!?=)([\w|]+)}.freeze
QUERY_PREDICATES = {
feature_category: :to_sym,
has_external_dependencies: lambda { |value| value == 'true' },
latency_sensitive: lambda { |value| value == 'true' },
name: :to_s,
resource_boundary: :to_sym
}.freeze
QueryError = Class.new(StandardError)
InvalidTerm = Class.new(QueryError)
UnknownOperator = Class.new(QueryError)
......@@ -102,24 +110,11 @@ module Gitlab
end
def predicate_factory(lhs, values)
to_bool = lambda { |value| value == 'true' }
case lhs
when 'feature_category'
lambda { |worker| values.map(&:to_sym).include?(worker[:feature_category]) }
when 'has_external_dependencies'
lambda { |worker| values.map(&to_bool).include?(worker[:has_external_dependencies]) }
values_block = QUERY_PREDICATES[lhs.to_sym]
when 'latency_sensitive'
lambda { |worker| values.map(&to_bool).include?(worker[:latency_sensitive]) }
raise UnknownPredicate.new("Unknown predicate: #{lhs}") unless values_block
when 'resource_boundary'
lambda { |worker| values.map(&:to_sym).include?(worker[:resource_boundary]) }
else
raise UnknownPredicate.new("Unknown predicate: #{lhs}")
end
lambda { |queue| values.map(&values_block).include?(queue[lhs.to_sym]) }
end
end
end
......
......@@ -173,6 +173,12 @@ describe Gitlab::SidekiqConfig::CliMethods do
'latency_sensitive=true latency_sensitive=false' | %w(a a_2 b c)
'latency_sensitive!=true' | %w(a c)
# name
'name=a' | %w(a)
'name=a|b' | %w(a b)
'name=a|a_2 name=b' | %w(a a_2 b)
'name!=a|a_2' | %w(b c)
# resource_boundary
'resource_boundary=memory' | %w(b c)
'resource_boundary=memory|cpu' | %w(a b c)
......@@ -197,7 +203,7 @@ describe Gitlab::SidekiqConfig::CliMethods do
'feature_category="category_a"' | described_class::InvalidTerm
'feature_category=' | described_class::InvalidTerm
'feature_category~category_a' | described_class::InvalidTerm
'name=a' | described_class::UnknownPredicate
'worker_name=a' | described_class::UnknownPredicate
end
with_them do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment