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

count_imported_projects_total_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: 4430c7453e67e42ac5b7fa9e58eae6d278058ec5 (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 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