debian-mirror-gitlab/spec/lib/gitlab/usage_data_spec.rb

202 lines
6.8 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
describe Gitlab::UsageData do
2017-09-10 17:25:29 +05:30
let(:projects) { create_list(:project, 3) }
let!(:board) { create(:board, project: projects[0]) }
2017-08-17 22:00:37 +05:30
describe '#data' do
2017-09-10 17:25:29 +05:30
before do
create(:jira_service, project: projects[0])
create(:jira_service, project: projects[1])
2018-12-13 13:39:08 +05:30
create(:jira_cloud_service, project: projects[2])
2017-09-10 17:25:29 +05:30
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)
2018-05-09 12:01:36 +05:30
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)
2018-12-13 13:39:08 +05:30
create(:clusters_applications_knative, :installed, cluster: gcp_cluster)
2017-09-10 17:25:29 +05:30
end
2017-08-17 22:00:37 +05:30
subject { described_class.data }
it "gathers usage data" do
expect(subject.keys).to match_array(%i(
active_user_count
counts
recorded_at
edition
version
2018-11-08 19:23:39 +05:30
installation_type
2017-08-17 22:00:37 +05:30
uuid
hostname
2018-11-08 19:23:39 +05:30
mattermost_enabled
signup_enabled
ldap_enabled
gravatar_enabled
omniauth_enabled
reply_by_email_enabled
container_registry_enabled
gitlab_shared_runners_enabled
2018-03-17 18:26:18 +05:30
gitlab_pages
git
database
2018-03-27 19:54:05 +05:30
avg_cycle_analytics
2018-12-05 23:21:45 +05:30
web_ide_commits
2017-08-17 22:00:37 +05:30
))
end
it "gathers usage counts" do
count_data = subject[:counts]
expect(count_data[:boards]).to eq(1)
2017-09-10 17:25:29 +05:30
expect(count_data[:projects]).to eq(3)
2017-08-17 22:00:37 +05:30
expect(count_data.keys).to match_array(%i(
2018-11-20 20:47:30 +05:30
assignee_lists
2017-08-17 22:00:37 +05:30
boards
ci_builds
2017-09-10 17:25:29 +05:30
ci_internal_pipelines
ci_external_pipelines
2018-03-17 18:26:18 +05:30
ci_pipeline_config_auto_devops
ci_pipeline_config_repository
2017-08-17 22:00:37 +05:30
ci_runners
ci_triggers
ci_pipeline_schedules
2018-03-17 18:26:18 +05:30
auto_devops_enabled
auto_devops_disabled
2017-08-17 22:00:37 +05:30
deploy_keys
deployments
environments
2018-03-17 18:26:18 +05:30
clusters
clusters_enabled
clusters_disabled
2018-05-09 12:01:36 +05:30
clusters_platforms_gke
clusters_platforms_user
clusters_applications_helm
clusters_applications_ingress
clusters_applications_prometheus
clusters_applications_runner
2018-12-13 13:39:08 +05:30
clusters_applications_knative
2017-09-10 17:25:29 +05:30
in_review_folder
2017-08-17 22:00:37 +05:30
groups
issues
keys
2018-11-20 20:47:30 +05:30
label_lists
2017-08-17 22:00:37 +05:30
labels
lfs_objects
merge_requests
2018-11-20 20:47:30 +05:30
milestone_lists
2017-08-17 22:00:37 +05:30
milestones
notes
projects
2017-09-10 17:25:29 +05:30
projects_imported_from_github
projects_jira_active
2018-12-13 13:39:08 +05:30
projects_jira_server_active
projects_jira_cloud_active
2017-09-10 17:25:29 +05:30
projects_slack_notifications_active
projects_slack_slash_active
2017-08-17 22:00:37 +05:30
projects_prometheus_active
pages_domains
protected_branches
releases
2018-10-15 14:42:47 +05:30
remote_mirrors
2017-08-17 22:00:37 +05:30
snippets
todos
uploads
web_hooks
))
end
2017-09-10 17:25:29 +05:30
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)
2018-12-13 13:39:08 +05:30
expect(count_data[:projects_jira_active]).to eq(3)
expect(count_data[:projects_jira_server_active]).to eq(2)
expect(count_data[:projects_jira_cloud_active]).to eq(1)
2017-09-10 17:25:29 +05:30
expect(count_data[:projects_slack_notifications_active]).to eq(2)
expect(count_data[:projects_slack_slash_active]).to eq(1)
2018-05-09 12:01:36 +05:30
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)
2018-12-13 13:39:08 +05:30
expect(count_data[:clusters_applications_knative]).to eq(1)
end
it 'works when queries time out' do
allow_any_instance_of(ActiveRecord::Relation)
.to receive(:count).and_raise(ActiveRecord::StatementInvalid.new(''))
expect { subject }.not_to raise_error
2017-09-10 17:25:29 +05:30
end
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
describe '#features_usage_data_ce' do
subject { described_class.features_usage_data_ce }
it 'gathers feature usage data' do
2018-11-08 19:23:39 +05:30
expect(subject[:mattermost_enabled]).to eq(Gitlab.config.mattermost.enabled)
expect(subject[:signup_enabled]).to eq(Gitlab::CurrentSettings.allow_signup?)
expect(subject[:ldap_enabled]).to eq(Gitlab.config.ldap.enabled)
expect(subject[:gravatar_enabled]).to eq(Gitlab::CurrentSettings.gravatar_enabled?)
2018-11-18 11:00:15 +05:30
expect(subject[:omniauth_enabled]).to eq(Gitlab::Auth.omniauth_enabled?)
2018-11-08 19:23:39 +05:30
expect(subject[:reply_by_email_enabled]).to eq(Gitlab::IncomingEmail.enabled?)
expect(subject[:container_registry_enabled]).to eq(Gitlab.config.registry.enabled)
expect(subject[:gitlab_shared_runners_enabled]).to eq(Gitlab.config.gitlab_ci.shared_runners_enabled)
2018-03-17 18:26:18 +05:30
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
2017-08-17 22:00:37 +05:30
describe '#license_usage_data' do
subject { described_class.license_usage_data }
it "gathers license data" do
2018-03-17 18:26:18 +05:30
expect(subject[:uuid]).to eq(Gitlab::CurrentSettings.uuid)
2017-08-17 22:00:37 +05:30
expect(subject[:version]).to eq(Gitlab::VERSION)
2018-11-08 19:23:39 +05:30
expect(subject[:installation_type]).to eq(Gitlab::INSTALLATION_TYPE)
2017-08-17 22:00:37 +05:30
expect(subject[:active_user_count]).to eq(User.active.count)
expect(subject[:recorded_at]).to be_a(Time)
end
end
2018-11-20 20:47:30 +05:30
describe '#count' do
let(:relation) { double(:relation) }
it 'returns the count when counting succeeds' do
allow(relation).to receive(:count).and_return(1)
expect(described_class.count(relation)).to eq(1)
end
it 'returns the fallback value when counting fails' do
allow(relation).to receive(:count).and_raise(ActiveRecord::StatementInvalid.new(''))
expect(described_class.count(relation, fallback: 15)).to eq(15)
end
end
2017-08-17 22:00:37 +05:30
end