Commit 98465b76 authored by Alper Akgun's avatar Alper Akgun

Speed up usage data specs

- It moves usage_activity_by_stage stage counters into separate
describe blocks
parent 939b05db
...@@ -13,8 +13,14 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -13,8 +13,14 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
describe '.uncached_data' do describe '.uncached_data' do
describe '.usage_activity_by_stage' do describe '.usage_activity_by_stage' do
it 'includes usage_activity_by_stage data' do it 'includes usage_activity_by_stage data' do
expect(described_class.uncached_data).to include(:usage_activity_by_stage) uncached_data = described_class.uncached_data
expect(described_class.uncached_data).to include(:usage_activity_by_stage_monthly)
expect(uncached_data).to include(:usage_activity_by_stage)
expect(uncached_data).to include(:usage_activity_by_stage_monthly)
expect(uncached_data[:usage_activity_by_stage])
.to include(:configure, :create, :manage, :monitor, :plan, :release, :verify)
expect(uncached_data[:usage_activity_by_stage_monthly])
.to include(:configure, :create, :manage, :monitor, :plan, :release, :verify)
end end
it 'clears memoized values' do it 'clears memoized values' do
...@@ -30,274 +36,269 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -30,274 +36,269 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
described_class.uncached_data described_class.uncached_data
end end
context 'for configure' do it 'merge_requests_users is included only in montly counters' do
it 'includes accurate usage_activity_by_stage data' do uncached_data = described_class.uncached_data
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)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:configure]).to include( expect(uncached_data[:usage_activity_by_stage][:create])
clusters_applications_cert_managers: 2, .not_to include(:merge_requests_users)
clusters_applications_helm: 2, expect(uncached_data[:usage_activity_by_stage_monthly][:create])
clusters_applications_ingress: 2, .to include(:merge_requests_users)
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.uncached_data[:usage_activity_by_stage_monthly][:configure]).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 end
end
context 'for create' do it 'ensures recorded_at is set before any other usage data calculation' do
it 'include usage_activity_by_stage data' do %i(alt_usage_data redis_usage_data distinct_count count).each do |method|
expect(described_class.uncached_data[:usage_activity_by_stage][:create]) expect(described_class).not_to receive(method)
.not_to include(
:merge_requests_users
)
end
it 'includes monthly usage_activity_by_stage data' do
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:create])
.to include(
:merge_requests_users
)
end
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)
create(:remote_mirror, project: project)
create(:snippet, author: user)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:create]).to include(
deploy_keys: 2,
keys: 2,
merge_requests: 2,
projects_with_disable_overriding_approvers_per_merge_request: 2,
projects_without_disable_overriding_approvers_per_merge_request: 4,
remote_mirrors: 2,
snippets: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:create]).to include(
deploy_keys: 1,
keys: 1,
merge_requests: 1,
projects_with_disable_overriding_approvers_per_merge_request: 1,
projects_without_disable_overriding_approvers_per_merge_request: 2,
remote_mirrors: 1,
snippets: 1
)
end
end end
expect(described_class).to receive(:recorded_at).and_raise(Exception.new('Stopped calculating recorded_at'))
context 'for manage' do expect { described_class.uncached_data }.to raise_error('Stopped calculating recorded_at')
it 'includes accurate usage_activity_by_stage data' do end
stub_config( end
omniauth:
{ providers: omniauth_providers }
)
for_defined_days_back do
user = create(:user)
create(:event, author: user)
create(:group_member, user: user)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:manage]).to include( describe '.usage_activity_by_stage_configure' do
events: 2, it 'includes accurate usage_activity_by_stage data' do
groups: 2, for_defined_days_back do
users_created: 6, user = create(:user)
omniauth_providers: ['google_oauth2'] cluster = create(:cluster, user: user)
) create(:clusters_applications_cert_manager, :installed, cluster: cluster)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:manage]).to include( create(:clusters_applications_helm, :installed, cluster: cluster)
events: 1, create(:clusters_applications_ingress, :installed, cluster: cluster)
groups: 1, create(:clusters_applications_knative, :installed, cluster: cluster)
users_created: 4, create(:cluster, :disabled, user: user)
omniauth_providers: ['google_oauth2'] create(:cluster_provider_gcp, :created)
) create(:cluster_provider_aws, :created)
end 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)
end
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
def omniauth_providers describe 'usage_activity_by_stage_create' do
[ it 'includes accurate usage_activity_by_stage data' do
OpenStruct.new(name: 'google_oauth2'), for_defined_days_back do
OpenStruct.new(name: 'ldapmain'), user = create(:user)
OpenStruct.new(name: 'group_saml') project = create(:project, :repository_private,
] :test_repo, :remote_mirror, creator: user)
end create(:merge_request, source_project: project)
end 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)
create(:remote_mirror, project: project)
create(:snippet, author: user)
end
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,
projects_without_disable_overriding_approvers_per_merge_request: 4,
remote_mirrors: 2,
snippets: 2
)
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,
projects_without_disable_overriding_approvers_per_merge_request: 2,
remote_mirrors: 1,
snippets: 1
)
end
end
context 'for monitor' do describe 'usage_activity_by_stage_manage' do
it 'includes accurate usage_activity_by_stage data' do it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do stub_config(
user = create(:user, dashboard: 'operations') omniauth:
cluster = create(:cluster, user: user) { providers: omniauth_providers }
create(:project, creator: user) )
create(:clusters_applications_prometheus, :installed, cluster: cluster)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:monitor]).to include( for_defined_days_back do
clusters: 2, user = create(:user)
clusters_applications_prometheus: 2, create(:event, author: user)
operations_dashboard_default_dashboard: 2 create(:group_member, user: user)
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:monitor]).to include(
clusters: 1,
clusters_applications_prometheus: 1,
operations_dashboard_default_dashboard: 1
)
end
end end
context 'for plan' do expect(described_class.usage_activity_by_stage_manage({})).to include(
it 'includes accurate usage_activity_by_stage data' do events: 2,
for_defined_days_back do groups: 2,
user = create(:user) users_created: 4,
project = create(:project, creator: user) omniauth_providers: ['google_oauth2']
issue = create(:issue, project: project, author: user) )
create(:issue, project: project, author: User.support_bot) expect(described_class.usage_activity_by_stage_manage(described_class.last_28_days_time_period)).to include(
create(:note, project: project, noteable: issue, author: user) events: 1,
create(:todo, project: project, target: issue, author: user) groups: 1,
end users_created: 2,
omniauth_providers: ['google_oauth2']
expect(described_class.uncached_data[:usage_activity_by_stage][:plan]).to include( )
issues: 3, end
notes: 2,
projects: 2,
todos: 2,
service_desk_enabled_projects: 2,
service_desk_issues: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:plan]).to include(
issues: 2,
notes: 1,
projects: 1,
todos: 1,
service_desk_enabled_projects: 1,
service_desk_issues: 1
)
end
end
context 'for release' do def omniauth_providers
it 'includes accurate usage_activity_by_stage data' do [
for_defined_days_back do OpenStruct.new(name: 'google_oauth2'),
user = create(:user) OpenStruct.new(name: 'ldapmain'),
create(:deployment, :failed, user: user) OpenStruct.new(name: 'group_saml')
create(:release, author: user) ]
create(:deployment, :success, user: user) end
end end
expect(described_class.uncached_data[:usage_activity_by_stage][:release]).to include( describe 'usage_activity_by_stage_monitor' do
deployments: 2, it 'includes accurate usage_activity_by_stage data' do
failed_deployments: 2, for_defined_days_back do
releases: 2, user = create(:user, dashboard: 'operations')
successful_deployments: 2 cluster = create(:cluster, user: user)
) create(:project, creator: user)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:release]).to include( create(:clusters_applications_prometheus, :installed, cluster: cluster)
deployments: 1,
failed_deployments: 1,
releases: 1,
successful_deployments: 1
)
end
end end
context 'for verify' do expect(described_class.usage_activity_by_stage_monitor({})).to include(
it 'includes accurate usage_activity_by_stage data' do clusters: 2,
for_defined_days_back do clusters_applications_prometheus: 2,
user = create(:user) operations_dashboard_default_dashboard: 2
create(:ci_build, user: user) )
create(:ci_empty_pipeline, source: :external, user: user) expect(described_class.usage_activity_by_stage_monitor(described_class.last_28_days_time_period)).to include(
create(:ci_empty_pipeline, user: user) clusters: 1,
create(:ci_pipeline, :auto_devops_source, user: user) clusters_applications_prometheus: 1,
create(:ci_pipeline, :repository_source, user: user) operations_dashboard_default_dashboard: 1
create(:ci_pipeline_schedule, owner: user) )
create(:ci_trigger, owner: user) end
create(:clusters_applications_runner, :installed) end
end
expect(described_class.uncached_data[:usage_activity_by_stage][:verify]).to include( describe 'usage_activity_by_stage_plan' do
ci_builds: 2, it 'includes accurate usage_activity_by_stage data' do
ci_external_pipelines: 2, for_defined_days_back do
ci_internal_pipelines: 2, user = create(:user)
ci_pipeline_config_auto_devops: 2, project = create(:project, creator: user)
ci_pipeline_config_repository: 2, issue = create(:issue, project: project, author: user)
ci_pipeline_schedules: 2, create(:issue, project: project, author: User.support_bot)
ci_pipelines: 2, create(:note, project: project, noteable: issue, author: user)
ci_triggers: 2, create(:todo, project: project, target: issue, author: user)
clusters_applications_runner: 2 end
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:verify]).to include( expect(described_class.usage_activity_by_stage_plan({})).to include(
ci_builds: 1, issues: 3,
ci_external_pipelines: 1, notes: 2,
ci_internal_pipelines: 1, projects: 2,
ci_pipeline_config_auto_devops: 1, todos: 2,
ci_pipeline_config_repository: 1, service_desk_enabled_projects: 2,
ci_pipeline_schedules: 1, service_desk_issues: 2
ci_pipelines: 1, )
ci_triggers: 1, expect(described_class.usage_activity_by_stage_plan(described_class.last_28_days_time_period)).to include(
clusters_applications_runner: 1 issues: 2,
) notes: 1,
end projects: 1,
end todos: 1,
service_desk_enabled_projects: 1,
service_desk_issues: 1
)
end end
end
it 'ensures recorded_at is set before any other usage data calculation' do describe 'usage_activity_by_stage_release' do
%i(alt_usage_data redis_usage_data distinct_count count).each do |method| it 'includes accurate usage_activity_by_stage data' do
expect(described_class).not_to receive(method) for_defined_days_back do
user = create(:user)
create(:deployment, :failed, user: user)
create(:release, author: user)
create(:deployment, :success, user: user)
end end
expect(described_class).to receive(:recorded_at).and_raise(Exception.new('Stopped calculating recorded_at'))
expect { described_class.uncached_data }.to raise_error('Stopped calculating recorded_at') 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
)
end
end
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)
end
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
)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment