2017-04-05 08:29:48 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::UsageData do
|
2017-07-19 10:45:28 -04:00
|
|
|
let(:projects) { create_list(:project, 3) }
|
|
|
|
let!(:board) { create(:board, project: projects[0]) }
|
2017-04-05 08:29:48 -04:00
|
|
|
|
|
|
|
describe '#data' do
|
2017-07-19 10:45:28 -04:00
|
|
|
before do
|
|
|
|
create(:jira_service, project: projects[0])
|
|
|
|
create(:jira_service, project: projects[1])
|
2019-07-11 05:53:08 -04:00
|
|
|
create(:jira_service, :jira_cloud_service, project: projects[2])
|
2017-07-19 10:45:28 -04:00
|
|
|
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-03-25 03:42:08 -04:00
|
|
|
create(:project_error_tracking_setting, project: projects[0])
|
|
|
|
create(:project_error_tracking_setting, project: projects[1], enabled: false)
|
2018-03-27 08:16:50 -04:00
|
|
|
|
|
|
|
gcp_cluster = create(:cluster, :provided_by_gcp)
|
|
|
|
create(:cluster, :provided_by_user)
|
|
|
|
create(:cluster, :provided_by_user, :disabled)
|
2018-12-05 08:48:28 -05:00
|
|
|
create(:cluster, :group)
|
|
|
|
create(:cluster, :group, :disabled)
|
|
|
|
create(:cluster, :group, :disabled)
|
2018-03-27 08:16:50 -04:00
|
|
|
create(:clusters_applications_helm, :installed, cluster: gcp_cluster)
|
|
|
|
create(:clusters_applications_ingress, :installed, cluster: gcp_cluster)
|
2018-11-19 15:45:33 -05:00
|
|
|
create(:clusters_applications_cert_managers, :installed, cluster: gcp_cluster)
|
2018-03-27 08:16:50 -04:00
|
|
|
create(:clusters_applications_prometheus, :installed, cluster: gcp_cluster)
|
|
|
|
create(:clusters_applications_runner, :installed, cluster: gcp_cluster)
|
2018-11-01 11:14:49 -04:00
|
|
|
create(:clusters_applications_knative, :installed, cluster: gcp_cluster)
|
2019-01-31 07:29:26 -05:00
|
|
|
|
|
|
|
ProjectFeature.first.update_attribute('repository_access_level', 0)
|
2017-07-19 10:45:28 -04:00
|
|
|
end
|
|
|
|
|
2017-05-01 11:13:33 -04:00
|
|
|
subject { described_class.data }
|
2017-04-05 08:29:48 -04:00
|
|
|
|
|
|
|
it "gathers usage data" do
|
2019-05-09 12:32:18 -04:00
|
|
|
expect(subject.keys).to include(*%i(
|
2017-04-05 08:29:48 -04:00
|
|
|
active_user_count
|
|
|
|
counts
|
|
|
|
recorded_at
|
2017-04-06 15:16:57 -04:00
|
|
|
edition
|
2017-04-05 08:49:22 -04:00
|
|
|
version
|
2018-06-07 11:01:20 -04:00
|
|
|
installation_type
|
2017-04-05 08:49:22 -04:00
|
|
|
uuid
|
2017-05-09 15:58:22 -04:00
|
|
|
hostname
|
2018-06-20 13:16:14 -04:00
|
|
|
mattermost_enabled
|
|
|
|
signup_enabled
|
|
|
|
ldap_enabled
|
|
|
|
gravatar_enabled
|
|
|
|
omniauth_enabled
|
|
|
|
reply_by_email_enabled
|
|
|
|
container_registry_enabled
|
|
|
|
gitlab_shared_runners_enabled
|
2017-09-15 12:23:56 -04:00
|
|
|
gitlab_pages
|
|
|
|
git
|
2019-06-20 07:04:56 -04:00
|
|
|
gitaly
|
2017-09-15 12:23:56 -04:00
|
|
|
database
|
2018-02-13 11:52:00 -05:00
|
|
|
avg_cycle_analytics
|
2018-10-01 07:15:31 -04:00
|
|
|
web_ide_commits
|
2019-04-10 13:22:05 -04:00
|
|
|
influxdb_metrics_enabled
|
|
|
|
prometheus_metrics_enabled
|
2017-04-05 08:29:48 -04:00
|
|
|
))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "gathers usage counts" do
|
2019-05-17 05:10:29 -04:00
|
|
|
expected_keys = %i(
|
2018-08-14 15:44:17 -04:00
|
|
|
assignee_lists
|
2017-04-05 08:29:48 -04:00
|
|
|
boards
|
|
|
|
ci_builds
|
2017-06-19 13:56:27 -04:00
|
|
|
ci_internal_pipelines
|
|
|
|
ci_external_pipelines
|
2017-09-08 13:38:02 -04:00
|
|
|
ci_pipeline_config_auto_devops
|
|
|
|
ci_pipeline_config_repository
|
2017-04-05 08:29:48 -04:00
|
|
|
ci_runners
|
|
|
|
ci_triggers
|
2017-05-07 18:35:56 -04:00
|
|
|
ci_pipeline_schedules
|
2017-09-12 06:33:48 -04:00
|
|
|
auto_devops_enabled
|
|
|
|
auto_devops_disabled
|
2017-04-05 08:29:48 -04:00
|
|
|
deploy_keys
|
|
|
|
deployments
|
2019-03-07 12:08:29 -05:00
|
|
|
successful_deployments
|
|
|
|
failed_deployments
|
2017-04-05 08:29:48 -04:00
|
|
|
environments
|
2017-11-01 03:12:44 -04:00
|
|
|
clusters
|
|
|
|
clusters_enabled
|
2018-12-05 08:48:28 -05:00
|
|
|
project_clusters_enabled
|
|
|
|
group_clusters_enabled
|
2017-11-01 03:12:44 -04:00
|
|
|
clusters_disabled
|
2018-12-05 08:48:28 -05:00
|
|
|
project_clusters_disabled
|
|
|
|
group_clusters_disabled
|
2018-03-26 15:54:13 -04:00
|
|
|
clusters_platforms_gke
|
|
|
|
clusters_platforms_user
|
|
|
|
clusters_applications_helm
|
|
|
|
clusters_applications_ingress
|
2018-11-19 15:45:33 -05:00
|
|
|
clusters_applications_cert_managers
|
2018-03-26 15:54:13 -04:00
|
|
|
clusters_applications_prometheus
|
|
|
|
clusters_applications_runner
|
2018-11-01 11:14:49 -04:00
|
|
|
clusters_applications_knative
|
2017-06-15 06:50:45 -04:00
|
|
|
in_review_folder
|
2017-04-05 08:29:48 -04:00
|
|
|
groups
|
|
|
|
issues
|
|
|
|
keys
|
2018-08-14 15:44:17 -04:00
|
|
|
label_lists
|
2017-04-05 08:29:48 -04:00
|
|
|
labels
|
|
|
|
lfs_objects
|
|
|
|
merge_requests
|
2018-08-14 15:44:17 -04:00
|
|
|
milestone_lists
|
2017-04-05 08:29:48 -04:00
|
|
|
milestones
|
|
|
|
notes
|
2019-05-17 05:10:29 -04:00
|
|
|
pool_repositories
|
2017-04-05 08:29:48 -04:00
|
|
|
projects
|
2017-07-19 03:07:17 -04:00
|
|
|
projects_imported_from_github
|
2017-07-19 10:45:28 -04:00
|
|
|
projects_jira_active
|
2018-11-03 20:37:47 -04:00
|
|
|
projects_jira_server_active
|
|
|
|
projects_jira_cloud_active
|
2017-07-19 10:45:28 -04:00
|
|
|
projects_slack_notifications_active
|
|
|
|
projects_slack_slash_active
|
2017-04-06 15:52:08 -04:00
|
|
|
projects_prometheus_active
|
2019-01-31 07:29:26 -05:00
|
|
|
projects_with_repositories_enabled
|
2019-03-25 03:42:08 -04:00
|
|
|
projects_with_error_tracking_enabled
|
2017-04-05 08:29:48 -04:00
|
|
|
pages_domains
|
|
|
|
protected_branches
|
|
|
|
releases
|
2018-05-03 08:55:14 -04:00
|
|
|
remote_mirrors
|
2017-04-05 08:29:48 -04:00
|
|
|
snippets
|
2018-12-13 14:17:19 -05:00
|
|
|
suggestions
|
2017-04-05 08:29:48 -04:00
|
|
|
todos
|
2017-03-09 11:00:25 -05:00
|
|
|
uploads
|
2017-04-05 08:29:48 -04:00
|
|
|
web_hooks
|
2019-02-06 12:56:16 -05:00
|
|
|
user_preferences
|
2019-05-17 05:10:29 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
count_data = subject[:counts]
|
|
|
|
|
|
|
|
expect(count_data[:boards]).to eq(1)
|
|
|
|
expect(count_data[:projects]).to eq(3)
|
|
|
|
expect(count_data.keys).to include(*expected_keys)
|
|
|
|
expect(expected_keys - count_data.keys).to be_empty
|
2017-04-05 08:29:48 -04:00
|
|
|
end
|
2017-07-19 10:45:28 -04:00
|
|
|
|
2019-02-08 06:22:11 -05:00
|
|
|
it 'does not gather user preferences usage data when the feature is disabled' do
|
|
|
|
stub_feature_flags(group_overview_security_dashboard: false)
|
|
|
|
expect(subject[:counts].keys).not_to include(:user_preferences)
|
|
|
|
end
|
|
|
|
|
2017-07-19 10:45:28 -04:00
|
|
|
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-11-03 20:37:47 -04:00
|
|
|
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-07-19 10:45:28 -04:00
|
|
|
expect(count_data[:projects_slack_notifications_active]).to eq(2)
|
|
|
|
expect(count_data[:projects_slack_slash_active]).to eq(1)
|
2019-01-31 07:29:26 -05:00
|
|
|
expect(count_data[:projects_with_repositories_enabled]).to eq(2)
|
2019-03-25 03:42:08 -04:00
|
|
|
expect(count_data[:projects_with_error_tracking_enabled]).to eq(1)
|
2018-03-27 08:16:50 -04:00
|
|
|
|
2018-12-05 08:48:28 -05:00
|
|
|
expect(count_data[:clusters_enabled]).to eq(7)
|
|
|
|
expect(count_data[:project_clusters_enabled]).to eq(6)
|
|
|
|
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)
|
2018-03-27 08:16:50 -04:00
|
|
|
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)
|
2018-11-19 15:45:33 -05:00
|
|
|
expect(count_data[:clusters_applications_cert_managers]).to eq(1)
|
2018-03-27 08:16:50 -04:00
|
|
|
expect(count_data[:clusters_applications_prometheus]).to eq(1)
|
|
|
|
expect(count_data[:clusters_applications_runner]).to eq(1)
|
2018-11-01 11:14:49 -04:00
|
|
|
expect(count_data[:clusters_applications_knative]).to eq(1)
|
2017-07-19 10:45:28 -04:00
|
|
|
end
|
2018-10-15 05:39:09 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
end
|
2017-04-05 08:29:48 -04:00
|
|
|
end
|
|
|
|
|
2017-09-15 12:23:56 -04:00
|
|
|
describe '#features_usage_data_ce' do
|
|
|
|
subject { described_class.features_usage_data_ce }
|
|
|
|
|
|
|
|
it 'gathers feature usage data' do
|
2018-06-20 13:16:14 -04:00
|
|
|
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-07-13 06:39:31 -04:00
|
|
|
expect(subject[:omniauth_enabled]).to eq(Gitlab::Auth.omniauth_enabled?)
|
2018-06-20 13:16:14 -04:00
|
|
|
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)
|
2017-09-15 12:23:56 -04:00
|
|
|
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)
|
2019-06-20 07:04:56 -04:00
|
|
|
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)
|
2017-09-15 12:23:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-05 08:29:48 -04:00
|
|
|
describe '#license_usage_data' do
|
2017-05-01 11:13:33 -04:00
|
|
|
subject { described_class.license_usage_data }
|
2017-04-05 08:29:48 -04:00
|
|
|
|
|
|
|
it "gathers license data" do
|
2018-02-02 13:39:55 -05:00
|
|
|
expect(subject[:uuid]).to eq(Gitlab::CurrentSettings.uuid)
|
2017-04-05 08:29:48 -04:00
|
|
|
expect(subject[:version]).to eq(Gitlab::VERSION)
|
2019-05-17 05:10:29 -04:00
|
|
|
expect(subject[:installation_type]).to eq('gitlab-development-kit')
|
2017-04-05 08:29:48 -04:00
|
|
|
expect(subject[:active_user_count]).to eq(User.active.count)
|
|
|
|
expect(subject[:recorded_at]).to be_a(Time)
|
|
|
|
end
|
|
|
|
end
|
2018-09-05 08:34:59 -04:00
|
|
|
|
|
|
|
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
|
2018-12-06 11:07:14 -05:00
|
|
|
|
|
|
|
describe '#approximate_counts' do
|
|
|
|
it 'gets approximate counts for selected models' do
|
|
|
|
create(:label)
|
|
|
|
|
|
|
|
expect(Gitlab::Database::Count).to receive(:approximate_counts)
|
|
|
|
.with(described_class::APPROXIMATE_COUNT_MODELS).once.and_call_original
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
it 'returns default values if counts can not be retrieved' do
|
|
|
|
described_class::APPROXIMATE_COUNT_MODELS.map do |model|
|
|
|
|
model.name.underscore.pluralize.to_sym
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(Gitlab::Database::Count).to receive(:approximate_counts)
|
|
|
|
.and_return({})
|
|
|
|
|
|
|
|
expect(described_class.approximate_counts.values.uniq).to eq([-1])
|
|
|
|
end
|
|
|
|
end
|
2017-04-05 08:29:48 -04:00
|
|
|
end
|