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

353 lines
14 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
describe Gitlab::UsageData do
2019-12-04 20:38:33 +05:30
let(:projects) { create_list(:project, 4) }
2017-09-10 17:25:29 +05:30
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])
2019-12-04 20:38:33 +05:30
create(:jira_service, :without_properties_callback, project: projects[1])
2019-09-30 21:07:59 +05:30
create(:jira_service, :jira_cloud_service, project: projects[2])
2019-12-04 20:38:33 +05:30
create(:jira_service, :without_properties_callback, project: projects[3],
properties: { url: 'https://mysite.atlassian.net' })
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)
2019-12-26 22:10:19 +05:30
create(:service, project: projects[2], type: 'MattermostService', active: true)
create(:service, project: projects[2], type: 'JenkinsService', active: true)
create(:service, project: projects[2], type: 'CustomIssueTrackerService', active: true)
2019-07-07 11:18:12 +05:30
create(:project_error_tracking_setting, project: projects[0])
create(:project_error_tracking_setting, project: projects[1], enabled: false)
2019-12-26 22:10:19 +05:30
create_list(:issue, 4, project: projects[0])
create(:zoom_meeting, project: projects[0], issue: projects[0].issues[0], issue_status: :added)
create_list(:zoom_meeting, 2, project: projects[0], issue: projects[0].issues[1], issue_status: :removed)
create(:zoom_meeting, project: projects[0], issue: projects[0].issues[2], issue_status: :added)
create_list(:zoom_meeting, 2, project: projects[0], issue: projects[0].issues[2], issue_status: :removed)
2018-05-09 12:01:36 +05:30
2019-12-26 22:10:19 +05:30
# Enabled clusters
gcp_cluster = create(:cluster_provider_gcp, :created).cluster
create(:cluster_provider_aws, :created)
create(:cluster_platform_kubernetes)
2019-02-15 15:39:39 +05:30
create(:cluster, :group)
2019-12-26 22:10:19 +05:30
# Disabled clusters
create(:cluster, :disabled)
2019-02-15 15:39:39 +05:30
create(:cluster, :group, :disabled)
create(:cluster, :group, :disabled)
2019-12-26 22:10:19 +05:30
# Applications
2018-05-09 12:01:36 +05:30
create(:clusters_applications_helm, :installed, cluster: gcp_cluster)
create(:clusters_applications_ingress, :installed, cluster: gcp_cluster)
2019-10-12 21:52:04 +05:30
create(:clusters_applications_cert_manager, :installed, cluster: gcp_cluster)
2018-05-09 12:01:36 +05:30
create(:clusters_applications_prometheus, :installed, cluster: gcp_cluster)
2019-12-26 22:10:19 +05:30
create(:clusters_applications_crossplane, :installed, cluster: gcp_cluster)
2018-05-09 12:01:36 +05:30
create(:clusters_applications_runner, :installed, cluster: gcp_cluster)
2018-12-13 13:39:08 +05:30
create(:clusters_applications_knative, :installed, cluster: gcp_cluster)
2019-12-26 22:10:19 +05:30
create(:clusters_applications_elastic_stack, :installed, cluster: gcp_cluster)
create(:grafana_integration, project: projects[0], enabled: true)
create(:grafana_integration, project: projects[1], enabled: true)
create(:grafana_integration, project: projects[2], enabled: false)
2019-03-02 22:35:43 +05:30
ProjectFeature.first.update_attribute('repository_access_level', 0)
2017-09-10 17:25:29 +05:30
end
2017-08-17 22:00:37 +05:30
subject { described_class.data }
2019-12-21 20:55:43 +05:30
it 'gathers usage data', :aggregate_failures do
2019-09-04 21:01:54 +05:30
expect(subject.keys).to include(*%i(
2017-08-17 22:00:37 +05:30
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
2019-12-21 20:55:43 +05:30
dependency_proxy_enabled
2018-11-08 19:23:39 +05:30
gitlab_shared_runners_enabled
2018-03-17 18:26:18 +05:30
gitlab_pages
git
2019-09-30 21:07:59 +05:30
gitaly
2018-03-17 18:26:18 +05:30
database
2018-03-27 19:54:05 +05:30
avg_cycle_analytics
2019-07-31 22:56:46 +05:30
influxdb_metrics_enabled
prometheus_metrics_enabled
2019-12-26 22:10:19 +05:30
web_ide_clientside_preview_enabled
ingress_modsecurity_enabled
2017-08-17 22:00:37 +05:30
))
end
2019-12-04 20:38:33 +05:30
it 'gathers usage counts' do
2019-12-21 20:55:43 +05:30
smau_keys = %i(
snippet_create
snippet_update
snippet_comment
merge_request_comment
merge_request_create
commit_comment
wiki_pages_create
wiki_pages_update
wiki_pages_delete
web_ide_views
web_ide_commits
web_ide_merge_requests
2019-12-26 22:10:19 +05:30
web_ide_previews
2019-12-21 20:55:43 +05:30
navbar_searches
cycle_analytics_views
productivity_analytics_views
source_code_pushes
)
2019-09-04 21:01:54 +05:30
expected_keys = %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
2019-07-07 11:18:12 +05:30
successful_deployments
failed_deployments
2017-08-17 22:00:37 +05:30
environments
2018-03-17 18:26:18 +05:30
clusters
clusters_enabled
2019-02-15 15:39:39 +05:30
project_clusters_enabled
group_clusters_enabled
2018-03-17 18:26:18 +05:30
clusters_disabled
2019-02-15 15:39:39 +05:30
project_clusters_disabled
group_clusters_disabled
2019-12-26 22:10:19 +05:30
clusters_platforms_eks
2018-05-09 12:01:36 +05:30
clusters_platforms_gke
clusters_platforms_user
clusters_applications_helm
clusters_applications_ingress
2019-02-15 15:39:39 +05:30
clusters_applications_cert_managers
2018-05-09 12:01:36 +05:30
clusters_applications_prometheus
2019-12-26 22:10:19 +05:30
clusters_applications_crossplane
2018-05-09 12:01:36 +05:30
clusters_applications_runner
2018-12-13 13:39:08 +05:30
clusters_applications_knative
2019-12-26 22:10:19 +05:30
clusters_applications_elastic_stack
2017-09-10 17:25:29 +05:30
in_review_folder
2019-12-26 22:10:19 +05:30
grafana_integrated_projects
2017-08-17 22:00:37 +05:30
groups
issues
2019-12-26 22:10:19 +05:30
issues_with_associated_zoom_link
issues_using_zoom_quick_actions
2017-08-17 22:00:37 +05:30
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
2019-09-04 21:01:54 +05:30
pool_repositories
2017-08-17 22:00:37 +05:30
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
2019-12-26 22:10:19 +05:30
projects_custom_issue_tracker_active
projects_jenkins_active
projects_mattermost_active
2017-08-17 22:00:37 +05:30
projects_prometheus_active
2019-03-02 22:35:43 +05:30
projects_with_repositories_enabled
2019-07-07 11:18:12 +05:30
projects_with_error_tracking_enabled
2017-08-17 22:00:37 +05:30
pages_domains
protected_branches
releases
2018-10-15 14:42:47 +05:30
remote_mirrors
2017-08-17 22:00:37 +05:30
snippets
2019-02-15 15:39:39 +05:30
suggestions
2017-08-17 22:00:37 +05:30
todos
uploads
web_hooks
2019-12-21 20:55:43 +05:30
).push(*smau_keys)
2019-09-04 21:01:54 +05:30
count_data = subject[:counts]
expect(count_data[:boards]).to eq(1)
2019-12-04 20:38:33 +05:30
expect(count_data[:projects]).to eq(4)
2019-12-21 20:55:43 +05:30
expect(count_data.values_at(*smau_keys)).to all(be_an(Integer))
2019-09-04 21:01:54 +05:30
expect(count_data.keys).to include(*expected_keys)
expect(expected_keys - count_data.keys).to be_empty
2017-08-17 22:00:37 +05:30
end
2017-09-10 17:25:29 +05:30
2019-12-21 20:55:43 +05:30
it 'gathers projects data correctly', :aggregate_failures do
2017-09-10 17:25:29 +05:30
count_data = subject[:counts]
2019-12-04 20:38:33 +05:30
expect(count_data[:projects]).to eq(4)
2017-09-10 17:25:29 +05:30
expect(count_data[:projects_prometheus_active]).to eq(1)
2019-12-04 20:38:33 +05:30
expect(count_data[:projects_jira_active]).to eq(4)
2018-12-13 13:39:08 +05:30
expect(count_data[:projects_jira_server_active]).to eq(2)
2019-12-04 20:38:33 +05:30
expect(count_data[:projects_jira_cloud_active]).to eq(2)
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)
2019-12-26 22:10:19 +05:30
expect(count_data[:projects_custom_issue_tracker_active]).to eq(1)
expect(count_data[:projects_jenkins_active]).to eq(1)
expect(count_data[:projects_mattermost_active]).to eq(1)
2019-12-04 20:38:33 +05:30
expect(count_data[:projects_with_repositories_enabled]).to eq(3)
2019-07-07 11:18:12 +05:30
expect(count_data[:projects_with_error_tracking_enabled]).to eq(1)
2019-12-26 22:10:19 +05:30
expect(count_data[:issues_with_associated_zoom_link]).to eq(2)
expect(count_data[:issues_using_zoom_quick_actions]).to eq(3)
2018-05-09 12:01:36 +05:30
2019-12-26 22:10:19 +05:30
expect(count_data[:clusters_enabled]).to eq(4)
expect(count_data[:project_clusters_enabled]).to eq(3)
2019-02-15 15:39:39 +05:30
expect(count_data[:group_clusters_enabled]).to eq(1)
expect(count_data[:clusters_disabled]).to eq(3)
expect(count_data[:project_clusters_disabled]).to eq(1)
expect(count_data[:group_clusters_disabled]).to eq(2)
expect(count_data[:group_clusters_enabled]).to eq(1)
2019-12-26 22:10:19 +05:30
expect(count_data[:clusters_platforms_eks]).to eq(1)
2018-05-09 12:01:36 +05:30
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)
2019-02-15 15:39:39 +05:30
expect(count_data[:clusters_applications_cert_managers]).to eq(1)
2019-12-26 22:10:19 +05:30
expect(count_data[:clusters_applications_crossplane]).to eq(1)
2018-05-09 12:01:36 +05:30
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)
2019-12-26 22:10:19 +05:30
expect(count_data[:clusters_applications_elastic_stack]).to eq(1)
expect(count_data[:grafana_integrated_projects]).to eq(2)
2018-12-13 13:39:08 +05:30
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
2019-10-12 21:52:04 +05:30
describe '#usage_data_counters' do
subject { described_class.usage_data_counters }
it { is_expected.to all(respond_to :totals) }
describe 'the results of calling #totals on all objects in the array' do
subject { described_class.usage_data_counters.map(&:totals) }
2019-12-21 20:55:43 +05:30
it { is_expected.to all(be_a Hash) }
it { is_expected.to all(have_attributes(keys: all(be_a Symbol), values: all(be_a Integer))) }
2019-10-12 21:52:04 +05:30
end
it 'does not have any conflicts' do
all_keys = subject.flat_map { |counter| counter.totals.keys }
expect(all_keys.size).to eq all_keys.to_set.size
end
end
2018-03-17 18:26:18 +05:30
describe '#features_usage_data_ce' do
subject { described_class.features_usage_data_ce }
2019-12-21 20:55:43 +05:30
it 'gathers feature usage data', :aggregate_failures 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)
2019-12-21 20:55:43 +05:30
expect(subject[:dependency_proxy_enabled]).to eq(Gitlab.config.dependency_proxy.enabled)
2018-11-08 19:23:39 +05:30
expect(subject[:gitlab_shared_runners_enabled]).to eq(Gitlab.config.gitlab_ci.shared_runners_enabled)
2019-12-26 22:10:19 +05:30
expect(subject[:web_ide_clientside_preview_enabled]).to eq(Gitlab::CurrentSettings.web_ide_clientside_preview_enabled?)
2018-03-17 18:26:18 +05:30
end
end
describe '#components_usage_data' do
subject { described_class.components_usage_data }
2019-12-21 20:55:43 +05:30
it 'gathers components usage data', :aggregate_failures do
2018-03-17 18:26:18 +05:30
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)
2019-09-30 21:07:59 +05:30
expect(subject[:gitaly][:version]).to be_present
expect(subject[:gitaly][:servers]).to be >= 1
expect(subject[:gitaly][:filesystems]).to be_an(Array)
expect(subject[:gitaly][:filesystems].first).to be_a(String)
2018-03-17 18:26:18 +05:30
end
end
2017-08-17 22:00:37 +05:30
describe '#license_usage_data' do
subject { described_class.license_usage_data }
2019-12-21 20:55:43 +05:30
it 'gathers license data', :aggregate_failures 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)
2019-09-04 21:01:54 +05:30
expect(subject[:installation_type]).to eq('gitlab-development-kit')
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
2019-12-04 20:38:33 +05:30
it 'returns the count for count_by when provided' do
allow(relation).to receive(:count).with(:creator_id).and_return(2)
expect(described_class.count(relation, count_by: :creator_id)).to eq(2)
end
2018-11-20 20:47:30 +05:30
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
2019-02-15 15:39:39 +05:30
describe '#approximate_counts' do
2019-12-21 20:55:43 +05:30
it 'gets approximate counts for selected models', :aggregate_failures do
2019-02-15 15:39:39 +05:30
create(:label)
expect(Gitlab::Database::Count).to receive(:approximate_counts)
2019-12-21 20:55:43 +05:30
.with(described_class::APPROXIMATE_COUNT_MODELS).once.and_call_original
2019-02-15 15:39:39 +05:30
counts = described_class.approximate_counts.values
expect(counts.count).to eq(described_class::APPROXIMATE_COUNT_MODELS.count)
expect(counts.any? { |count| count < 0 }).to be_falsey
end
2019-12-21 20:55:43 +05:30
it 'returns default values if counts can not be retrieved', :aggregate_failures do
2019-02-15 15:39:39 +05:30
described_class::APPROXIMATE_COUNT_MODELS.map do |model|
model.name.underscore.pluralize.to_sym
end
2019-12-21 20:55:43 +05:30
expect(Gitlab::Database::Count).to receive(:approximate_counts).and_return({})
2019-02-15 15:39:39 +05:30
expect(described_class.approximate_counts.values.uniq).to eq([-1])
end
end
2017-08-17 22:00:37 +05:30
end