blob: 642b67a3b02fe1c932307dbe562714428f241115 (
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
|
# 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
end
def source_type
options[:source_type].to_s
end
def status
options[:status]
end
def allowed_source_types
BulkImports::Entity.source_types.keys.map(&:to_s)
end
end
end
end
end
end
|