usage_data_spec.rb 5.42 KB
Newer Older
1 2 3
require 'spec_helper'

describe Gitlab::UsageData do
4 5
  let(:projects) { create_list(:project, 3) }
  let!(:board) { create(:board, project: projects[0]) }
6 7

  describe '#data' do
8 9 10 11 12 13 14
    before do
      create(:jira_service, project: projects[0])
      create(:jira_service, project: projects[1])
      create(:prometheus_service, project: projects[1])
      create(:service, project: projects[0], type: 'SlackSlashCommandsService', active: true)
      create(:service, project: projects[1], type: 'SlackService', active: true)
      create(:service, project: projects[2], type: 'SlackService', active: true)
15 16 17 18 19 20 21 22

      gcp_cluster = create(:cluster, :provided_by_gcp)
      create(:cluster, :provided_by_user)
      create(:cluster, :provided_by_user, :disabled)
      create(:clusters_applications_helm, :installed, cluster: gcp_cluster)
      create(:clusters_applications_ingress, :installed, cluster: gcp_cluster)
      create(:clusters_applications_prometheus, :installed, cluster: gcp_cluster)
      create(:clusters_applications_runner, :installed, cluster: gcp_cluster)
23 24
    end

25
    subject { described_class.data }
26 27 28 29 30 31

    it "gathers usage data" do
      expect(subject.keys).to match_array(%i(
        active_user_count
        counts
        recorded_at
Z.J. van de Weg's avatar
Z.J. van de Weg committed
32
        mattermost_enabled
33
        edition
34
        version
35
        installation_type
36
        uuid
37
        hostname
38 39 40 41 42 43 44 45 46 47
        signup
        ldap
        gravatar
        omniauth
        reply_by_email
        container_registry
        gitlab_pages
        gitlab_shared_runners
        git
        database
48
        avg_cycle_analytics
49 50 51 52 53 54 55
      ))
    end

    it "gathers usage counts" do
      count_data = subject[:counts]

      expect(count_data[:boards]).to eq(1)
56
      expect(count_data[:projects]).to eq(3)
57 58 59 60

      expect(count_data.keys).to match_array(%i(
        boards
        ci_builds
61 62
        ci_internal_pipelines
        ci_external_pipelines
63 64
        ci_pipeline_config_auto_devops
        ci_pipeline_config_repository
65 66
        ci_runners
        ci_triggers
67
        ci_pipeline_schedules
68 69
        auto_devops_enabled
        auto_devops_disabled
70 71 72
        deploy_keys
        deployments
        environments
73 74 75
        clusters
        clusters_enabled
        clusters_disabled
76 77 78 79 80 81
        clusters_platforms_gke
        clusters_platforms_user
        clusters_applications_helm
        clusters_applications_ingress
        clusters_applications_prometheus
        clusters_applications_runner
82
        in_review_folder
83 84 85 86 87 88 89 90 91
        groups
        issues
        keys
        labels
        lfs_objects
        merge_requests
        milestones
        notes
        projects
92
        projects_imported_from_github
93 94 95
        projects_jira_active
        projects_slack_notifications_active
        projects_slack_slash_active
96
        projects_prometheus_active
97 98 99
        pages_domains
        protected_branches
        releases
100
        remote_mirrors
101 102
        snippets
        todos
103
        uploads
104 105 106
        web_hooks
      ))
    end
107 108 109 110 111 112 113 114 115

    it 'gathers projects data correctly' do
      count_data = subject[:counts]

      expect(count_data[:projects]).to eq(3)
      expect(count_data[:projects_prometheus_active]).to eq(1)
      expect(count_data[:projects_jira_active]).to eq(2)
      expect(count_data[:projects_slack_notifications_active]).to eq(2)
      expect(count_data[:projects_slack_slash_active]).to eq(1)
116 117 118 119 120 121 122 123 124

      expect(count_data[:clusters_enabled]).to eq(6)
      expect(count_data[:clusters_disabled]).to eq(1)
      expect(count_data[:clusters_platforms_gke]).to eq(1)
      expect(count_data[:clusters_platforms_user]).to eq(1)
      expect(count_data[:clusters_applications_helm]).to eq(1)
      expect(count_data[:clusters_applications_ingress]).to eq(1)
      expect(count_data[:clusters_applications_prometheus]).to eq(1)
      expect(count_data[:clusters_applications_runner]).to eq(1)
125
    end
126 127
  end

128 129 130 131
  describe '#features_usage_data_ce' do
    subject { described_class.features_usage_data_ce }

    it 'gathers feature usage data' do
132
      expect(subject[:signup]).to eq(Gitlab::CurrentSettings.allow_signup?)
133
      expect(subject[:ldap]).to eq(Gitlab.config.ldap.enabled)
134
      expect(subject[:gravatar]).to eq(Gitlab::CurrentSettings.gravatar_enabled?)
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
      expect(subject[:omniauth]).to eq(Gitlab.config.omniauth.enabled)
      expect(subject[:reply_by_email]).to eq(Gitlab::IncomingEmail.enabled?)
      expect(subject[:container_registry]).to eq(Gitlab.config.registry.enabled)
      expect(subject[:gitlab_shared_runners]).to eq(Gitlab.config.gitlab_ci.shared_runners_enabled)
    end
  end

  describe '#components_usage_data' do
    subject { described_class.components_usage_data }

    it 'gathers components usage data' do
      expect(subject[:gitlab_pages][:enabled]).to eq(Gitlab.config.pages.enabled)
      expect(subject[:gitlab_pages][:version]).to eq(Gitlab::Pages::VERSION)
      expect(subject[:git][:version]).to eq(Gitlab::Git.version)
      expect(subject[:database][:adapter]).to eq(Gitlab::Database.adapter_name)
      expect(subject[:database][:version]).to eq(Gitlab::Database.version)
    end
  end

154
  describe '#license_usage_data' do
155
    subject { described_class.license_usage_data }
156 157

    it "gathers license data" do
158
      expect(subject[:uuid]).to eq(Gitlab::CurrentSettings.uuid)
159
      expect(subject[:version]).to eq(Gitlab::VERSION)
160
      expect(subject[:installation_type]).to eq(Gitlab::INSTALLATION_TYPE)
161 162 163 164 165
      expect(subject[:active_user_count]).to eq(User.active.count)
      expect(subject[:recorded_at]).to be_a(Time)
    end
  end
end