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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/usage/metrics/instrumentations/count_deployments_metric.rb')
-rw-r--r--lib/gitlab/usage/metrics/instrumentations/count_deployments_metric.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/gitlab/usage/metrics/instrumentations/count_deployments_metric.rb b/lib/gitlab/usage/metrics/instrumentations/count_deployments_metric.rb
new file mode 100644
index 00000000000..97813fbb5c0
--- /dev/null
+++ b/lib/gitlab/usage/metrics/instrumentations/count_deployments_metric.rb
@@ -0,0 +1,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