Commit 526e383c authored by Stan Hu's avatar Stan Hu

Merge branch 'aa-speed-up-usage-data-specs' into 'master'

Speed up usage data specs

See merge request gitlab-org/gitlab!38697
parents f53bd910 98465b76
...@@ -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,7 +36,27 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -30,7 +36,27 @@ 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
uncached_data = described_class.uncached_data
expect(uncached_data[:usage_activity_by_stage][:create])
.not_to include(:merge_requests_users)
expect(uncached_data[:usage_activity_by_stage_monthly][:create])
.to include(:merge_requests_users)
end
end
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'))
expect { described_class.uncached_data }.to raise_error('Stopped calculating recorded_at')
end
end
describe '.usage_activity_by_stage_configure' do
it 'includes accurate usage_activity_by_stage data' do it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do for_defined_days_back do
user = create(:user) user = create(:user)
...@@ -50,7 +76,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -50,7 +76,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:cluster, :management_project) create(:cluster, :management_project)
end end
expect(described_class.uncached_data[:usage_activity_by_stage][:configure]).to include( expect(described_class.usage_activity_by_stage_configure({})).to include(
clusters_applications_cert_managers: 2, clusters_applications_cert_managers: 2,
clusters_applications_helm: 2, clusters_applications_helm: 2,
clusters_applications_ingress: 2, clusters_applications_ingress: 2,
...@@ -68,7 +94,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -68,7 +94,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
project_clusters_disabled: 2, project_clusters_disabled: 2,
project_clusters_enabled: 10 project_clusters_enabled: 10
) )
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:configure]).to include( expect(described_class.usage_activity_by_stage_configure(described_class.last_28_days_time_period)).to include(
clusters_applications_cert_managers: 1, clusters_applications_cert_managers: 1,
clusters_applications_helm: 1, clusters_applications_helm: 1,
clusters_applications_ingress: 1, clusters_applications_ingress: 1,
...@@ -89,21 +115,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -89,21 +115,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end end
end end
context 'for create' do describe 'usage_activity_by_stage_create' do
it 'include usage_activity_by_stage data' do
expect(described_class.uncached_data[:usage_activity_by_stage][:create])
.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 it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do for_defined_days_back do
user = create(:user) user = create(:user)
...@@ -118,7 +130,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -118,7 +130,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:snippet, author: user) create(:snippet, author: user)
end end
expect(described_class.uncached_data[:usage_activity_by_stage][:create]).to include( expect(described_class.usage_activity_by_stage_create({})).to include(
deploy_keys: 2, deploy_keys: 2,
keys: 2, keys: 2,
merge_requests: 2, merge_requests: 2,
...@@ -127,7 +139,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -127,7 +139,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
remote_mirrors: 2, remote_mirrors: 2,
snippets: 2 snippets: 2
) )
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:create]).to include( expect(described_class.usage_activity_by_stage_create(described_class.last_28_days_time_period)).to include(
deploy_keys: 1, deploy_keys: 1,
keys: 1, keys: 1,
merge_requests: 1, merge_requests: 1,
...@@ -139,7 +151,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -139,7 +151,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end end
end end
context 'for manage' 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
stub_config( stub_config(
omniauth: omniauth:
...@@ -152,16 +164,16 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -152,16 +164,16 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:group_member, user: user) create(:group_member, user: user)
end end
expect(described_class.uncached_data[:usage_activity_by_stage][:manage]).to include( expect(described_class.usage_activity_by_stage_manage({})).to include(
events: 2, events: 2,
groups: 2, groups: 2,
users_created: 6, users_created: 4,
omniauth_providers: ['google_oauth2'] omniauth_providers: ['google_oauth2']
) )
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:manage]).to include( expect(described_class.usage_activity_by_stage_manage(described_class.last_28_days_time_period)).to include(
events: 1, events: 1,
groups: 1, groups: 1,
users_created: 4, users_created: 2,
omniauth_providers: ['google_oauth2'] omniauth_providers: ['google_oauth2']
) )
end end
...@@ -175,7 +187,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -175,7 +187,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end end
end end
context 'for monitor' do describe 'usage_activity_by_stage_monitor' do
it 'includes accurate usage_activity_by_stage data' do it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do for_defined_days_back do
user = create(:user, dashboard: 'operations') user = create(:user, dashboard: 'operations')
...@@ -184,12 +196,12 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -184,12 +196,12 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:clusters_applications_prometheus, :installed, cluster: cluster) create(:clusters_applications_prometheus, :installed, cluster: cluster)
end end
expect(described_class.uncached_data[:usage_activity_by_stage][:monitor]).to include( expect(described_class.usage_activity_by_stage_monitor({})).to include(
clusters: 2, clusters: 2,
clusters_applications_prometheus: 2, clusters_applications_prometheus: 2,
operations_dashboard_default_dashboard: 2 operations_dashboard_default_dashboard: 2
) )
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:monitor]).to include( expect(described_class.usage_activity_by_stage_monitor(described_class.last_28_days_time_period)).to include(
clusters: 1, clusters: 1,
clusters_applications_prometheus: 1, clusters_applications_prometheus: 1,
operations_dashboard_default_dashboard: 1 operations_dashboard_default_dashboard: 1
...@@ -197,7 +209,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -197,7 +209,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end end
end end
context 'for plan' do describe 'usage_activity_by_stage_plan' do
it 'includes accurate usage_activity_by_stage data' do it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do for_defined_days_back do
user = create(:user) user = create(:user)
...@@ -208,7 +220,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -208,7 +220,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:todo, project: project, target: issue, author: user) create(:todo, project: project, target: issue, author: user)
end end
expect(described_class.uncached_data[:usage_activity_by_stage][:plan]).to include( expect(described_class.usage_activity_by_stage_plan({})).to include(
issues: 3, issues: 3,
notes: 2, notes: 2,
projects: 2, projects: 2,
...@@ -216,7 +228,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -216,7 +228,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
service_desk_enabled_projects: 2, service_desk_enabled_projects: 2,
service_desk_issues: 2 service_desk_issues: 2
) )
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:plan]).to include( expect(described_class.usage_activity_by_stage_plan(described_class.last_28_days_time_period)).to include(
issues: 2, issues: 2,
notes: 1, notes: 1,
projects: 1, projects: 1,
...@@ -227,7 +239,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -227,7 +239,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end end
end end
context 'for release' do describe 'usage_activity_by_stage_release' do
it 'includes accurate usage_activity_by_stage data' do it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do for_defined_days_back do
user = create(:user) user = create(:user)
...@@ -236,13 +248,13 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -236,13 +248,13 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:deployment, :success, user: user) create(:deployment, :success, user: user)
end end
expect(described_class.uncached_data[:usage_activity_by_stage][:release]).to include( expect(described_class.usage_activity_by_stage_release({})).to include(
deployments: 2, deployments: 2,
failed_deployments: 2, failed_deployments: 2,
releases: 2, releases: 2,
successful_deployments: 2 successful_deployments: 2
) )
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:release]).to include( expect(described_class.usage_activity_by_stage_release(described_class.last_28_days_time_period)).to include(
deployments: 1, deployments: 1,
failed_deployments: 1, failed_deployments: 1,
releases: 1, releases: 1,
...@@ -251,7 +263,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -251,7 +263,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end end
end end
context 'for verify' do describe 'usage_activity_by_stage_verify' do
it 'includes accurate usage_activity_by_stage data' do it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do for_defined_days_back do
user = create(:user) user = create(:user)
...@@ -265,7 +277,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -265,7 +277,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:clusters_applications_runner, :installed) create(:clusters_applications_runner, :installed)
end end
expect(described_class.uncached_data[:usage_activity_by_stage][:verify]).to include( expect(described_class.usage_activity_by_stage_verify({})).to include(
ci_builds: 2, ci_builds: 2,
ci_external_pipelines: 2, ci_external_pipelines: 2,
ci_internal_pipelines: 2, ci_internal_pipelines: 2,
...@@ -276,7 +288,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -276,7 +288,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
ci_triggers: 2, ci_triggers: 2,
clusters_applications_runner: 2 clusters_applications_runner: 2
) )
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:verify]).to include( expect(described_class.usage_activity_by_stage_verify(described_class.last_28_days_time_period)).to include(
ci_builds: 1, ci_builds: 1,
ci_external_pipelines: 1, ci_external_pipelines: 1,
ci_internal_pipelines: 1, ci_internal_pipelines: 1,
...@@ -289,17 +301,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -289,17 +301,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
) )
end end
end end
end
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'))
expect { described_class.uncached_data }.to raise_error('Stopped calculating recorded_at')
end
end
describe '.data' do describe '.data' do
let!(:ud) { build(:usage_data) } let!(:ud) { build(:usage_data) }
......
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