2019-08-16 15:56:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-05 12:29:48 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Gitlab::UsageData, :aggregate_failures do
|
2020-03-18 15:09:45 +00:00
|
|
|
include UsageDataHelpers
|
2017-04-05 12:29:48 +00:00
|
|
|
|
2020-02-17 18:09:00 +00:00
|
|
|
before do
|
2020-06-03 12:08:21 +00:00
|
|
|
stub_usage_data_connections
|
2020-04-29 15:09:58 +00:00
|
|
|
stub_object_store_settings
|
2020-10-14 06:08:33 +00:00
|
|
|
clear_memoized_values(described_class::CE_MEMOIZED_VALUES)
|
2020-02-17 18:09:00 +00:00
|
|
|
end
|
2020-03-18 15:09:45 +00:00
|
|
|
|
2020-06-19 12:09:07 +00:00
|
|
|
describe '.uncached_data' do
|
2020-10-22 15:08:25 +00:00
|
|
|
subject { described_class.uncached_data }
|
|
|
|
|
|
|
|
it 'includes basic top and second level keys' do
|
|
|
|
is_expected.to include(:counts)
|
|
|
|
is_expected.to include(:counts_monthly)
|
|
|
|
is_expected.to include(:counts_weekly)
|
|
|
|
is_expected.to include(:license)
|
|
|
|
is_expected.to include(:settings)
|
|
|
|
|
|
|
|
# usage_activity_by_stage data
|
|
|
|
is_expected.to include(:usage_activity_by_stage)
|
|
|
|
is_expected.to include(:usage_activity_by_stage_monthly)
|
|
|
|
expect(subject[:usage_activity_by_stage])
|
|
|
|
.to include(:configure, :create, :manage, :monitor, :plan, :release, :verify)
|
|
|
|
expect(subject[:usage_activity_by_stage_monthly])
|
|
|
|
.to include(:configure, :create, :manage, :monitor, :plan, :release, :verify)
|
|
|
|
expect(subject[:usage_activity_by_stage][:create])
|
|
|
|
.not_to include(:merge_requests_users)
|
|
|
|
expect(subject[:usage_activity_by_stage_monthly][:create])
|
|
|
|
.to include(:merge_requests_users)
|
2020-11-04 15:08:41 +00:00
|
|
|
expect(subject[:counts_weekly]).to include(:aggregated_metrics)
|
|
|
|
expect(subject[:counts_monthly]).to include(:aggregated_metrics)
|
2020-10-22 15:08:25 +00:00
|
|
|
end
|
2020-07-08 09:09:17 +00:00
|
|
|
|
2020-10-22 15:08:25 +00:00
|
|
|
it 'clears memoized values' do
|
|
|
|
allow(described_class).to receive(:clear_memoization)
|
2020-10-14 06:08:33 +00:00
|
|
|
|
2020-10-22 15:08:25 +00:00
|
|
|
subject
|
2020-07-08 09:09:17 +00:00
|
|
|
|
2020-10-22 15:08:25 +00:00
|
|
|
described_class::CE_MEMOIZED_VALUES.each do |key|
|
|
|
|
expect(described_class).to have_received(:clear_memoization).with(key)
|
2020-06-19 12:09:07 +00:00
|
|
|
end
|
2020-08-06 00:09:53 +00:00
|
|
|
end
|
2020-07-07 21:09:13 +00:00
|
|
|
|
2020-08-06 00:09:53 +00:00
|
|
|
it 'ensures recorded_at is set before any other usage data calculation' do
|
|
|
|
%i(alt_usage_data redis_usage_data distinct_count count).each do |method|
|
|
|
|
expect(described_class).not_to receive(method)
|
|
|
|
end
|
|
|
|
expect(described_class).to receive(:recorded_at).and_raise(Exception.new('Stopped calculating recorded_at'))
|
2020-07-13 18:09:16 +00:00
|
|
|
|
2020-10-22 15:08:25 +00:00
|
|
|
expect { subject }.to raise_error('Stopped calculating recorded_at')
|
2020-08-06 00:09:53 +00:00
|
|
|
end
|
2020-12-21 15:10:05 +00:00
|
|
|
|
|
|
|
context 'when generating usage ping in critical weeks' do
|
|
|
|
it 'does not raise error when generated in last week of the year' do
|
|
|
|
travel_to(DateTime.parse('2020-12-29')) do
|
|
|
|
expect { subject }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not raise error when generated in first week of the year' do
|
|
|
|
travel_to(DateTime.parse('2021-01-01')) do
|
|
|
|
expect { subject }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not raise error when generated in second week of the year' do
|
|
|
|
travel_to(DateTime.parse('2021-01-07')) do
|
|
|
|
expect { subject }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not raise error when generated in 3rd week of the year' do
|
|
|
|
travel_to(DateTime.parse('2021-01-14')) do
|
|
|
|
expect { subject }.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-08-06 00:09:53 +00:00
|
|
|
end
|
2020-07-13 18:09:16 +00:00
|
|
|
|
2020-08-24 09:10:14 +00:00
|
|
|
describe 'usage_activity_by_stage_package' do
|
|
|
|
it 'includes accurate usage_activity_by_stage data' do
|
|
|
|
for_defined_days_back do
|
|
|
|
create(:project, packages: [create(:package)] )
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(described_class.usage_activity_by_stage_package({})).to eq(
|
|
|
|
projects_with_packages: 2
|
|
|
|
)
|
|
|
|
expect(described_class.usage_activity_by_stage_package(described_class.last_28_days_time_period)).to eq(
|
|
|
|
projects_with_packages: 1
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-06 00:09:53 +00:00
|
|
|
describe '.usage_activity_by_stage_configure' do
|
|
|
|
it 'includes accurate usage_activity_by_stage data' do
|
|
|
|
for_defined_days_back do
|
|
|
|
user = create(:user)
|
|
|
|
cluster = create(:cluster, user: user)
|
|
|
|
create(:clusters_applications_cert_manager, :installed, cluster: cluster)
|
|
|
|
create(:clusters_applications_helm, :installed, cluster: cluster)
|
|
|
|
create(:clusters_applications_ingress, :installed, cluster: cluster)
|
|
|
|
create(:clusters_applications_knative, :installed, cluster: cluster)
|
|
|
|
create(:cluster, :disabled, user: user)
|
|
|
|
create(:cluster_provider_gcp, :created)
|
|
|
|
create(:cluster_provider_aws, :created)
|
|
|
|
create(:cluster_platform_kubernetes)
|
|
|
|
create(:cluster, :group, :disabled, user: user)
|
|
|
|
create(:cluster, :group, user: user)
|
|
|
|
create(:cluster, :instance, :disabled, :production_environment)
|
|
|
|
create(:cluster, :instance, :production_environment)
|
|
|
|
create(:cluster, :management_project)
|
2020-07-13 18:09:16 +00:00
|
|
|
end
|
|
|
|
|
2020-08-06 00:09:53 +00:00
|
|
|
expect(described_class.usage_activity_by_stage_configure({})).to include(
|
|
|
|
clusters_applications_cert_managers: 2,
|
|
|
|
clusters_applications_helm: 2,
|
|
|
|
clusters_applications_ingress: 2,
|
|
|
|
clusters_applications_knative: 2,
|
|
|
|
clusters_management_project: 2,
|
|
|
|
clusters_disabled: 4,
|
|
|
|
clusters_enabled: 12,
|
|
|
|
clusters_platforms_gke: 2,
|
|
|
|
clusters_platforms_eks: 2,
|
|
|
|
clusters_platforms_user: 2,
|
|
|
|
instance_clusters_disabled: 2,
|
|
|
|
instance_clusters_enabled: 2,
|
|
|
|
group_clusters_disabled: 2,
|
|
|
|
group_clusters_enabled: 2,
|
|
|
|
project_clusters_disabled: 2,
|
|
|
|
project_clusters_enabled: 10
|
|
|
|
)
|
|
|
|
expect(described_class.usage_activity_by_stage_configure(described_class.last_28_days_time_period)).to include(
|
|
|
|
clusters_applications_cert_managers: 1,
|
|
|
|
clusters_applications_helm: 1,
|
|
|
|
clusters_applications_ingress: 1,
|
|
|
|
clusters_applications_knative: 1,
|
|
|
|
clusters_management_project: 1,
|
|
|
|
clusters_disabled: 2,
|
|
|
|
clusters_enabled: 6,
|
|
|
|
clusters_platforms_gke: 1,
|
|
|
|
clusters_platforms_eks: 1,
|
|
|
|
clusters_platforms_user: 1,
|
|
|
|
instance_clusters_disabled: 1,
|
|
|
|
instance_clusters_enabled: 1,
|
|
|
|
group_clusters_disabled: 1,
|
|
|
|
group_clusters_enabled: 1,
|
|
|
|
project_clusters_disabled: 1,
|
|
|
|
project_clusters_enabled: 5
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2020-07-07 21:09:13 +00:00
|
|
|
|
2020-08-06 00:09:53 +00:00
|
|
|
describe 'usage_activity_by_stage_create' do
|
|
|
|
it 'includes accurate usage_activity_by_stage data' do
|
|
|
|
for_defined_days_back do
|
|
|
|
user = create(:user)
|
|
|
|
project = create(:project, :repository_private,
|
|
|
|
:test_repo, :remote_mirror, creator: user)
|
|
|
|
create(:merge_request, source_project: project)
|
|
|
|
create(:deploy_key, user: user)
|
|
|
|
create(:key, user: user)
|
|
|
|
create(:project, creator: user, disable_overriding_approvers_per_merge_request: true)
|
|
|
|
create(:project, creator: user, disable_overriding_approvers_per_merge_request: false)
|
2021-03-24 21:09:02 +00:00
|
|
|
create(:remote_mirror, project: project, enabled: true)
|
|
|
|
another_user = create(:user)
|
|
|
|
another_project = create(:project, :repository, creator: another_user)
|
|
|
|
create(:remote_mirror, project: another_project, enabled: false)
|
2020-08-06 00:09:53 +00:00
|
|
|
create(:snippet, author: user)
|
2021-05-04 12:10:04 +00:00
|
|
|
create(:suggestion, note: create(:note, project: project))
|
2020-07-07 21:09:13 +00:00
|
|
|
end
|
2020-07-09 03:09:01 +00:00
|
|
|
|
2020-08-06 00:09:53 +00:00
|
|
|
expect(described_class.usage_activity_by_stage_create({})).to include(
|
|
|
|
deploy_keys: 2,
|
|
|
|
keys: 2,
|
|
|
|
merge_requests: 2,
|
|
|
|
projects_with_disable_overriding_approvers_per_merge_request: 2,
|
2021-03-24 21:09:02 +00:00
|
|
|
projects_without_disable_overriding_approvers_per_merge_request: 6,
|
2020-08-06 00:09:53 +00:00
|
|
|
remote_mirrors: 2,
|
2021-05-04 12:10:04 +00:00
|
|
|
snippets: 2,
|
|
|
|
suggestions: 2
|
2020-08-06 00:09:53 +00:00
|
|
|
)
|
|
|
|
expect(described_class.usage_activity_by_stage_create(described_class.last_28_days_time_period)).to include(
|
|
|
|
deploy_keys: 1,
|
|
|
|
keys: 1,
|
|
|
|
merge_requests: 1,
|
|
|
|
projects_with_disable_overriding_approvers_per_merge_request: 1,
|
2021-03-24 21:09:02 +00:00
|
|
|
projects_without_disable_overriding_approvers_per_merge_request: 3,
|
2020-08-06 00:09:53 +00:00
|
|
|
remote_mirrors: 1,
|
2021-05-04 12:10:04 +00:00
|
|
|
snippets: 1,
|
|
|
|
suggestions: 1
|
2020-08-06 00:09:53 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'usage_activity_by_stage_manage' do
|
|
|
|
it 'includes accurate usage_activity_by_stage data' do
|
|
|
|
stub_config(
|
|
|
|
omniauth:
|
|
|
|
{ providers: omniauth_providers }
|
|
|
|
)
|
2020-11-17 21:09:19 +00:00
|
|
|
allow(Devise).to receive(:omniauth_providers).and_return(%w(ldapmain ldapsecondary group_saml))
|
2020-08-06 00:09:53 +00:00
|
|
|
|
|
|
|
for_defined_days_back do
|
|
|
|
user = create(:user)
|
2020-09-19 00:09:50 +00:00
|
|
|
user2 = create(:user)
|
2020-08-06 00:09:53 +00:00
|
|
|
create(:event, author: user)
|
|
|
|
create(:group_member, user: user)
|
2020-09-19 00:09:50 +00:00
|
|
|
create(:authentication_event, user: user, provider: :ldapmain, result: :success)
|
|
|
|
create(:authentication_event, user: user2, provider: :ldapsecondary, result: :success)
|
|
|
|
create(:authentication_event, user: user2, provider: :group_saml, result: :success)
|
|
|
|
create(:authentication_event, user: user2, provider: :group_saml, result: :success)
|
|
|
|
create(:authentication_event, user: user, provider: :group_saml, result: :failed)
|
2020-07-13 18:09:16 +00:00
|
|
|
end
|
|
|
|
|
2020-08-06 00:09:53 +00:00
|
|
|
expect(described_class.usage_activity_by_stage_manage({})).to include(
|
|
|
|
events: 2,
|
|
|
|
groups: 2,
|
2020-09-19 00:09:50 +00:00
|
|
|
users_created: 6,
|
|
|
|
omniauth_providers: ['google_oauth2'],
|
2020-11-17 21:09:19 +00:00
|
|
|
user_auth_by_provider: { 'group_saml' => 2, 'ldap' => 4, 'standard' => 0, 'two-factor' => 0, 'two-factor-via-u2f-device' => 0, "two-factor-via-webauthn-device" => 0 }
|
2020-08-06 00:09:53 +00:00
|
|
|
)
|
|
|
|
expect(described_class.usage_activity_by_stage_manage(described_class.last_28_days_time_period)).to include(
|
|
|
|
events: 1,
|
|
|
|
groups: 1,
|
2020-09-19 00:09:50 +00:00
|
|
|
users_created: 3,
|
|
|
|
omniauth_providers: ['google_oauth2'],
|
2020-11-17 21:09:19 +00:00
|
|
|
user_auth_by_provider: { 'group_saml' => 1, 'ldap' => 2, 'standard' => 0, 'two-factor' => 0, 'two-factor-via-u2f-device' => 0, "two-factor-via-webauthn-device" => 0 }
|
2020-08-06 00:09:53 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-02-01 15:08:56 +00:00
|
|
|
it 'includes import gmau usage data' do
|
|
|
|
for_defined_days_back do
|
|
|
|
user = create(:user)
|
|
|
|
group = create(:group)
|
|
|
|
|
|
|
|
group.add_owner(user)
|
|
|
|
|
|
|
|
create(:project, import_type: :github, creator_id: user.id)
|
|
|
|
create(:jira_import_state, :finished, project: create(:project, creator_id: user.id))
|
|
|
|
create(:issue_csv_import, user: user)
|
|
|
|
create(:group_import_state, group: group, user: user)
|
|
|
|
create(:bulk_import, user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(described_class.usage_activity_by_stage_manage({})).to include(
|
|
|
|
unique_users_all_imports: 10
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(described_class.usage_activity_by_stage_manage(described_class.last_28_days_time_period)).to include(
|
|
|
|
unique_users_all_imports: 5
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-08-31 12:10:39 +00:00
|
|
|
it 'includes imports usage data' do
|
2020-08-28 12:10:37 +00:00
|
|
|
for_defined_days_back do
|
|
|
|
user = create(:user)
|
|
|
|
|
2020-08-31 12:10:39 +00:00
|
|
|
%w(gitlab_project gitlab github bitbucket bitbucket_server gitea git manifest fogbugz phabricator).each do |type|
|
2020-08-28 12:10:37 +00:00
|
|
|
create(:project, import_type: type, creator_id: user.id)
|
|
|
|
end
|
2020-08-31 12:10:39 +00:00
|
|
|
|
|
|
|
jira_project = create(:project, creator_id: user.id)
|
|
|
|
create(:jira_import_state, :finished, project: jira_project)
|
2020-10-20 15:08:57 +00:00
|
|
|
|
2020-10-27 12:08:33 +00:00
|
|
|
create(:issue_csv_import, user: user)
|
2021-02-01 21:09:15 +00:00
|
|
|
|
|
|
|
group = create(:group)
|
|
|
|
group.add_owner(user)
|
|
|
|
create(:group_import_state, group: group, user: user)
|
|
|
|
|
|
|
|
bulk_import = create(:bulk_import, user: user)
|
|
|
|
create(:bulk_import_entity, :group_entity, bulk_import: bulk_import)
|
|
|
|
create(:bulk_import_entity, :project_entity, bulk_import: bulk_import)
|
2020-08-28 12:10:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
expect(described_class.usage_activity_by_stage_manage({})).to include(
|
|
|
|
{
|
2020-10-23 00:08:30 +00:00
|
|
|
bulk_imports: {
|
2021-02-01 21:09:15 +00:00
|
|
|
gitlab_v1: 2,
|
|
|
|
gitlab: Gitlab::UsageData::DEPRECATED_VALUE
|
2020-10-23 00:08:30 +00:00
|
|
|
},
|
2021-02-01 21:09:15 +00:00
|
|
|
project_imports: {
|
2020-08-28 12:10:37 +00:00
|
|
|
bitbucket: 2,
|
|
|
|
bitbucket_server: 2,
|
|
|
|
git: 2,
|
2021-02-01 21:09:15 +00:00
|
|
|
gitea: 2,
|
|
|
|
github: 2,
|
|
|
|
gitlab: 2,
|
|
|
|
gitlab_migration: 2,
|
|
|
|
gitlab_project: 2,
|
2020-08-28 12:10:37 +00:00
|
|
|
manifest: 2
|
2020-08-31 12:10:39 +00:00
|
|
|
},
|
2021-02-01 21:09:15 +00:00
|
|
|
issue_imports: {
|
2020-08-31 12:10:39 +00:00
|
|
|
jira: 2,
|
|
|
|
fogbugz: 2,
|
2020-10-20 15:08:57 +00:00
|
|
|
phabricator: 2,
|
|
|
|
csv: 2
|
2021-02-01 21:09:15 +00:00
|
|
|
},
|
|
|
|
group_imports: {
|
|
|
|
group_import: 2,
|
|
|
|
gitlab_migration: 2
|
|
|
|
},
|
|
|
|
projects_imported: {
|
|
|
|
total: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
gitlab_project: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
gitlab: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
github: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
bitbucket: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
bitbucket_server: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
gitea: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
git: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
manifest: Gitlab::UsageData::DEPRECATED_VALUE
|
|
|
|
},
|
|
|
|
issues_imported: {
|
|
|
|
jira: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
fogbugz: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
phabricator: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
csv: Gitlab::UsageData::DEPRECATED_VALUE
|
|
|
|
},
|
|
|
|
groups_imported: Gitlab::UsageData::DEPRECATED_VALUE
|
2020-08-28 12:10:37 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
expect(described_class.usage_activity_by_stage_manage(described_class.last_28_days_time_period)).to include(
|
|
|
|
{
|
2020-10-23 00:08:30 +00:00
|
|
|
bulk_imports: {
|
2021-02-01 21:09:15 +00:00
|
|
|
gitlab_v1: 1,
|
|
|
|
gitlab: Gitlab::UsageData::DEPRECATED_VALUE
|
2020-10-23 00:08:30 +00:00
|
|
|
},
|
2021-02-01 21:09:15 +00:00
|
|
|
project_imports: {
|
2020-08-28 12:10:37 +00:00
|
|
|
bitbucket: 1,
|
|
|
|
bitbucket_server: 1,
|
|
|
|
git: 1,
|
2021-02-01 21:09:15 +00:00
|
|
|
gitea: 1,
|
|
|
|
github: 1,
|
|
|
|
gitlab: 1,
|
|
|
|
gitlab_migration: 1,
|
|
|
|
gitlab_project: 1,
|
2020-08-28 12:10:37 +00:00
|
|
|
manifest: 1
|
2020-08-31 12:10:39 +00:00
|
|
|
},
|
2021-02-01 21:09:15 +00:00
|
|
|
issue_imports: {
|
2020-08-31 12:10:39 +00:00
|
|
|
jira: 1,
|
|
|
|
fogbugz: 1,
|
2020-10-20 15:08:57 +00:00
|
|
|
phabricator: 1,
|
|
|
|
csv: 1
|
2021-02-01 21:09:15 +00:00
|
|
|
},
|
|
|
|
group_imports: {
|
|
|
|
group_import: 1,
|
|
|
|
gitlab_migration: 1
|
|
|
|
},
|
|
|
|
projects_imported: {
|
|
|
|
total: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
gitlab_project: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
gitlab: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
github: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
bitbucket: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
bitbucket_server: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
gitea: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
git: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
manifest: Gitlab::UsageData::DEPRECATED_VALUE
|
|
|
|
},
|
|
|
|
issues_imported: {
|
|
|
|
jira: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
fogbugz: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
phabricator: Gitlab::UsageData::DEPRECATED_VALUE,
|
|
|
|
csv: Gitlab::UsageData::DEPRECATED_VALUE
|
|
|
|
},
|
|
|
|
groups_imported: Gitlab::UsageData::DEPRECATED_VALUE
|
|
|
|
|
2020-08-28 12:10:37 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-08-06 00:09:53 +00:00
|
|
|
def omniauth_providers
|
|
|
|
[
|
|
|
|
OpenStruct.new(name: 'google_oauth2'),
|
|
|
|
OpenStruct.new(name: 'ldapmain'),
|
|
|
|
OpenStruct.new(name: 'group_saml')
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'usage_activity_by_stage_monitor' do
|
|
|
|
it 'includes accurate usage_activity_by_stage data' do
|
|
|
|
for_defined_days_back do
|
2021-03-12 18:09:23 +00:00
|
|
|
user = create(:user, dashboard: 'operations')
|
2020-08-06 00:09:53 +00:00
|
|
|
cluster = create(:cluster, user: user)
|
2021-03-12 18:09:23 +00:00
|
|
|
project = create(:project, creator: user)
|
2020-08-06 00:09:53 +00:00
|
|
|
create(:clusters_applications_prometheus, :installed, cluster: cluster)
|
2020-10-02 12:09:03 +00:00
|
|
|
create(:project_tracing_setting)
|
2020-11-03 03:08:56 +00:00
|
|
|
create(:project_error_tracking_setting)
|
2020-11-18 00:09:02 +00:00
|
|
|
create(:incident)
|
|
|
|
create(:incident, alert_management_alert: create(:alert_management_alert))
|
2021-03-12 18:09:23 +00:00
|
|
|
create(:alert_management_http_integration, :active, project: project)
|
2020-07-13 18:09:16 +00:00
|
|
|
end
|
|
|
|
|
2020-08-06 00:09:53 +00:00
|
|
|
expect(described_class.usage_activity_by_stage_monitor({})).to include(
|
|
|
|
clusters: 2,
|
|
|
|
clusters_applications_prometheus: 2,
|
2020-10-02 12:09:03 +00:00
|
|
|
operations_dashboard_default_dashboard: 2,
|
2020-11-03 03:08:56 +00:00
|
|
|
projects_with_tracing_enabled: 2,
|
2020-11-18 00:09:02 +00:00
|
|
|
projects_with_error_tracking_enabled: 2,
|
|
|
|
projects_with_incidents: 4,
|
2021-03-12 18:09:23 +00:00
|
|
|
projects_with_alert_incidents: 2,
|
|
|
|
projects_with_enabled_alert_integrations_histogram: { '1' => 2 }
|
2020-08-06 00:09:53 +00:00
|
|
|
)
|
2020-11-05 00:09:16 +00:00
|
|
|
|
2021-03-12 18:09:23 +00:00
|
|
|
data_28_days = described_class.usage_activity_by_stage_monitor(described_class.last_28_days_time_period)
|
|
|
|
expect(data_28_days).to include(
|
2020-08-06 00:09:53 +00:00
|
|
|
clusters: 1,
|
|
|
|
clusters_applications_prometheus: 1,
|
2020-10-02 12:09:03 +00:00
|
|
|
operations_dashboard_default_dashboard: 1,
|
2020-11-03 03:08:56 +00:00
|
|
|
projects_with_tracing_enabled: 1,
|
2020-11-18 00:09:02 +00:00
|
|
|
projects_with_error_tracking_enabled: 1,
|
|
|
|
projects_with_incidents: 2,
|
|
|
|
projects_with_alert_incidents: 1
|
2020-08-06 00:09:53 +00:00
|
|
|
)
|
2021-03-12 18:09:23 +00:00
|
|
|
|
|
|
|
expect(data_28_days).not_to include(:projects_with_enabled_alert_integrations_histogram)
|
2020-08-06 00:09:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'usage_activity_by_stage_plan' do
|
|
|
|
it 'includes accurate usage_activity_by_stage data' do
|
|
|
|
for_defined_days_back do
|
|
|
|
user = create(:user)
|
|
|
|
project = create(:project, creator: user)
|
|
|
|
issue = create(:issue, project: project, author: user)
|
|
|
|
create(:issue, project: project, author: User.support_bot)
|
|
|
|
create(:note, project: project, noteable: issue, author: user)
|
|
|
|
create(:todo, project: project, target: issue, author: user)
|
2020-09-01 12:11:01 +00:00
|
|
|
create(:jira_service, :jira_cloud_service, active: true, project: create(:project, :jira_dvcs_cloud, creator: user))
|
|
|
|
create(:jira_service, active: true, project: create(:project, :jira_dvcs_server, creator: user))
|
2020-07-13 18:09:16 +00:00
|
|
|
end
|
|
|
|
|
2020-08-06 00:09:53 +00:00
|
|
|
expect(described_class.usage_activity_by_stage_plan({})).to include(
|
|
|
|
issues: 3,
|
|
|
|
notes: 2,
|
|
|
|
projects: 2,
|
|
|
|
todos: 2,
|
|
|
|
service_desk_enabled_projects: 2,
|
2020-09-01 12:11:01 +00:00
|
|
|
service_desk_issues: 2,
|
|
|
|
projects_jira_active: 2,
|
|
|
|
projects_jira_dvcs_cloud_active: 2,
|
|
|
|
projects_jira_dvcs_server_active: 2
|
2020-08-06 00:09:53 +00:00
|
|
|
)
|
|
|
|
expect(described_class.usage_activity_by_stage_plan(described_class.last_28_days_time_period)).to include(
|
|
|
|
issues: 2,
|
|
|
|
notes: 1,
|
|
|
|
projects: 1,
|
|
|
|
todos: 1,
|
|
|
|
service_desk_enabled_projects: 1,
|
2020-09-01 12:11:01 +00:00
|
|
|
service_desk_issues: 1,
|
|
|
|
projects_jira_active: 1,
|
|
|
|
projects_jira_dvcs_cloud_active: 1,
|
|
|
|
projects_jira_dvcs_server_active: 1
|
2020-08-06 00:09:53 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'usage_activity_by_stage_release' do
|
|
|
|
it 'includes accurate usage_activity_by_stage data' do
|
|
|
|
for_defined_days_back do
|
|
|
|
user = create(:user)
|
|
|
|
create(:deployment, :failed, user: user)
|
|
|
|
create(:release, author: user)
|
|
|
|
create(:deployment, :success, user: user)
|
2020-07-09 03:09:01 +00:00
|
|
|
end
|
2020-08-06 00:09:53 +00:00
|
|
|
|
|
|
|
expect(described_class.usage_activity_by_stage_release({})).to include(
|
|
|
|
deployments: 2,
|
|
|
|
failed_deployments: 2,
|
|
|
|
releases: 2,
|
|
|
|
successful_deployments: 2
|
|
|
|
)
|
|
|
|
expect(described_class.usage_activity_by_stage_release(described_class.last_28_days_time_period)).to include(
|
|
|
|
deployments: 1,
|
|
|
|
failed_deployments: 1,
|
|
|
|
releases: 1,
|
|
|
|
successful_deployments: 1
|
|
|
|
)
|
2020-06-19 12:09:07 +00:00
|
|
|
end
|
2020-08-06 00:09:53 +00:00
|
|
|
end
|
2020-06-19 12:09:07 +00:00
|
|
|
|
2020-08-06 00:09:53 +00:00
|
|
|
describe 'usage_activity_by_stage_verify' do
|
|
|
|
it 'includes accurate usage_activity_by_stage data' do
|
|
|
|
for_defined_days_back do
|
|
|
|
user = create(:user)
|
|
|
|
create(:ci_build, user: user)
|
|
|
|
create(:ci_empty_pipeline, source: :external, user: user)
|
|
|
|
create(:ci_empty_pipeline, user: user)
|
|
|
|
create(:ci_pipeline, :auto_devops_source, user: user)
|
|
|
|
create(:ci_pipeline, :repository_source, user: user)
|
|
|
|
create(:ci_pipeline_schedule, owner: user)
|
|
|
|
create(:ci_trigger, owner: user)
|
|
|
|
create(:clusters_applications_runner, :installed)
|
2020-06-05 18:08:19 +00:00
|
|
|
end
|
|
|
|
|
2020-08-06 00:09:53 +00:00
|
|
|
expect(described_class.usage_activity_by_stage_verify({})).to include(
|
|
|
|
ci_builds: 2,
|
|
|
|
ci_external_pipelines: 2,
|
|
|
|
ci_internal_pipelines: 2,
|
|
|
|
ci_pipeline_config_auto_devops: 2,
|
|
|
|
ci_pipeline_config_repository: 2,
|
|
|
|
ci_pipeline_schedules: 2,
|
|
|
|
ci_pipelines: 2,
|
|
|
|
ci_triggers: 2,
|
|
|
|
clusters_applications_runner: 2
|
|
|
|
)
|
|
|
|
expect(described_class.usage_activity_by_stage_verify(described_class.last_28_days_time_period)).to include(
|
|
|
|
ci_builds: 1,
|
|
|
|
ci_external_pipelines: 1,
|
|
|
|
ci_internal_pipelines: 1,
|
|
|
|
ci_pipeline_config_auto_devops: 1,
|
|
|
|
ci_pipeline_config_repository: 1,
|
|
|
|
ci_pipeline_schedules: 1,
|
|
|
|
ci_pipelines: 1,
|
|
|
|
ci_triggers: 1,
|
|
|
|
clusters_applications_runner: 1
|
|
|
|
)
|
2020-06-05 18:08:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-02 06:09:26 +00:00
|
|
|
describe '.data' do
|
2020-06-04 15:08:21 +00:00
|
|
|
let!(:ud) { build(:usage_data) }
|
2020-03-18 15:09:45 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:grafana_embed_usage_data).and_return(2)
|
|
|
|
end
|
2018-10-15 09:39:09 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
subject { described_class.data }
|
2020-02-17 18:09:00 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'gathers usage data' do
|
|
|
|
expect(subject.keys).to include(*UsageDataHelpers::USAGE_DATA_KEYS)
|
|
|
|
end
|
2020-02-17 18:09:00 +00:00
|
|
|
|
2021-03-12 18:09:23 +00:00
|
|
|
it 'gathers usage counts', :aggregate_failures do
|
2020-06-04 15:08:21 +00:00
|
|
|
count_data = subject[:counts]
|
2020-02-17 18:09:00 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(count_data[:boards]).to eq(1)
|
|
|
|
expect(count_data[:projects]).to eq(4)
|
|
|
|
expect(count_data.keys).to include(*UsageDataHelpers::COUNTS_KEYS)
|
|
|
|
expect(UsageDataHelpers::COUNTS_KEYS - count_data.keys).to be_empty
|
2021-03-12 18:09:23 +00:00
|
|
|
expect(count_data.values).to all(be_a_kind_of(Integer))
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-02-17 18:09:00 +00:00
|
|
|
|
2020-07-03 12:08:53 +00:00
|
|
|
it 'gathers usage counts correctly' do
|
2020-06-04 15:08:21 +00:00
|
|
|
count_data = subject[:counts]
|
|
|
|
|
|
|
|
expect(count_data[:projects]).to eq(4)
|
|
|
|
expect(count_data[:projects_asana_active]).to eq(0)
|
|
|
|
expect(count_data[:projects_prometheus_active]).to eq(1)
|
2020-11-26 15:09:30 +00:00
|
|
|
expect(count_data[:projects_jenkins_active]).to eq(1)
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(count_data[:projects_jira_active]).to eq(4)
|
|
|
|
expect(count_data[:projects_jira_server_active]).to eq(2)
|
|
|
|
expect(count_data[:projects_jira_cloud_active]).to eq(2)
|
|
|
|
expect(count_data[:jira_imports_projects_count]).to eq(2)
|
|
|
|
expect(count_data[:jira_imports_total_imported_count]).to eq(3)
|
|
|
|
expect(count_data[:jira_imports_total_imported_issues_count]).to eq(13)
|
|
|
|
expect(count_data[:projects_slack_active]).to eq(2)
|
|
|
|
expect(count_data[:projects_slack_slash_commands_active]).to eq(1)
|
|
|
|
expect(count_data[:projects_custom_issue_tracker_active]).to eq(1)
|
2020-08-06 21:10:15 +00:00
|
|
|
expect(count_data[:projects_mattermost_active]).to eq(1)
|
2020-10-16 12:09:33 +00:00
|
|
|
expect(count_data[:groups_mattermost_active]).to eq(1)
|
2020-08-04 00:10:01 +00:00
|
|
|
expect(count_data[:templates_mattermost_active]).to eq(1)
|
|
|
|
expect(count_data[:instances_mattermost_active]).to eq(1)
|
2020-10-16 12:09:33 +00:00
|
|
|
expect(count_data[:projects_inheriting_mattermost_active]).to eq(1)
|
|
|
|
expect(count_data[:groups_inheriting_slack_active]).to eq(1)
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(count_data[:projects_with_repositories_enabled]).to eq(3)
|
|
|
|
expect(count_data[:projects_with_error_tracking_enabled]).to eq(1)
|
2020-10-02 12:09:03 +00:00
|
|
|
expect(count_data[:projects_with_tracing_enabled]).to eq(1)
|
2020-11-06 03:09:19 +00:00
|
|
|
expect(count_data[:projects_with_enabled_alert_integrations]).to eq(1)
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(count_data[:projects_with_prometheus_alerts]).to eq(2)
|
|
|
|
expect(count_data[:projects_with_terraform_reports]).to eq(2)
|
|
|
|
expect(count_data[:projects_with_terraform_states]).to eq(2)
|
2020-11-05 00:09:16 +00:00
|
|
|
expect(count_data[:projects_with_alerts_created]).to eq(1)
|
2020-08-07 21:10:07 +00:00
|
|
|
expect(count_data[:protected_branches]).to eq(2)
|
|
|
|
expect(count_data[:protected_branches_except_default]).to eq(1)
|
2020-06-10 15:08:07 +00:00
|
|
|
expect(count_data[:terraform_reports]).to eq(6)
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(count_data[:terraform_states]).to eq(3)
|
|
|
|
expect(count_data[:issues_created_from_gitlab_error_tracking_ui]).to eq(1)
|
|
|
|
expect(count_data[:issues_with_associated_zoom_link]).to eq(2)
|
|
|
|
expect(count_data[:issues_using_zoom_quick_actions]).to eq(3)
|
|
|
|
expect(count_data[:issues_with_embedded_grafana_charts_approx]).to eq(2)
|
|
|
|
expect(count_data[:incident_issues]).to eq(4)
|
|
|
|
expect(count_data[:issues_created_gitlab_alerts]).to eq(1)
|
2020-06-06 00:08:18 +00:00
|
|
|
expect(count_data[:issues_created_from_alerts]).to eq(3)
|
|
|
|
expect(count_data[:issues_created_manually_from_alerts]).to eq(1)
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(count_data[:alert_bot_incident_issues]).to eq(4)
|
|
|
|
expect(count_data[:incident_labeled_issues]).to eq(3)
|
|
|
|
|
|
|
|
expect(count_data[:clusters_enabled]).to eq(6)
|
|
|
|
expect(count_data[:project_clusters_enabled]).to eq(4)
|
|
|
|
expect(count_data[:group_clusters_enabled]).to eq(1)
|
|
|
|
expect(count_data[:instance_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(1)
|
|
|
|
expect(count_data[:instance_clusters_disabled]).to eq(1)
|
|
|
|
expect(count_data[:clusters_platforms_eks]).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_cert_managers]).to eq(1)
|
|
|
|
expect(count_data[:clusters_applications_crossplane]).to eq(1)
|
|
|
|
expect(count_data[:clusters_applications_prometheus]).to eq(1)
|
|
|
|
expect(count_data[:clusters_applications_runner]).to eq(1)
|
|
|
|
expect(count_data[:clusters_applications_knative]).to eq(1)
|
|
|
|
expect(count_data[:clusters_applications_elastic_stack]).to eq(1)
|
|
|
|
expect(count_data[:grafana_integrated_projects]).to eq(2)
|
|
|
|
expect(count_data[:clusters_applications_jupyter]).to eq(1)
|
2020-07-13 06:09:23 +00:00
|
|
|
expect(count_data[:clusters_applications_cilium]).to eq(1)
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(count_data[:clusters_management_project]).to eq(1)
|
2020-09-01 06:10:44 +00:00
|
|
|
expect(count_data[:kubernetes_agents]).to eq(2)
|
|
|
|
expect(count_data[:kubernetes_agents_with_token]).to eq(1)
|
2020-06-23 06:08:52 +00:00
|
|
|
|
2020-07-03 12:08:53 +00:00
|
|
|
expect(count_data[:deployments]).to eq(4)
|
|
|
|
expect(count_data[:successful_deployments]).to eq(2)
|
|
|
|
expect(count_data[:failed_deployments]).to eq(2)
|
2020-06-24 18:09:03 +00:00
|
|
|
expect(count_data[:snippets]).to eq(6)
|
|
|
|
expect(count_data[:personal_snippets]).to eq(2)
|
|
|
|
expect(count_data[:project_snippets]).to eq(4)
|
2020-08-24 09:10:14 +00:00
|
|
|
|
2020-09-30 09:10:11 +00:00
|
|
|
expect(count_data[:projects_creating_incidents]).to eq(2)
|
2020-08-24 09:10:14 +00:00
|
|
|
expect(count_data[:projects_with_packages]).to eq(2)
|
2020-09-04 15:08:46 +00:00
|
|
|
expect(count_data[:packages]).to eq(4)
|
2020-09-23 12:09:58 +00:00
|
|
|
expect(count_data[:user_preferences_user_gitpod_enabled]).to eq(1)
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-02-17 18:09:00 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'gathers object store usage correctly' do
|
|
|
|
expect(subject[:object_store]).to eq(
|
|
|
|
{ artifacts: { enabled: true, object_store: { enabled: true, direct_upload: true, background_upload: false, provider: "AWS" } },
|
|
|
|
external_diffs: { enabled: false },
|
|
|
|
lfs: { enabled: true, object_store: { enabled: false, direct_upload: true, background_upload: false, provider: "AWS" } },
|
|
|
|
uploads: { enabled: nil, object_store: { enabled: false, direct_upload: true, background_upload: false, provider: "AWS" } },
|
|
|
|
packages: { enabled: true, object_store: { enabled: false, direct_upload: false, background_upload: true, provider: "AWS" } } }
|
|
|
|
)
|
|
|
|
end
|
2020-04-29 15:09:58 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'with existing container expiration policies' do
|
|
|
|
let_it_be(:disabled) { create(:container_expiration_policy, enabled: false) }
|
|
|
|
let_it_be(:enabled) { create(:container_expiration_policy, enabled: true) }
|
2020-05-15 12:08:28 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
%i[keep_n cadence older_than].each do |attribute|
|
|
|
|
ContainerExpirationPolicy.send("#{attribute}_options").keys.each do |value|
|
|
|
|
let_it_be("container_expiration_policy_with_#{attribute}_set_to_#{value}") { create(:container_expiration_policy, attribute => value) }
|
2020-05-15 12:08:28 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-05-15 12:08:28 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
let_it_be('container_expiration_policy_with_keep_n_set_to_null') { create(:container_expiration_policy, keep_n: nil) }
|
|
|
|
let_it_be('container_expiration_policy_with_older_than_set_to_null') { create(:container_expiration_policy, older_than: nil) }
|
2020-05-15 12:08:28 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
let(:inactive_policies) { ::ContainerExpirationPolicy.where(enabled: false) }
|
|
|
|
let(:active_policies) { ::ContainerExpirationPolicy.active }
|
2020-05-15 12:08:28 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
subject { described_class.data[:counts] }
|
2020-05-15 12:08:28 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'gathers usage data' do
|
2020-10-28 00:08:34 +00:00
|
|
|
expect(subject[:projects_with_expiration_policy_enabled]).to eq 18
|
|
|
|
expect(subject[:projects_with_expiration_policy_disabled]).to eq 5
|
2020-06-04 15:08:21 +00:00
|
|
|
|
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_keep_n_unset]).to eq 1
|
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_keep_n_set_to_1]).to eq 1
|
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_keep_n_set_to_5]).to eq 1
|
2020-10-28 00:08:34 +00:00
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_keep_n_set_to_10]).to eq 12
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_keep_n_set_to_25]).to eq 1
|
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_keep_n_set_to_50]).to eq 1
|
|
|
|
|
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_older_than_unset]).to eq 1
|
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_older_than_set_to_7d]).to eq 1
|
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_older_than_set_to_14d]).to eq 1
|
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_older_than_set_to_30d]).to eq 1
|
2020-10-28 00:08:34 +00:00
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_older_than_set_to_90d]).to eq 14
|
2020-06-04 15:08:21 +00:00
|
|
|
|
2020-10-28 00:08:34 +00:00
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_cadence_set_to_1d]).to eq 14
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_cadence_set_to_7d]).to eq 1
|
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_cadence_set_to_14d]).to eq 1
|
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_cadence_set_to_1month]).to eq 1
|
|
|
|
expect(subject[:projects_with_expiration_policy_enabled_with_cadence_set_to_3month]).to eq 1
|
2020-05-15 12:08:28 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-05-15 12:08:28 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'works when queries time out' do
|
|
|
|
allow_any_instance_of(ActiveRecord::Relation)
|
|
|
|
.to receive(:count).and_raise(ActiveRecord::StatementInvalid.new(''))
|
2020-02-17 18:09:00 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
expect { subject }.not_to raise_error
|
|
|
|
end
|
2020-03-27 21:07:53 +00:00
|
|
|
|
2020-06-17 12:08:42 +00:00
|
|
|
it 'includes a recording_ce_finished_at timestamp' do
|
|
|
|
expect(subject[:recording_ce_finished_at]).to be_a(Time)
|
|
|
|
end
|
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'jira usage works when queries time out' do
|
|
|
|
allow_any_instance_of(ActiveRecord::Relation)
|
|
|
|
.to receive(:find_in_batches).and_raise(ActiveRecord::StatementInvalid.new(''))
|
2020-03-27 21:07:53 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
expect { described_class.jira_usage }.not_to raise_error
|
2020-03-18 15:09:45 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2018-10-15 09:39:09 +00:00
|
|
|
|
2020-06-23 06:08:52 +00:00
|
|
|
describe '.system_usage_data_monthly' do
|
2020-10-09 00:08:41 +00:00
|
|
|
let_it_be(:project) { create(:project) }
|
2020-06-23 06:08:52 +00:00
|
|
|
|
2020-10-09 00:08:41 +00:00
|
|
|
before do
|
2020-10-28 09:08:37 +00:00
|
|
|
project = create(:project)
|
|
|
|
env = create(:environment)
|
|
|
|
create(:package, project: project, created_at: 3.days.ago)
|
|
|
|
create(:package, created_at: 2.months.ago, project: project)
|
|
|
|
|
|
|
|
[3, 31].each do |n|
|
|
|
|
deployment_options = { created_at: n.days.ago, project: env.project, environment: env }
|
|
|
|
create(:deployment, :failed, deployment_options)
|
|
|
|
create(:deployment, :success, deployment_options)
|
|
|
|
create(:project_snippet, project: project, created_at: n.days.ago)
|
|
|
|
create(:personal_snippet, created_at: n.days.ago)
|
2020-11-05 00:09:16 +00:00
|
|
|
create(:alert_management_alert, project: project, created_at: n.days.ago)
|
2020-10-28 09:08:37 +00:00
|
|
|
end
|
|
|
|
|
2020-10-09 00:08:41 +00:00
|
|
|
stub_application_setting(self_monitoring_project: project)
|
|
|
|
|
|
|
|
for_defined_days_back do
|
|
|
|
create(:product_analytics_event, project: project, se_category: 'epics', se_action: 'promote')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-23 06:08:52 +00:00
|
|
|
subject { described_class.system_usage_data_monthly }
|
|
|
|
|
2020-07-03 12:08:53 +00:00
|
|
|
it 'gathers monthly usage counts correctly' do
|
2020-06-23 06:08:52 +00:00
|
|
|
counts_monthly = subject[:counts_monthly]
|
|
|
|
|
2020-07-03 12:08:53 +00:00
|
|
|
expect(counts_monthly[:deployments]).to eq(2)
|
|
|
|
expect(counts_monthly[:successful_deployments]).to eq(1)
|
|
|
|
expect(counts_monthly[:failed_deployments]).to eq(1)
|
2020-10-28 09:08:37 +00:00
|
|
|
expect(counts_monthly[:snippets]).to eq(2)
|
2020-06-24 18:09:03 +00:00
|
|
|
expect(counts_monthly[:personal_snippets]).to eq(1)
|
2020-10-28 09:08:37 +00:00
|
|
|
expect(counts_monthly[:project_snippets]).to eq(1)
|
2020-11-05 00:09:16 +00:00
|
|
|
expect(counts_monthly[:projects_with_alerts_created]).to eq(1)
|
2020-10-28 09:08:37 +00:00
|
|
|
expect(counts_monthly[:packages]).to eq(1)
|
2020-10-09 00:08:41 +00:00
|
|
|
expect(counts_monthly[:promoted_issues]).to eq(1)
|
2020-06-23 06:08:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-03 12:09:49 +00:00
|
|
|
describe '.runners_usage' do
|
|
|
|
before do
|
|
|
|
project = build(:project)
|
|
|
|
create_list(:ci_runner, 2, :instance_type, :online)
|
|
|
|
create(:ci_runner, :group, :online)
|
|
|
|
create(:ci_runner, :group, :inactive)
|
|
|
|
create_list(:ci_runner, 3, :project_type, :online, projects: [project])
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.runners_usage }
|
|
|
|
|
|
|
|
it 'gathers runner usage counts correctly' do
|
|
|
|
expect(subject[:ci_runners]).to eq(7)
|
|
|
|
expect(subject[:ci_runners_instance_type_active]).to eq(2)
|
|
|
|
expect(subject[:ci_runners_group_type_active]).to eq(1)
|
|
|
|
expect(subject[:ci_runners_project_type_active]).to eq(3)
|
|
|
|
|
|
|
|
expect(subject[:ci_runners_instance_type_active_online]).to eq(2)
|
|
|
|
expect(subject[:ci_runners_group_type_active_online]).to eq(1)
|
|
|
|
expect(subject[:ci_runners_project_type_active_online]).to eq(3)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-02 21:10:43 +00:00
|
|
|
describe '.usage_counters' do
|
|
|
|
subject { described_class.usage_counters }
|
|
|
|
|
|
|
|
it { is_expected.to include(:kubernetes_agent_gitops_sync) }
|
2021-05-07 06:10:43 +00:00
|
|
|
it { is_expected.to include(:kubernetes_agent_k8s_api_proxy_request) }
|
2020-10-13 18:08:58 +00:00
|
|
|
it { is_expected.to include(:static_site_editor_views) }
|
2021-01-05 15:10:02 +00:00
|
|
|
it { is_expected.to include(:package_events_i_package_pull_package) }
|
|
|
|
it { is_expected.to include(:package_events_i_package_delete_package_by_user) }
|
|
|
|
it { is_expected.to include(:package_events_i_package_conan_push_package) }
|
2020-09-02 21:10:43 +00:00
|
|
|
end
|
|
|
|
|
2020-07-02 06:09:26 +00:00
|
|
|
describe '.usage_data_counters' do
|
2020-06-04 15:08:21 +00:00
|
|
|
subject { described_class.usage_data_counters }
|
2017-04-05 12:29:48 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it { is_expected.to all(respond_to :totals) }
|
|
|
|
it { is_expected.to all(respond_to :fallback_totals) }
|
2019-07-21 01:26:19 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
describe 'the results of calling #totals on all objects in the array' do
|
|
|
|
subject { described_class.usage_data_counters.map(&:totals) }
|
2019-07-21 01:26:19 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
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))) }
|
|
|
|
end
|
2019-07-21 01:26:19 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
describe 'the results of calling #fallback_totals on all objects in the array' do
|
|
|
|
subject { described_class.usage_data_counters.map(&:fallback_totals) }
|
2020-05-06 03:09:33 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it { is_expected.to all(be_a Hash) }
|
|
|
|
it { is_expected.to all(have_attributes(keys: all(be_a Symbol), values: all(eq(-1)))) }
|
|
|
|
end
|
2020-05-06 03:09:33 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'does not have any conflicts' do
|
|
|
|
all_keys = subject.flat_map { |counter| counter.totals.keys }
|
2019-07-21 01:26:19 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(all_keys.size).to eq all_keys.to_set.size
|
2020-03-18 15:09:45 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2019-07-21 01:26:19 +00:00
|
|
|
|
2020-07-02 06:09:26 +00:00
|
|
|
describe '.license_usage_data' do
|
2020-06-04 15:08:21 +00:00
|
|
|
subject { described_class.license_usage_data }
|
2020-03-18 15:09:45 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'gathers license data' do
|
|
|
|
expect(subject[:uuid]).to eq(Gitlab::CurrentSettings.uuid)
|
|
|
|
expect(subject[:version]).to eq(Gitlab::VERSION)
|
|
|
|
expect(subject[:installation_type]).to eq('gitlab-development-kit')
|
|
|
|
expect(subject[:active_user_count]).to eq(User.active.size)
|
|
|
|
expect(subject[:recorded_at]).to be_a(Time)
|
2020-03-18 15:09:45 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-03-18 15:09:45 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'when not relying on database records' do
|
2020-07-02 06:09:26 +00:00
|
|
|
describe '.features_usage_data_ce' do
|
2020-06-04 15:08:21 +00:00
|
|
|
subject { described_class.features_usage_data_ce }
|
|
|
|
|
2020-06-05 15:08:23 +00:00
|
|
|
it 'gathers feature usage data', :aggregate_failures do
|
|
|
|
expect(subject[:instance_auto_devops_enabled]).to eq(Gitlab::CurrentSettings.auto_devops_enabled?)
|
2020-06-04 15:08:21 +00: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?)
|
|
|
|
expect(subject[:omniauth_enabled]).to eq(Gitlab::Auth.omniauth_enabled?)
|
|
|
|
expect(subject[:reply_by_email_enabled]).to eq(Gitlab::IncomingEmail.enabled?)
|
|
|
|
expect(subject[:container_registry_enabled]).to eq(Gitlab.config.registry.enabled)
|
|
|
|
expect(subject[:dependency_proxy_enabled]).to eq(Gitlab.config.dependency_proxy.enabled)
|
|
|
|
expect(subject[:gitlab_shared_runners_enabled]).to eq(Gitlab.config.gitlab_ci.shared_runners_enabled)
|
|
|
|
expect(subject[:web_ide_clientside_preview_enabled]).to eq(Gitlab::CurrentSettings.web_ide_clientside_preview_enabled?)
|
|
|
|
expect(subject[:grafana_link_enabled]).to eq(Gitlab::CurrentSettings.grafana_enabled?)
|
2020-09-18 12:09:50 +00:00
|
|
|
expect(subject[:gitpod_enabled]).to eq(Gitlab::CurrentSettings.gitpod_enabled?)
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-05-13 12:07:54 +00:00
|
|
|
|
2020-07-03 15:09:13 +00:00
|
|
|
context 'with embedded Prometheus' do
|
|
|
|
it 'returns true when embedded Prometheus is enabled' do
|
|
|
|
allow(Gitlab::Prometheus::Internal).to receive(:prometheus_enabled?).and_return(true)
|
|
|
|
|
|
|
|
expect(subject[:prometheus_enabled]).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when embedded Prometheus is disabled' do
|
|
|
|
allow(Gitlab::Prometheus::Internal).to receive(:prometheus_enabled?).and_return(false)
|
|
|
|
|
|
|
|
expect(subject[:prometheus_enabled]).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'with embedded grafana' do
|
|
|
|
it 'returns true when embedded grafana is enabled' do
|
|
|
|
stub_application_setting(grafana_enabled: true)
|
2020-05-13 12:07:54 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(subject[:grafana_link_enabled]).to eq(true)
|
2020-02-17 18:09:00 +00:00
|
|
|
end
|
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'returns false when embedded grafana is disabled' do
|
|
|
|
stub_application_setting(grafana_enabled: false)
|
2020-06-03 12:08:21 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(subject[:grafana_link_enabled]).to eq(false)
|
2020-02-17 18:09:00 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-09-18 12:09:50 +00:00
|
|
|
|
|
|
|
context 'with Gitpod' do
|
|
|
|
it 'returns true when is enabled' do
|
|
|
|
stub_application_setting(gitpod_enabled: true)
|
|
|
|
|
|
|
|
expect(subject[:gitpod_enabled]).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when is disabled' do
|
|
|
|
stub_application_setting(gitpod_enabled: false)
|
|
|
|
|
|
|
|
expect(subject[:gitpod_enabled]).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-06-03 12:08:21 +00:00
|
|
|
|
2020-07-02 06:09:26 +00:00
|
|
|
describe '.components_usage_data' do
|
2020-06-04 15:08:21 +00:00
|
|
|
subject { described_class.components_usage_data }
|
|
|
|
|
|
|
|
it 'gathers basic components usage data' do
|
2020-07-17 21:09:23 +00:00
|
|
|
stub_application_setting(container_registry_vendor: 'gitlab', container_registry_version: 'x.y.z')
|
2020-06-04 15:08:21 +00:00
|
|
|
|
|
|
|
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)
|
2020-10-19 12:09:20 +00:00
|
|
|
expect(subject[:database][:pg_system_id]).to eq(Gitlab::Database.system_id)
|
2020-09-02 18:10:40 +00:00
|
|
|
expect(subject[:mail][:smtp_server]).to eq(ActionMailer::Base.smtp_settings[:address])
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(subject[:gitaly][:version]).to be_present
|
|
|
|
expect(subject[:gitaly][:servers]).to be >= 1
|
|
|
|
expect(subject[:gitaly][:clusters]).to be >= 0
|
|
|
|
expect(subject[:gitaly][:filesystems]).to be_an(Array)
|
|
|
|
expect(subject[:gitaly][:filesystems].first).to be_a(String)
|
2020-07-24 18:09:45 +00:00
|
|
|
expect(subject[:container_registry_server][:vendor]).to eq('gitlab')
|
|
|
|
expect(subject[:container_registry_server][:version]).to eq('x.y.z')
|
2020-06-03 12:08:21 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-04-01 09:07:45 +00:00
|
|
|
|
2020-07-02 06:09:26 +00:00
|
|
|
describe '.object_store_config' do
|
2020-06-04 15:08:21 +00:00
|
|
|
let(:component) { 'lfs' }
|
2020-04-29 15:09:58 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
subject { described_class.object_store_config(component) }
|
2020-04-29 15:09:58 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'when object_store is not configured' do
|
|
|
|
it 'returns component enable status only' do
|
|
|
|
allow(Settings).to receive(:[]).with(component).and_return({ 'enabled' => false })
|
2020-04-29 15:09:58 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(subject).to eq({ enabled: false })
|
2020-04-29 15:09:58 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-04-29 15:09:58 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'when object_store is configured' do
|
|
|
|
it 'returns filtered object store config' do
|
|
|
|
allow(Settings).to receive(:[]).with(component)
|
|
|
|
.and_return(
|
|
|
|
{ 'enabled' => true,
|
|
|
|
'object_store' =>
|
2020-04-29 15:09:58 +00:00
|
|
|
{ 'enabled' => true,
|
2020-06-04 15:08:21 +00:00
|
|
|
'remote_directory' => component,
|
|
|
|
'direct_upload' => true,
|
|
|
|
'connection' =>
|
|
|
|
{ 'provider' => 'AWS', 'aws_access_key_id' => 'minio', 'aws_secret_access_key' => 'gdk-minio', 'region' => 'gdk', 'endpoint' => 'http://127.0.0.1:9000', 'path_style' => true },
|
|
|
|
'background_upload' => false,
|
|
|
|
'proxy_download' => false } })
|
|
|
|
|
|
|
|
expect(subject).to eq(
|
|
|
|
{ enabled: true, object_store: { enabled: true, direct_upload: true, background_upload: false, provider: "AWS" } })
|
2020-04-29 15:09:58 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-04-29 15:09:58 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'when retrieve component setting meets exception' do
|
|
|
|
it 'returns -1 for component enable status' do
|
|
|
|
allow(Settings).to receive(:[]).with(component).and_raise(StandardError)
|
2020-04-29 15:09:58 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(subject).to eq({ enabled: -1 })
|
2020-04-29 15:09:58 +00:00
|
|
|
end
|
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-04-29 15:09:58 +00:00
|
|
|
|
2020-07-02 06:09:26 +00:00
|
|
|
describe '.object_store_usage_data' do
|
2020-06-04 15:08:21 +00:00
|
|
|
subject { described_class.object_store_usage_data }
|
2020-04-29 15:09:58 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'fetches object store config of five components' do
|
|
|
|
%w(artifacts external_diffs lfs uploads packages).each do |component|
|
|
|
|
expect(described_class).to receive(:object_store_config).with(component).and_return("#{component}_object_store_config")
|
2020-04-29 15:09:58 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
|
|
|
|
expect(subject).to eq(
|
|
|
|
object_store: {
|
|
|
|
artifacts: 'artifacts_object_store_config',
|
|
|
|
external_diffs: 'external_diffs_object_store_config',
|
|
|
|
lfs: 'lfs_object_store_config',
|
|
|
|
uploads: 'uploads_object_store_config',
|
|
|
|
packages: 'packages_object_store_config'
|
|
|
|
})
|
2020-04-29 15:09:58 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-04-29 15:09:58 +00:00
|
|
|
|
2020-07-02 06:09:26 +00:00
|
|
|
describe '.ingress_modsecurity_usage' do
|
2020-06-04 15:08:21 +00:00
|
|
|
subject { described_class.ingress_modsecurity_usage }
|
|
|
|
|
|
|
|
let(:environment) { create(:environment) }
|
|
|
|
let(:project) { environment.project }
|
|
|
|
let(:environment_scope) { '*' }
|
|
|
|
let(:deployment) { create(:deployment, :success, environment: environment, project: project, cluster: cluster) }
|
|
|
|
let(:cluster) { create(:cluster, environment_scope: environment_scope, projects: [project]) }
|
|
|
|
let(:ingress_mode) { :modsecurity_blocking }
|
|
|
|
let!(:ingress) { create(:clusters_applications_ingress, ingress_mode, cluster: cluster) }
|
|
|
|
|
|
|
|
context 'when cluster is disabled' do
|
|
|
|
let(:cluster) { create(:cluster, :disabled, projects: [project]) }
|
|
|
|
|
|
|
|
it 'gathers ingress data' do
|
|
|
|
expect(subject[:ingress_modsecurity_logging]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_blocking]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_disabled]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_not_installed]).to eq(0)
|
2020-03-05 18:08:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'when deployment is unsuccessful' do
|
|
|
|
let!(:deployment) { create(:deployment, :failed, environment: environment, project: project, cluster: cluster) }
|
2020-02-17 18:09:00 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'gathers ingress data' do
|
|
|
|
expect(subject[:ingress_modsecurity_logging]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_blocking]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_disabled]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_not_installed]).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
2020-05-04 03:09:50 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'when deployment is successful' do
|
|
|
|
let!(:deployment) { create(:deployment, :success, environment: environment, project: project, cluster: cluster) }
|
2020-05-04 03:09:50 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'when modsecurity is in blocking mode' do
|
2020-05-04 03:09:50 +00:00
|
|
|
it 'gathers ingress data' do
|
|
|
|
expect(subject[:ingress_modsecurity_logging]).to eq(0)
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(subject[:ingress_modsecurity_blocking]).to eq(1)
|
2020-05-04 03:09:50 +00:00
|
|
|
expect(subject[:ingress_modsecurity_disabled]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_not_installed]).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'when modsecurity is in logging mode' do
|
|
|
|
let(:ingress_mode) { :modsecurity_logging }
|
2020-05-04 03:09:50 +00:00
|
|
|
|
|
|
|
it 'gathers ingress data' do
|
2020-06-04 15:08:21 +00:00
|
|
|
expect(subject[:ingress_modsecurity_logging]).to eq(1)
|
2020-05-04 03:09:50 +00:00
|
|
|
expect(subject[:ingress_modsecurity_blocking]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_disabled]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_not_installed]).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'when modsecurity is disabled' do
|
|
|
|
let(:ingress_mode) { :modsecurity_disabled }
|
2020-05-04 03:09:50 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'gathers ingress data' do
|
|
|
|
expect(subject[:ingress_modsecurity_logging]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_blocking]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_disabled]).to eq(1)
|
|
|
|
expect(subject[:ingress_modsecurity_not_installed]).to eq(0)
|
2020-05-04 03:09:50 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-05-04 03:09:50 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'when modsecurity is not installed' do
|
|
|
|
let(:ingress_mode) { :modsecurity_not_installed }
|
2020-05-04 03:09:50 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'gathers ingress data' do
|
|
|
|
expect(subject[:ingress_modsecurity_logging]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_blocking]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_disabled]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_not_installed]).to eq(1)
|
2020-05-04 03:09:50 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-05-04 03:09:50 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'with multiple projects' do
|
|
|
|
let(:environment_2) { create(:environment) }
|
|
|
|
let(:project_2) { environment_2.project }
|
|
|
|
let(:cluster_2) { create(:cluster, environment_scope: environment_scope, projects: [project_2]) }
|
|
|
|
let!(:ingress_2) { create(:clusters_applications_ingress, :modsecurity_logging, cluster: cluster_2) }
|
|
|
|
let!(:deployment_2) { create(:deployment, :success, environment: environment_2, project: project_2, cluster: cluster_2) }
|
2020-05-04 03:09:50 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'gathers non-duplicated ingress data' do
|
|
|
|
expect(subject[:ingress_modsecurity_logging]).to eq(1)
|
|
|
|
expect(subject[:ingress_modsecurity_blocking]).to eq(1)
|
|
|
|
expect(subject[:ingress_modsecurity_disabled]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_not_installed]).to eq(0)
|
2020-05-04 03:09:50 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-05-04 03:09:50 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'with multiple deployments' do
|
|
|
|
let!(:deployment_2) { create(:deployment, :success, environment: environment, project: project, cluster: cluster) }
|
2020-05-04 03:09:50 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'gathers non-duplicated ingress data' do
|
|
|
|
expect(subject[:ingress_modsecurity_logging]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_blocking]).to eq(1)
|
|
|
|
expect(subject[:ingress_modsecurity_disabled]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_not_installed]).to eq(0)
|
2020-05-04 03:09:50 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-05-04 03:09:50 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'with multiple projects' do
|
|
|
|
let(:environment_2) { create(:environment) }
|
|
|
|
let(:project_2) { environment_2.project }
|
|
|
|
let!(:deployment_2) { create(:deployment, :success, environment: environment_2, project: project_2, cluster: cluster) }
|
|
|
|
let(:cluster) { create(:cluster, environment_scope: environment_scope, projects: [project, project_2]) }
|
2020-05-04 03:09:50 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'gathers ingress data' do
|
|
|
|
expect(subject[:ingress_modsecurity_logging]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_blocking]).to eq(2)
|
|
|
|
expect(subject[:ingress_modsecurity_disabled]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_not_installed]).to eq(0)
|
2020-05-04 03:09:50 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-05-04 03:09:50 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'with multiple environments' do
|
|
|
|
let!(:environment_2) { create(:environment, project: project) }
|
|
|
|
let!(:deployment_2) { create(:deployment, :success, environment: environment_2, project: project, cluster: cluster) }
|
2020-05-04 03:09:50 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'gathers ingress data' do
|
|
|
|
expect(subject[:ingress_modsecurity_logging]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_blocking]).to eq(2)
|
|
|
|
expect(subject[:ingress_modsecurity_disabled]).to eq(0)
|
|
|
|
expect(subject[:ingress_modsecurity_not_installed]).to eq(0)
|
2020-05-04 03:09:50 +00:00
|
|
|
end
|
2020-02-17 18:09:00 +00:00
|
|
|
end
|
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2017-09-15 16:23:56 +00:00
|
|
|
|
2020-07-02 06:09:26 +00:00
|
|
|
describe '.grafana_embed_usage_data' do
|
2020-06-04 15:08:21 +00:00
|
|
|
subject { described_class.grafana_embed_usage_data }
|
2020-04-09 12:09:24 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:description_with_embed) { "Some comment\n\nhttps://grafana.example.com/d/xvAk4q0Wk/go-processes?orgId=1&from=1573238522762&to=1573240322762&var-job=prometheus&var-interval=10m&panelId=1&fullscreen" }
|
|
|
|
let(:description_with_unintegrated_embed) { "Some comment\n\nhttps://grafana.exp.com/d/xvAk4q0Wk/go-processes?orgId=1&from=1573238522762&to=1573240322762&var-job=prometheus&var-interval=10m&panelId=1&fullscreen" }
|
|
|
|
let(:description_with_non_grafana_inline_metric) { "Some comment\n\n#{Gitlab::Routing.url_helpers.metrics_namespace_project_environment_url(*['foo', 'bar', 12])}" }
|
2020-04-09 12:09:24 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
shared_examples "zero count" do
|
|
|
|
it "does not count the issue" do
|
|
|
|
expect(subject).to eq(0)
|
2020-04-09 12:09:24 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-04-09 12:09:24 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'with project grafana integration enabled' do
|
|
|
|
before do
|
|
|
|
create(:grafana_integration, project: project, enabled: true)
|
2020-04-09 12:09:24 +00:00
|
|
|
end
|
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'with valid and invalid embeds' do
|
2020-04-09 12:09:24 +00:00
|
|
|
before do
|
2020-06-04 15:08:21 +00:00
|
|
|
# Valid
|
|
|
|
create(:issue, project: project, description: description_with_embed)
|
|
|
|
create(:issue, project: project, description: description_with_embed)
|
|
|
|
# In-Valid
|
|
|
|
create(:issue, project: project, description: description_with_unintegrated_embed)
|
|
|
|
create(:issue, project: project, description: description_with_non_grafana_inline_metric)
|
|
|
|
create(:issue, project: project, description: nil)
|
|
|
|
create(:issue, project: project, description: '')
|
|
|
|
create(:issue, project: project)
|
2020-04-09 12:09:24 +00:00
|
|
|
end
|
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it 'counts only the issues with embeds' do
|
|
|
|
expect(subject).to eq(2)
|
2020-04-09 12:09:24 +00:00
|
|
|
end
|
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
end
|
2020-04-09 12:09:24 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'with project grafana integration disabled' do
|
|
|
|
before do
|
|
|
|
create(:grafana_integration, project: project, enabled: false)
|
|
|
|
end
|
2020-04-09 12:09:24 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'with one issue having a grafana link in the description and one without' do
|
|
|
|
before do
|
|
|
|
create(:issue, project: project, description: description_with_embed)
|
|
|
|
create(:issue, project: project)
|
2020-04-09 12:09:24 +00:00
|
|
|
end
|
2020-06-04 15:08:21 +00:00
|
|
|
|
|
|
|
it_behaves_like('zero count')
|
2020-04-09 12:09:24 +00:00
|
|
|
end
|
|
|
|
end
|
2020-03-18 15:09:45 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
context 'with an un-integrated project' do
|
|
|
|
context 'with one issue having a grafana link in the description and one without' do
|
|
|
|
before do
|
|
|
|
create(:issue, project: project, description: description_with_embed)
|
|
|
|
create(:issue, project: project)
|
|
|
|
end
|
2020-03-18 15:09:45 +00:00
|
|
|
|
2020-06-04 15:08:21 +00:00
|
|
|
it_behaves_like('zero count')
|
|
|
|
end
|
|
|
|
end
|
2020-03-18 15:09:45 +00:00
|
|
|
end
|
2020-12-11 21:10:13 +00:00
|
|
|
|
2021-03-03 15:10:53 +00:00
|
|
|
describe ".operating_system" do
|
|
|
|
let(:ohai_data) { { "platform" => "ubuntu", "platform_version" => "20.04" } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_next_instance_of(Ohai::System) do |ohai|
|
|
|
|
allow(ohai).to receive(:data).and_return(ohai_data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.operating_system }
|
|
|
|
|
|
|
|
it { is_expected.to eq("ubuntu-20.04") }
|
|
|
|
|
|
|
|
context 'when on Debian with armv architecture' do
|
|
|
|
let(:ohai_data) { { "platform" => "debian", "platform_version" => "10", 'kernel' => { 'machine' => 'armv' } } }
|
|
|
|
|
|
|
|
it { is_expected.to eq("raspbian-10") }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-11 21:10:13 +00:00
|
|
|
describe ".system_usage_data_settings" do
|
2021-04-21 09:09:15 +00:00
|
|
|
let(:prometheus_client) { double(Gitlab::PrometheusClient) }
|
|
|
|
|
2021-03-03 15:10:53 +00:00
|
|
|
before do
|
|
|
|
allow(described_class).to receive(:operating_system).and_return('ubuntu-20.04')
|
2021-04-21 09:09:15 +00:00
|
|
|
expect(prometheus_client).to receive(:query).with(/gitlab_usage_ping:gitaly_apdex:ratio_avg_over_time_5m/).and_return([
|
|
|
|
{
|
|
|
|
'metric' => {},
|
|
|
|
'value' => [1616016381.473, '0.95']
|
|
|
|
}
|
|
|
|
])
|
|
|
|
expect(described_class).to receive(:with_prometheus_client).and_yield(prometheus_client)
|
2021-03-03 15:10:53 +00:00
|
|
|
end
|
|
|
|
|
2020-12-11 21:10:13 +00:00
|
|
|
subject { described_class.system_usage_data_settings }
|
|
|
|
|
|
|
|
it 'gathers settings usage data', :aggregate_failures do
|
|
|
|
expect(subject[:settings][:ldap_encrypted_secrets_enabled]).to eq(Gitlab::Auth::Ldap::Config.encrypted_secrets.active?)
|
|
|
|
end
|
2021-03-03 15:10:53 +00:00
|
|
|
|
|
|
|
it 'populates operating system information' do
|
|
|
|
expect(subject[:settings][:operating_system]).to eq('ubuntu-20.04')
|
|
|
|
end
|
2021-04-21 09:09:15 +00:00
|
|
|
|
|
|
|
it 'gathers gitaly apdex', :aggregate_failures do
|
|
|
|
expect(subject[:settings][:gitaly_apdex]).to be_within(0.001).of(0.95)
|
|
|
|
end
|
2020-12-11 21:10:13 +00:00
|
|
|
end
|
2020-03-18 15:09:45 +00:00
|
|
|
end
|
2020-06-03 00:08:38 +00:00
|
|
|
|
2020-09-02 12:10:35 +00:00
|
|
|
describe '.merge_requests_users', :clean_gitlab_redis_shared_state do
|
|
|
|
let(:time_period) { { created_at: 2.days.ago..time } }
|
|
|
|
let(:time) { Time.current }
|
2020-06-03 00:08:38 +00:00
|
|
|
|
|
|
|
before do
|
2020-09-02 12:10:35 +00:00
|
|
|
counter = Gitlab::UsageDataCounters::TrackUniqueEvents
|
|
|
|
merge_request = Event::TARGET_TYPES[:merge_request]
|
2020-09-09 09:08:40 +00:00
|
|
|
design = Event::TARGET_TYPES[:design]
|
2020-09-02 12:10:35 +00:00
|
|
|
|
|
|
|
counter.track_event(event_action: :commented, event_target: merge_request, author_id: 1, time: time)
|
|
|
|
counter.track_event(event_action: :opened, event_target: merge_request, author_id: 1, time: time)
|
|
|
|
counter.track_event(event_action: :merged, event_target: merge_request, author_id: 2, time: time)
|
|
|
|
counter.track_event(event_action: :closed, event_target: merge_request, author_id: 3, time: time)
|
|
|
|
counter.track_event(event_action: :opened, event_target: merge_request, author_id: 4, time: time - 3.days)
|
2020-09-09 09:08:40 +00:00
|
|
|
counter.track_event(event_action: :created, event_target: design, author_id: 5, time: time)
|
2020-06-03 00:08:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the distinct count of users using merge requests (via events table) within the specified time period' do
|
2020-09-02 12:10:35 +00:00
|
|
|
expect(described_class.merge_requests_users(time_period)).to eq(3)
|
2020-06-03 00:08:38 +00:00
|
|
|
end
|
|
|
|
end
|
2020-06-19 12:09:07 +00:00
|
|
|
|
2020-09-28 12:10:02 +00:00
|
|
|
def for_defined_days_back(days: [31, 3])
|
2020-06-19 12:09:07 +00:00
|
|
|
days.each do |n|
|
2020-10-19 21:09:06 +00:00
|
|
|
travel_to(n.days.ago) do
|
2020-06-19 12:09:07 +00:00
|
|
|
yield
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-06-22 15:09:27 +00:00
|
|
|
|
2020-07-15 15:09:21 +00:00
|
|
|
describe '#action_monthly_active_users', :clean_gitlab_redis_shared_state do
|
|
|
|
let(:time_period) { { created_at: 2.days.ago..time } }
|
|
|
|
let(:time) { Time.zone.now }
|
2020-09-03 12:08:47 +00:00
|
|
|
let(:user1) { build(:user, id: 1) }
|
|
|
|
let(:user2) { build(:user, id: 2) }
|
|
|
|
let(:user3) { build(:user, id: 3) }
|
2020-11-12 21:09:19 +00:00
|
|
|
let(:user4) { build(:user, id: 4) }
|
2020-07-15 15:09:21 +00:00
|
|
|
|
|
|
|
before do
|
2020-08-20 15:10:18 +00:00
|
|
|
counter = Gitlab::UsageDataCounters::TrackUniqueEvents
|
2020-08-18 15:10:33 +00:00
|
|
|
project = Event::TARGET_TYPES[:project]
|
|
|
|
wiki = Event::TARGET_TYPES[:wiki]
|
|
|
|
design = Event::TARGET_TYPES[:design]
|
|
|
|
|
|
|
|
counter.track_event(event_action: :pushed, event_target: project, author_id: 1)
|
|
|
|
counter.track_event(event_action: :pushed, event_target: project, author_id: 1)
|
|
|
|
counter.track_event(event_action: :pushed, event_target: project, author_id: 2)
|
|
|
|
counter.track_event(event_action: :pushed, event_target: project, author_id: 3)
|
|
|
|
counter.track_event(event_action: :pushed, event_target: project, author_id: 4, time: time - 3.days)
|
|
|
|
counter.track_event(event_action: :created, event_target: wiki, author_id: 3)
|
|
|
|
counter.track_event(event_action: :created, event_target: design, author_id: 3)
|
2020-11-12 21:09:19 +00:00
|
|
|
counter.track_event(event_action: :created, event_target: design, author_id: 4)
|
2020-09-03 12:08:47 +00:00
|
|
|
|
|
|
|
counter = Gitlab::UsageDataCounters::EditorUniqueCounter
|
|
|
|
|
|
|
|
counter.track_web_ide_edit_action(author: user1)
|
|
|
|
counter.track_web_ide_edit_action(author: user1)
|
|
|
|
counter.track_sfe_edit_action(author: user1)
|
|
|
|
counter.track_snippet_editor_edit_action(author: user1)
|
|
|
|
counter.track_snippet_editor_edit_action(author: user1, time: time - 3.days)
|
|
|
|
|
|
|
|
counter.track_web_ide_edit_action(author: user2)
|
|
|
|
counter.track_sfe_edit_action(author: user2)
|
|
|
|
|
|
|
|
counter.track_web_ide_edit_action(author: user3, time: time - 3.days)
|
|
|
|
counter.track_snippet_editor_edit_action(author: user3)
|
2020-11-26 15:09:30 +00:00
|
|
|
|
|
|
|
counter.track_sse_edit_action(author: user1)
|
|
|
|
counter.track_sse_edit_action(author: user1)
|
|
|
|
counter.track_sse_edit_action(author: user2)
|
|
|
|
counter.track_sse_edit_action(author: user3)
|
|
|
|
counter.track_sse_edit_action(author: user2, time: time - 3.days)
|
2020-08-18 15:10:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the distinct count of user actions within the specified time period' do
|
|
|
|
expect(described_class.action_monthly_active_users(time_period)).to eq(
|
|
|
|
{
|
2020-11-12 21:09:19 +00:00
|
|
|
action_monthly_active_users_design_management: 2,
|
2020-08-18 15:10:33 +00:00
|
|
|
action_monthly_active_users_project_repo: 3,
|
2020-09-03 12:08:47 +00:00
|
|
|
action_monthly_active_users_wiki_repo: 1,
|
2020-11-12 21:09:19 +00:00
|
|
|
action_monthly_active_users_git_write: 4,
|
2020-09-03 12:08:47 +00:00
|
|
|
action_monthly_active_users_web_ide_edit: 2,
|
|
|
|
action_monthly_active_users_sfe_edit: 2,
|
|
|
|
action_monthly_active_users_snippet_editor_edit: 2,
|
2020-11-26 15:09:30 +00:00
|
|
|
action_monthly_active_users_ide_edit: 3,
|
|
|
|
action_monthly_active_users_sse_edit: 3
|
2020-08-18 15:10:33 +00:00
|
|
|
}
|
|
|
|
)
|
2020-07-15 15:09:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-22 15:09:27 +00:00
|
|
|
describe '.analytics_unique_visits_data' do
|
|
|
|
subject { described_class.analytics_unique_visits_data }
|
|
|
|
|
|
|
|
it 'returns the number of unique visits to pages with analytics features' do
|
2020-08-25 09:10:42 +00:00
|
|
|
::Gitlab::Analytics::UniqueVisits.analytics_events.each do |target|
|
|
|
|
expect_any_instance_of(::Gitlab::Analytics::UniqueVisits).to receive(:unique_visits_for).with(targets: target).and_return(123)
|
2020-06-22 15:09:27 +00:00
|
|
|
end
|
|
|
|
|
2020-08-13 03:10:13 +00:00
|
|
|
expect_any_instance_of(::Gitlab::Analytics::UniqueVisits).to receive(:unique_visits_for).with(targets: :analytics).and_return(543)
|
2020-08-19 18:10:34 +00:00
|
|
|
expect_any_instance_of(::Gitlab::Analytics::UniqueVisits).to receive(:unique_visits_for).with(targets: :analytics, start_date: 4.weeks.ago.to_date, end_date: Date.current).and_return(987)
|
2020-06-22 15:09:27 +00:00
|
|
|
|
|
|
|
expect(subject).to eq({
|
|
|
|
analytics_unique_visits: {
|
|
|
|
'g_analytics_contribution' => 123,
|
|
|
|
'g_analytics_insights' => 123,
|
|
|
|
'g_analytics_issues' => 123,
|
|
|
|
'g_analytics_productivity' => 123,
|
|
|
|
'g_analytics_valuestream' => 123,
|
|
|
|
'p_analytics_pipelines' => 123,
|
|
|
|
'p_analytics_code_reviews' => 123,
|
|
|
|
'p_analytics_valuestream' => 123,
|
|
|
|
'p_analytics_insights' => 123,
|
|
|
|
'p_analytics_issues' => 123,
|
|
|
|
'p_analytics_repo' => 123,
|
|
|
|
'i_analytics_cohorts' => 123,
|
|
|
|
'i_analytics_dev_ops_score' => 123,
|
2020-09-16 12:10:15 +00:00
|
|
|
'i_analytics_instance_statistics' => 123,
|
2020-08-31 18:10:43 +00:00
|
|
|
'p_analytics_merge_request' => 123,
|
|
|
|
'g_analytics_merge_request' => 123,
|
2021-04-27 15:09:52 +00:00
|
|
|
'i_analytics_dev_ops_adoption' => 123,
|
|
|
|
'users_viewing_analytics_group_devops_adoption' => 123,
|
2020-07-23 21:09:19 +00:00
|
|
|
'analytics_unique_visits_for_any_target' => 543,
|
|
|
|
'analytics_unique_visits_for_any_target_monthly' => 987
|
2020-06-22 15:09:27 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2020-07-22 21:09:50 +00:00
|
|
|
|
2020-08-13 03:10:13 +00:00
|
|
|
describe '.compliance_unique_visits_data' do
|
|
|
|
subject { described_class.compliance_unique_visits_data }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_next_instance_of(::Gitlab::Analytics::UniqueVisits) do |instance|
|
2020-08-25 09:10:42 +00:00
|
|
|
::Gitlab::Analytics::UniqueVisits.compliance_events.each do |target|
|
|
|
|
allow(instance).to receive(:unique_visits_for).with(targets: target).and_return(123)
|
2020-08-13 03:10:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
allow(instance).to receive(:unique_visits_for).with(targets: :compliance).and_return(543)
|
|
|
|
|
2020-08-19 18:10:34 +00:00
|
|
|
allow(instance).to receive(:unique_visits_for).with(targets: :compliance, start_date: 4.weeks.ago.to_date, end_date: Date.current).and_return(987)
|
2020-08-13 03:10:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the number of unique visits to pages with compliance features' do
|
|
|
|
expect(subject).to eq({
|
|
|
|
compliance_unique_visits: {
|
|
|
|
'g_compliance_dashboard' => 123,
|
|
|
|
'g_compliance_audit_events' => 123,
|
|
|
|
'i_compliance_credential_inventory' => 123,
|
|
|
|
'i_compliance_audit_events' => 123,
|
2020-09-18 00:09:39 +00:00
|
|
|
'a_compliance_audit_events_api' => 123,
|
2020-08-13 03:10:13 +00:00
|
|
|
'compliance_unique_visits_for_any_target' => 543,
|
|
|
|
'compliance_unique_visits_for_any_target_monthly' => 987
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-28 12:10:37 +00:00
|
|
|
describe '.search_unique_visits_data' do
|
|
|
|
subject { described_class.search_unique_visits_data }
|
|
|
|
|
|
|
|
before do
|
|
|
|
events = ::Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category('search')
|
|
|
|
events.each do |event|
|
|
|
|
allow(::Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:unique_events).with(event_names: event, start_date: 7.days.ago.to_date, end_date: Date.current).and_return(123)
|
|
|
|
end
|
|
|
|
allow(::Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:unique_events).with(event_names: events, start_date: 7.days.ago.to_date, end_date: Date.current).and_return(543)
|
|
|
|
allow(::Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:unique_events).with(event_names: events, start_date: 4.weeks.ago.to_date, end_date: Date.current).and_return(987)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the number of unique visits to pages with search features' do
|
|
|
|
expect(subject).to eq({
|
|
|
|
search_unique_visits: {
|
|
|
|
'i_search_total' => 123,
|
|
|
|
'i_search_advanced' => 123,
|
|
|
|
'i_search_paid' => 123,
|
|
|
|
'search_unique_visits_for_any_target_weekly' => 543,
|
|
|
|
'search_unique_visits_for_any_target_monthly' => 987
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-04 18:08:48 +00:00
|
|
|
describe 'redis_hll_counters' do
|
|
|
|
subject { described_class.redis_hll_counters }
|
|
|
|
|
|
|
|
let(:categories) { ::Gitlab::UsageDataCounters::HLLRedisCounter.categories }
|
2021-02-04 12:09:25 +00:00
|
|
|
let(:ineligible_total_categories) do
|
2021-04-16 09:09:16 +00:00
|
|
|
%w[source_code ci_secrets_management incident_management_alerts snippets terraform incident_management_oncall secure]
|
2021-02-04 12:09:25 +00:00
|
|
|
end
|
2020-09-04 18:08:48 +00:00
|
|
|
|
2021-03-23 12:09:33 +00:00
|
|
|
context 'with redis_hll_tracking feature enabled' do
|
|
|
|
it 'has all known_events' do
|
|
|
|
stub_feature_flags(redis_hll_tracking: true)
|
2020-09-04 18:08:48 +00:00
|
|
|
|
2021-03-23 12:09:33 +00:00
|
|
|
expect(subject).to have_key(:redis_hll_counters)
|
2020-09-04 18:08:48 +00:00
|
|
|
|
2021-03-23 12:09:33 +00:00
|
|
|
expect(subject[:redis_hll_counters].keys).to match_array(categories)
|
2020-09-09 09:08:40 +00:00
|
|
|
|
2021-03-23 12:09:33 +00:00
|
|
|
categories.each do |category|
|
|
|
|
keys = ::Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category(category)
|
2020-09-23 09:10:07 +00:00
|
|
|
|
2021-03-23 12:09:33 +00:00
|
|
|
metrics = keys.map { |key| "#{key}_weekly" } + keys.map { |key| "#{key}_monthly" }
|
|
|
|
|
|
|
|
if ineligible_total_categories.exclude?(category)
|
|
|
|
metrics.append("#{category}_total_unique_counts_weekly", "#{category}_total_unique_counts_monthly")
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(subject[:redis_hll_counters][category].keys).to match_array(metrics)
|
2020-09-09 09:08:40 +00:00
|
|
|
end
|
2021-03-23 12:09:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with redis_hll_tracking disabled' do
|
|
|
|
it 'does not have redis_hll_tracking key' do
|
|
|
|
stub_feature_flags(redis_hll_tracking: false)
|
2020-09-04 18:08:48 +00:00
|
|
|
|
2021-03-23 12:09:33 +00:00
|
|
|
expect(subject).not_to have_key(:redis_hll_counters)
|
2020-09-04 18:08:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-08 18:09:12 +00:00
|
|
|
describe '.aggregated_metrics_data' do
|
|
|
|
it 'uses ::Gitlab::Usage::Metrics::Aggregates::Aggregate methods', :aggregate_failures do
|
|
|
|
expected_payload = {
|
|
|
|
counts_weekly: { aggregated_metrics: { global_search_gmau: 123 } },
|
|
|
|
counts_monthly: { aggregated_metrics: { global_search_gmau: 456 } },
|
|
|
|
counts: { aggregate_global_search_gmau: 789 }
|
|
|
|
}
|
2020-11-04 15:08:41 +00:00
|
|
|
|
2021-02-01 12:09:03 +00:00
|
|
|
expect_next_instance_of(::Gitlab::Usage::Metrics::Aggregates::Aggregate) do |instance|
|
|
|
|
expect(instance).to receive(:weekly_data).and_return(global_search_gmau: 123)
|
2021-03-08 18:09:12 +00:00
|
|
|
expect(instance).to receive(:monthly_data).and_return(global_search_gmau: 456)
|
|
|
|
expect(instance).to receive(:all_time_data).and_return(global_search_gmau: 789)
|
2021-02-01 12:09:03 +00:00
|
|
|
end
|
2021-03-08 18:09:12 +00:00
|
|
|
expect(described_class.aggregated_metrics_data).to eq(expected_payload)
|
2020-11-03 00:08:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-22 21:09:50 +00:00
|
|
|
describe '.service_desk_counts' do
|
|
|
|
subject { described_class.send(:service_desk_counts) }
|
|
|
|
|
|
|
|
let(:project) { create(:project, :service_desk_enabled) }
|
|
|
|
|
|
|
|
it 'gathers Service Desk data' do
|
|
|
|
create_list(:issue, 2, :confidential, author: User.support_bot, project: project)
|
|
|
|
|
|
|
|
expect(subject).to eq(service_desk_enabled_projects: 1,
|
|
|
|
service_desk_issues: 2)
|
|
|
|
end
|
|
|
|
end
|
2020-09-10 00:08:32 +00:00
|
|
|
|
|
|
|
describe '.snowplow_event_counts' do
|
2020-10-01 15:10:05 +00:00
|
|
|
let_it_be(:time_period) { { collector_tstamp: 8.days.ago..1.day.ago } }
|
|
|
|
|
2020-09-10 00:08:32 +00:00
|
|
|
context 'when self-monitoring project exists' do
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_application_setting(self_monitoring_project: project)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and product_analytics FF is enabled for it' do
|
|
|
|
before do
|
2020-12-07 15:09:49 +00:00
|
|
|
stub_feature_flags(product_analytics_tracking: true)
|
2020-09-10 00:08:32 +00:00
|
|
|
|
|
|
|
create(:product_analytics_event, project: project, se_category: 'epics', se_action: 'promote')
|
2020-10-01 15:10:05 +00:00
|
|
|
create(:product_analytics_event, project: project, se_category: 'epics', se_action: 'promote', collector_tstamp: 2.days.ago)
|
|
|
|
create(:product_analytics_event, project: project, se_category: 'epics', se_action: 'promote', collector_tstamp: 9.days.ago)
|
|
|
|
|
|
|
|
create(:product_analytics_event, project: project, se_category: 'foo', se_action: 'bar', collector_tstamp: 2.days.ago)
|
2020-09-10 00:08:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns promoted_issues for the time period' do
|
2020-10-01 15:10:05 +00:00
|
|
|
expect(described_class.snowplow_event_counts(time_period)[:promoted_issues]).to eq(1)
|
2020-09-10 00:08:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and product_analytics FF is disabled' do
|
|
|
|
before do
|
2020-12-07 15:09:49 +00:00
|
|
|
stub_feature_flags(product_analytics_tracking: false)
|
2020-09-10 00:08:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty hash' do
|
2020-10-01 15:10:05 +00:00
|
|
|
expect(described_class.snowplow_event_counts(time_period)).to eq({})
|
2020-09-10 00:08:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when self-monitoring project does not exist' do
|
|
|
|
it 'returns an empty hash' do
|
2020-10-01 15:10:05 +00:00
|
|
|
expect(described_class.snowplow_event_counts(time_period)).to eq({})
|
2020-09-10 00:08:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-05 12:29:48 +00:00
|
|
|
end
|