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

count_bulk_imports_entities_metric.rb « instrumentations « metrics « usage « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c0d53b1b21a6bbcefae5d3e9bba9acc56bdbce12 (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
# frozen_string_literal: true

module Gitlab
  module Usage
    module Metrics
      module Instrumentations
        class CountBulkImportsEntitiesMetric < DatabaseMetric
          operation :count

          def initialize(time_frame:, options: {})
            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
            return super.where(source_type: source_type) if source_type.present? # rubocop: disable CodeReuse/ActiveRecord

            super
          end

          def source_type
            options[:source_type].to_s
          end

          def allowed_source_types
            BulkImports::Entity.source_types.keys.map(&:to_s)
          end
        end
      end
    end
  end
end