summaryrefslogtreecommitdiff
path: root/lib/gitlab/usage/metrics/instrumentations/jira_active_integrations_metric.rb
blob: 13af3937f430f241d7bd721f7e6d1f3efc70535b (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
# frozen_string_literal: true

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

          def initialize(metric_definition)
            super

            deployment_type = options[:deployment_type]

            return if deployment_type.in?(allowed_types)

            raise ArgumentError, "deployment_type '#{deployment_type}' must be one of: #{allowed_types.join(', ')}"
          end

          relation do |options|
            ::Integrations::Jira
              .active
              .joins(:jira_tracker_data)
              .where(jira_tracker_data: { deployment_type: options[:deployment_type] })
          end

          private

          def allowed_types
            Integrations::JiraTrackerData.deployment_types.keys
          end
        end
      end
    end
  end
end