blob: ca122ccf6f3197df5e5e3fd5070e55794640731b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Instrumentations
class CountBulkImportsEntitiesMetric < DatabaseMetric
operation :count
def initialize(metric_definition)
super
if source_type.present? && !source_type.in?(allowed_source_types)
raise ArgumentError, "source_type '#{source_type}' must be one of: #{allowed_source_types.join(', ')}"
end
end
relation { ::BulkImports::Entity }
private
def relation
scope = super
scope = scope.where(source_type: source_type) if source_type.present?
scope = scope.where(status: status) if status.present?
scope = scope.where(has_failures: failures) if failures.present?
scope
end
def source_type
options[:source_type].to_s
end
def status
options[:status]
end
def failures
options[:has_failures].to_s
end
def allowed_source_types
BulkImports::Entity.source_types.keys.map(&:to_s)
end
end
end
end
end
end
|