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:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-30 15:08:23 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-30 15:08:23 +0300
commitf1284938edfc2e033baf2c26ebadf42c526f6432 (patch)
tree1537dfd31ad896605914c9e5aa57351d67260b1f /lib/gitlab/usage
parentbf774d67fc8a84f76f20494c318d7cfacb0c69ac (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/usage')
-rw-r--r--lib/gitlab/usage/metrics/instrumentations/count_imported_projects_total_metric.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/gitlab/usage/metrics/instrumentations/count_imported_projects_total_metric.rb b/lib/gitlab/usage/metrics/instrumentations/count_imported_projects_total_metric.rb
new file mode 100644
index 00000000000..109d2245635
--- /dev/null
+++ b/lib/gitlab/usage/metrics/instrumentations/count_imported_projects_total_metric.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Usage
+ module Metrics
+ module Instrumentations
+ class CountImportedProjectsTotalMetric < DatabaseMetric
+ # Relation and operation are not used, but are included to satisfy expectations
+ # of other metric generation logic.
+ relation { Project }
+ operation :count
+
+ IMPORT_TYPES = %w(gitlab_project gitlab github bitbucket bitbucket_server gitea git manifest
+ gitlab_migration).freeze
+
+ def value
+ count(project_relation) + count(entity_relation)
+ end
+
+ def to_sql
+ project_relation_sql = Gitlab::Usage::Metrics::Query.for(:count, project_relation)
+ entity_relation_sql = Gitlab::Usage::Metrics::Query.for(:count, entity_relation)
+
+ "SELECT (#{project_relation_sql}) + (#{entity_relation_sql})"
+ end
+
+ private
+
+ def project_relation
+ Project.imported_from(IMPORT_TYPES).where(time_constraints)
+ end
+
+ def entity_relation
+ BulkImports::Entity.where(source_type: :project_entity).where(time_constraints)
+ end
+ end
+ end
+ end
+ end
+end