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

count_deployments_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: 97813fbb5c08328570250a5dd07333df0666947e (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
# frozen_string_literal: true

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

          start { Deployment.minimum(:id) }
          finish { Deployment.maximum(:id) }

          def initialize(metric_definition)
            super

            raise ArgumentError, 'Missing Deployment type' unless type
            raise ArgumentError, "Invalid Deployment type: #{type}" unless type.in?(%i[all success failed])
          end

          private

          def type
            options[:type].to_sym
          end

          def relation
            @metric_relation = case type
                               when :all
                                 Deployment
                               when :success
                                 Deployment.success
                               when :failed
                                 Deployment.failed
                               end.where(time_constraints)
          end
        end
      end
    end
  end
end