Commit be1011fe authored by Markus Koller's avatar Markus Koller

Merge branch 'aa-speed-up-ee-usage-data-spec' into 'master'

Speed up EE usage data specs

See merge request gitlab-org/gitlab!38775
parents 71ce21e3 57741742
...@@ -268,392 +268,392 @@ RSpec.describe Gitlab::UsageData do ...@@ -268,392 +268,392 @@ RSpec.describe Gitlab::UsageData do
expect(described_class.uncached_data).to include(:usage_activity_by_stage) expect(described_class.uncached_data).to include(:usage_activity_by_stage)
expect(described_class.uncached_data).to include(:usage_activity_by_stage_monthly) expect(described_class.uncached_data).to include(:usage_activity_by_stage_monthly)
end end
end
end
describe 'usage_activity_by_stage_configure' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
user = create(:user)
project = create(:project, creator: user)
create(:slack_service, project: project)
create(:slack_slash_commands_service, project: project)
create(:prometheus_service, project: project)
end
expect(described_class.usage_activity_by_stage_configure({})).to include(
projects_slack_notifications_active: 2,
projects_slack_slash_active: 2,
projects_with_prometheus_alerts: 2
)
expect(described_class.usage_activity_by_stage_configure(described_class.last_28_days_time_period)).to include(
projects_slack_notifications_active: 1,
projects_slack_slash_active: 1,
projects_with_prometheus_alerts: 1
)
end
end
context 'for configure' do describe 'usage_activity_by_stage_create' do
it 'includes accurate usage_activity_by_stage data' do it 'includes accurate usage_activity_by_stage data', :aggregate_failures do
for_defined_days_back do for_defined_days_back do
user = create(:user) user = create(:user)
project = create(:project, creator: user) project = create(:project, :repository_private, :github_imported,
create(:slack_service, project: project) :test_repo, creator: user)
create(:slack_slash_commands_service, project: project) merge_request = create(:merge_request, source_project: project)
create(:prometheus_service, project: project) project_rule = create(:approval_project_rule, project: project)
end merge_rule = create(:approval_merge_request_rule, merge_request: merge_request)
create(:approval_merge_request_rule_source, approval_merge_request_rule: merge_rule, approval_project_rule: project_rule)
expect(described_class.uncached_data[:usage_activity_by_stage][:configure]).to include( create(:project, creator: user)
projects_slack_notifications_active: 2, create(:project, creator: user, disable_overriding_approvers_per_merge_request: true)
projects_slack_slash_active: 2, create(:project, creator: user, disable_overriding_approvers_per_merge_request: false)
projects_with_prometheus_alerts: 2 create(:approval_project_rule, project: project)
) protected_branch = create(:protected_branch, project: project)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:configure]).to include( create(:approval_project_rule, protected_branches: [protected_branch], project: project)
projects_slack_notifications_active: 1, create(:suggestion, note: create(:note, project: project))
projects_slack_slash_active: 1, create(:code_owner_rule, merge_request: merge_request, approvals_required: 3)
projects_with_prometheus_alerts: 1 create(:code_owner_rule, merge_request: merge_request, approvals_required: 7)
) create(:approval_merge_request_rule, merge_request: merge_request)
end create_list(:code_owner_rule, 3, approvals_required: 2)
create_list(:code_owner_rule, 2)
end end
context 'for create' do expect(described_class.usage_activity_by_stage_create({})).to include(
it 'includes accurate usage_activity_by_stage data', :aggregate_failures do approval_project_rules: 6,
for_defined_days_back do approval_project_rules_with_target_branch: 2,
user = create(:user) projects_enforcing_code_owner_approval: 0,
project = create(:project, :repository_private, :github_imported, merge_requests_with_added_rules: 12,
:test_repo, creator: user) merge_requests_with_optional_codeowners: 4,
merge_request = create(:merge_request, source_project: project) merge_requests_with_required_codeowners: 8,
project_rule = create(:approval_project_rule, project: project) projects_imported_from_github: 2,
merge_rule = create(:approval_merge_request_rule, merge_request: merge_request) projects_with_repositories_enabled: 12,
create(:approval_merge_request_rule_source, approval_merge_request_rule: merge_rule, approval_project_rule: project_rule) protected_branches: 2,
create(:project, creator: user) suggestions: 2
create(:project, creator: user, disable_overriding_approvers_per_merge_request: true) )
create(:project, creator: user, disable_overriding_approvers_per_merge_request: false) expect(described_class.usage_activity_by_stage_create(described_class.last_28_days_time_period)).to include(
create(:approval_project_rule, project: project) approval_project_rules: 6,
protected_branch = create(:protected_branch, project: project) approval_project_rules_with_target_branch: 2,
create(:approval_project_rule, protected_branches: [protected_branch], project: project) projects_enforcing_code_owner_approval: 0,
create(:suggestion, note: create(:note, project: project)) merge_requests_with_added_rules: 6,
create(:code_owner_rule, merge_request: merge_request, approvals_required: 3) merge_requests_with_optional_codeowners: 2,
create(:code_owner_rule, merge_request: merge_request, approvals_required: 7) merge_requests_with_required_codeowners: 4,
create(:approval_merge_request_rule, merge_request: merge_request) projects_imported_from_github: 1,
create_list(:code_owner_rule, 3, approvals_required: 2) projects_with_repositories_enabled: 6,
create_list(:code_owner_rule, 2) protected_branches: 1,
end suggestions: 1
)
expect(described_class.uncached_data[:usage_activity_by_stage][:create]).to include( end
approval_project_rules: 6, end
approval_project_rules_with_target_branch: 2,
projects_enforcing_code_owner_approval: 0, describe 'usage_activity_by_stage_manage' do
merge_requests_with_added_rules: 12, it 'includes accurate usage_activity_by_stage data' do
merge_requests_with_optional_codeowners: 4, stub_config(
merge_requests_with_required_codeowners: 8, ldap:
projects_imported_from_github: 2, { enabled: true, servers: ldap_server_config }
projects_with_repositories_enabled: 12, )
protected_branches: 2,
suggestions: 2 for_defined_days_back do
) user = create(:user)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:create]).to include( create(:key, type: 'LDAPKey', user: user)
approval_project_rules: 6, create(:group_member, ldap: true, user: user)
approval_project_rules_with_target_branch: 2, create(:cycle_analytics_group_stage)
projects_enforcing_code_owner_approval: 0, create(:compliance_framework_project_setting)
merge_requests_with_added_rules: 6,
merge_requests_with_optional_codeowners: 2,
merge_requests_with_required_codeowners: 4,
projects_imported_from_github: 1,
projects_with_repositories_enabled: 6,
protected_branches: 1,
suggestions: 1
)
end
end end
context 'for manage' do expect(described_class.usage_activity_by_stage_manage({})).to include(
it 'includes accurate usage_activity_by_stage data' do ldap_keys: 2,
stub_config( ldap_users: 2,
ldap: value_stream_management_customized_group_stages: 2,
{ enabled: true, servers: ldap_server_config } projects_with_compliance_framework: 2,
) ldap_servers: 2,
ldap_group_sync_enabled: true,
for_defined_days_back do ldap_admin_sync_enabled: true,
user = create(:user) group_saml_enabled: true
create(:key, type: 'LDAPKey', user: user) )
create(:group_member, ldap: true, user: user) expect(described_class.usage_activity_by_stage_manage(described_class.last_28_days_time_period)).to include(
create(:cycle_analytics_group_stage) ldap_keys: 1,
create(:compliance_framework_project_setting) ldap_users: 1,
end value_stream_management_customized_group_stages: 2,
projects_with_compliance_framework: 2,
expect(described_class.uncached_data[:usage_activity_by_stage][:manage]).to include( ldap_servers: 2,
ldap_keys: 2, ldap_group_sync_enabled: true,
ldap_users: 2, ldap_admin_sync_enabled: true,
value_stream_management_customized_group_stages: 2, group_saml_enabled: true
projects_with_compliance_framework: 2, )
ldap_servers: 2, end
ldap_group_sync_enabled: true,
ldap_admin_sync_enabled: true, def ldap_server_config
group_saml_enabled: true {
) 'main' =>
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:manage]).to include( {
ldap_keys: 1, 'provider_name' => 'ldapmain',
ldap_users: 1, 'group_base' => 'ou=groups',
value_stream_management_customized_group_stages: 2, 'admin_group' => 'my_group'
projects_with_compliance_framework: 2, },
ldap_servers: 2, 'secondary' =>
ldap_group_sync_enabled: true, {
ldap_admin_sync_enabled: true, 'provider_name' => 'ldapsecondary',
group_saml_enabled: true 'group_base' => nil,
) 'admin_group' => nil
end }
}
def ldap_server_config end
{ end
'main' =>
{ describe 'usage_activity_by_stage_monitor' do
'provider_name' => 'ldapmain', it 'includes accurate usage_activity_by_stage data' do
'group_base' => 'ou=groups', for_defined_days_back do
'admin_group' => 'my_group' user = create(:user, dashboard: 'operations')
}, project = create(:project, creator: user)
'secondary' => create(:users_ops_dashboard_project, user: user)
{ create(:prometheus_service, project: project)
'provider_name' => 'ldapsecondary', create(:project_error_tracking_setting, project: project)
'group_base' => nil, create(:project_tracing_setting, project: project)
'admin_group' => nil end
}
} expect(described_class.usage_activity_by_stage_monitor({})).to include(
end operations_dashboard_users_with_projects_added: 2,
projects_prometheus_active: 2,
projects_with_error_tracking_enabled: 2,
projects_with_tracing_enabled: 2
)
expect(described_class.usage_activity_by_stage_monitor(described_class.last_28_days_time_period)).to include(
operations_dashboard_users_with_projects_added: 1,
projects_prometheus_active: 1,
projects_with_error_tracking_enabled: 1,
projects_with_tracing_enabled: 1
)
end
end
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
describe 'usage_activity_by_stage_plan' do
it 'includes accurate usage_activity_by_stage data' do
stub_licensed_features(board_assignee_lists: true, board_milestone_lists: true)
for_defined_days_back do
user = create(:user)
project = create(:project, creator: user)
board = create(:board, project: project)
create(:user_list, board: board, user: user)
create(:milestone_list, board: board, milestone: create(:milestone, project: project), user: user)
create(:list, board: board, label: create(:label, project: project), user: user)
create(:epic, author: user)
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))
end end
context 'for monitor' do expect(described_class.usage_activity_by_stage_plan({})).to include(
it 'includes accurate usage_activity_by_stage data' do assignee_lists: 2,
for_defined_days_back do epics: 2,
user = create(:user, dashboard: 'operations') label_lists: 2,
project = create(:project, creator: user) milestone_lists: 2,
create(:users_ops_dashboard_project, user: user) projects_jira_active: 2,
create(:prometheus_service, project: project) projects_jira_dvcs_cloud_active: 2,
create(:project_error_tracking_setting, project: project) projects_jira_dvcs_server_active: 2
create(:project_tracing_setting, project: project) )
end expect(described_class.usage_activity_by_stage_plan(described_class.last_28_days_time_period)).to include(
assignee_lists: 1,
expect(described_class.uncached_data[:usage_activity_by_stage][:monitor]).to include( epics: 1,
operations_dashboard_users_with_projects_added: 2, label_lists: 1,
projects_prometheus_active: 2, milestone_lists: 1,
projects_with_error_tracking_enabled: 2, projects_jira_active: 1,
projects_with_tracing_enabled: 2 projects_jira_dvcs_cloud_active: 1,
) projects_jira_dvcs_server_active: 1
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:monitor]).to include( )
operations_dashboard_users_with_projects_added: 1, end
projects_prometheus_active: 1, end
projects_with_error_tracking_enabled: 1,
projects_with_tracing_enabled: 1 describe 'usage_activity_by_stage_release' do
) it 'includes accurate usage_activity_by_stage data' do
end for_defined_days_back do
create(:project, :mirror, mirror_trigger_builds: true)
end end
context 'for package' do expect(described_class.usage_activity_by_stage_release({})).to include(
it 'includes accurate usage_activity_by_stage data' do projects_mirrored_with_pipelines_enabled: 2
for_defined_days_back do )
create(:project, packages: [create(:package)] ) expect(described_class.usage_activity_by_stage_release(described_class.last_28_days_time_period)).to include(
end projects_mirrored_with_pipelines_enabled: 1
)
expect(described_class.uncached_data[:usage_activity_by_stage][:package]).to eq( end
projects_with_packages: 2 end
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:package]).to eq( describe 'usage_activity_by_stage_secure' do
projects_with_packages: 1 let_it_be(:user) { create(:user, group_view: :security_dashboard) }
) let_it_be(:user2) { create(:user, group_view: :security_dashboard) }
end let_it_be(:user3) { create(:user, group_view: :security_dashboard) }
before do
for_defined_days_back do
create(:ci_build, name: 'container_scanning', user: user)
create(:ci_build, name: 'dast', user: user)
create(:ci_build, name: 'dependency_scanning', user: user)
create(:ci_build, name: 'license_management', user: user)
create(:ci_build, name: 'sast', user: user)
create(:ci_build, name: 'secret_detection', user: user)
end end
end
context 'for plan' do it 'includes accurate usage_activity_by_stage data' do
it 'includes accurate usage_activity_by_stage data' do expect(described_class.usage_activity_by_stage_secure(described_class.last_28_days_time_period)).to eq(
stub_licensed_features(board_assignee_lists: true, board_milestone_lists: true) user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
for_defined_days_back do user_dast_jobs: 1,
user = create(:user) user_dependency_scanning_jobs: 1,
project = create(:project, creator: user) user_license_management_jobs: 1,
board = create(:board, project: project) user_sast_jobs: 1,
create(:user_list, board: board, user: user) user_secret_detection_jobs: 1,
create(:milestone_list, board: board, milestone: create(:milestone, project: project), user: user) sast_pipeline: 0,
create(:list, board: board, label: create(:label, project: project), user: user) dependency_scanning_pipeline: 0,
create(:epic, author: user) container_scanning_pipeline: 0,
create(:jira_service, :jira_cloud_service, active: true, project: create(:project, :jira_dvcs_cloud, creator: user)) dast_pipeline: 0,
create(:jira_service, active: true, project: create(:project, :jira_dvcs_server, creator: user)) secret_detection_pipeline: 0,
end coverage_fuzzing_pipeline: 0,
user_unique_users_all_secure_scanners: 1
expect(described_class.uncached_data[:usage_activity_by_stage][:plan]).to include( )
assignee_lists: 2, end
epics: 2,
label_lists: 2, it 'counts pipelines that have security jobs' do
milestone_lists: 2, for_defined_days_back do
projects_jira_active: 2, ds_build = create(:ci_build, name: 'retirejs', user: user, status: 'success')
projects_jira_dvcs_cloud_active: 2, ds_bundler_build = create(:ci_build, name: 'bundler-audit', user: user, commit_id: ds_build.pipeline.id, status: 'success')
projects_jira_dvcs_server_active: 2 secret_detection_build = create(:ci_build, name: 'secret', user: user, commit_id: ds_build.pipeline.id, status: 'success')
) cs_build = create(:ci_build, name: 'klar', user: user, status: 'success')
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:plan]).to include( sast_build = create(:ci_build, name: 'sast', user: user, status: 'success', retried: true)
assignee_lists: 1, create(:security_scan, build: ds_build, scan_type: 'dependency_scanning' )
epics: 1, create(:security_scan, build: ds_bundler_build, scan_type: 'dependency_scanning')
label_lists: 1, create(:security_scan, build: secret_detection_build, scan_type: 'secret_detection')
milestone_lists: 1, create(:security_scan, build: cs_build, scan_type: 'container_scanning')
projects_jira_active: 1, create(:security_scan, build: sast_build, scan_type: 'sast')
projects_jira_dvcs_cloud_active: 1,
projects_jira_dvcs_server_active: 1
)
end
end end
context 'for release' do expect(described_class.usage_activity_by_stage_secure({})).to include(
it 'includes accurate usage_activity_by_stage data' do user_preferences_group_overview_security_dashboard: 3,
for_defined_days_back do user_container_scanning_jobs: 1,
create(:project, :mirror, mirror_trigger_builds: true) user_dast_jobs: 1,
end user_dependency_scanning_jobs: 1,
user_license_management_jobs: 1,
expect(described_class.uncached_data[:usage_activity_by_stage][:release]).to include( user_sast_jobs: 1,
projects_mirrored_with_pipelines_enabled: 2 user_secret_detection_jobs: 1,
) user_unique_users_all_secure_scanners: 1
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:release]).to include( )
projects_mirrored_with_pipelines_enabled: 1
) expect(described_class.usage_activity_by_stage_secure(described_class.last_28_days_time_period)).to include(
end user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
user_dast_jobs: 1,
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 1,
user_sast_jobs: 1,
user_secret_detection_jobs: 1,
sast_pipeline: 0,
dependency_scanning_pipeline: 1,
container_scanning_pipeline: 1,
dast_pipeline: 0,
secret_detection_pipeline: 1,
coverage_fuzzing_pipeline: 0,
user_unique_users_all_secure_scanners: 1
)
end
it 'counts unique users correctly across multiple scanners' do
for_defined_days_back do
create(:ci_build, name: 'sast', user: user2)
create(:ci_build, name: 'dast', user: user2)
create(:ci_build, name: 'dast', user: user3)
end end
context 'for secure' do expect(described_class.usage_activity_by_stage_secure(described_class.last_28_days_time_period)).to eq(
let_it_be(:user) { create(:user, group_view: :security_dashboard) } user_preferences_group_overview_security_dashboard: 3,
let_it_be(:user2) { create(:user, group_view: :security_dashboard) } user_container_scanning_jobs: 1,
let_it_be(:user3) { create(:user, group_view: :security_dashboard) } user_dast_jobs: 3,
user_dependency_scanning_jobs: 1,
before do user_license_management_jobs: 1,
for_defined_days_back do user_sast_jobs: 2,
create(:ci_build, name: 'container_scanning', user: user) user_secret_detection_jobs: 1,
create(:ci_build, name: 'dast', user: user) sast_pipeline: 0,
create(:ci_build, name: 'dependency_scanning', user: user) dependency_scanning_pipeline: 0,
create(:ci_build, name: 'license_management', user: user) container_scanning_pipeline: 0,
create(:ci_build, name: 'sast', user: user) dast_pipeline: 0,
create(:ci_build, name: 'secret_detection', user: user) secret_detection_pipeline: 0,
end coverage_fuzzing_pipeline: 0,
end user_unique_users_all_secure_scanners: 3
)
it 'includes accurate usage_activity_by_stage data' do end
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:secure]).to eq(
user_preferences_group_overview_security_dashboard: 3, it 'combines license_scanning into license_management' do
user_container_scanning_jobs: 1, for_defined_days_back do
user_dast_jobs: 1, create(:ci_build, name: 'license_scanning', user: user)
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 1,
user_sast_jobs: 1,
user_secret_detection_jobs: 1,
sast_pipeline: 0,
dependency_scanning_pipeline: 0,
container_scanning_pipeline: 0,
dast_pipeline: 0,
secret_detection_pipeline: 0,
coverage_fuzzing_pipeline: 0,
user_unique_users_all_secure_scanners: 1
)
end
it 'counts pipelines that have security jobs' do
for_defined_days_back do
ds_build = create(:ci_build, name: 'retirejs', user: user, status: 'success')
ds_bundler_build = create(:ci_build, name: 'bundler-audit', user: user, commit_id: ds_build.pipeline.id, status: 'success')
secret_detection_build = create(:ci_build, name: 'secret', user: user, commit_id: ds_build.pipeline.id, status: 'success')
cs_build = create(:ci_build, name: 'klar', user: user, status: 'success')
sast_build = create(:ci_build, name: 'sast', user: user, status: 'success', retried: true)
create(:security_scan, build: ds_build, scan_type: 'dependency_scanning' )
create(:security_scan, build: ds_bundler_build, scan_type: 'dependency_scanning')
create(:security_scan, build: secret_detection_build, scan_type: 'secret_detection')
create(:security_scan, build: cs_build, scan_type: 'container_scanning')
create(:security_scan, build: sast_build, scan_type: 'sast')
end
expect(described_class.uncached_data[:usage_activity_by_stage][:secure]).to include(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
user_dast_jobs: 1,
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 1,
user_sast_jobs: 1,
user_secret_detection_jobs: 1,
user_unique_users_all_secure_scanners: 1
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:secure]).to include(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
user_dast_jobs: 1,
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 1,
user_sast_jobs: 1,
user_secret_detection_jobs: 1,
sast_pipeline: 0,
dependency_scanning_pipeline: 1,
container_scanning_pipeline: 1,
dast_pipeline: 0,
secret_detection_pipeline: 1,
coverage_fuzzing_pipeline: 0,
user_unique_users_all_secure_scanners: 1
)
end
it 'counts unique users correctly across multiple scanners' do
for_defined_days_back do
create(:ci_build, name: 'sast', user: user2)
create(:ci_build, name: 'dast', user: user2)
create(:ci_build, name: 'dast', user: user3)
end
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:secure]).to eq(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
user_dast_jobs: 3,
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 1,
user_sast_jobs: 2,
user_secret_detection_jobs: 1,
sast_pipeline: 0,
dependency_scanning_pipeline: 0,
container_scanning_pipeline: 0,
dast_pipeline: 0,
secret_detection_pipeline: 0,
coverage_fuzzing_pipeline: 0,
user_unique_users_all_secure_scanners: 3
)
end
it 'combines license_scanning into license_management' do
for_defined_days_back do
create(:ci_build, name: 'license_scanning', user: user)
end
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:secure]).to eq(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: 1,
user_dast_jobs: 1,
user_dependency_scanning_jobs: 1,
user_license_management_jobs: 2,
user_sast_jobs: 1,
user_secret_detection_jobs: 1,
sast_pipeline: 0,
dependency_scanning_pipeline: 0,
container_scanning_pipeline: 0,
dast_pipeline: 0,
secret_detection_pipeline: 0,
coverage_fuzzing_pipeline: 0,
user_unique_users_all_secure_scanners: 1
)
end
it 'has to resort to 0 for counting license scan' do
allow(Gitlab::Database::BatchCount).to receive(:batch_distinct_count).and_raise(ActiveRecord::StatementInvalid)
allow(::Ci::Build).to receive(:distinct_count_by).and_raise(ActiveRecord::StatementInvalid)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:secure]).to eq(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: -1,
user_dast_jobs: -1,
user_dependency_scanning_jobs: -1,
user_license_management_jobs: -1,
user_sast_jobs: -1,
user_secret_detection_jobs: -1,
sast_pipeline: -1,
dependency_scanning_pipeline: -1,
container_scanning_pipeline: -1,
dast_pipeline: -1,
secret_detection_pipeline: -1,
coverage_fuzzing_pipeline: -1,
user_unique_users_all_secure_scanners: -1
)
end
end end
context 'for verify' do expect(described_class.usage_activity_by_stage_secure(described_class.last_28_days_time_period)).to eq(
it 'includes accurate usage_activity_by_stage data' do user_preferences_group_overview_security_dashboard: 3,
for_defined_days_back do user_container_scanning_jobs: 1,
create(:github_service) user_dast_jobs: 1,
end user_dependency_scanning_jobs: 1,
user_license_management_jobs: 2,
expect(described_class.uncached_data[:usage_activity_by_stage][:verify]).to include( user_sast_jobs: 1,
projects_reporting_ci_cd_back_to_github: 2 user_secret_detection_jobs: 1,
) sast_pipeline: 0,
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:verify]).to include( dependency_scanning_pipeline: 0,
projects_reporting_ci_cd_back_to_github: 1 container_scanning_pipeline: 0,
) dast_pipeline: 0,
end secret_detection_pipeline: 0,
coverage_fuzzing_pipeline: 0,
user_unique_users_all_secure_scanners: 1
)
end
it 'has to resort to 0 for counting license scan' do
allow(Gitlab::Database::BatchCount).to receive(:batch_distinct_count).and_raise(ActiveRecord::StatementInvalid)
allow(::Ci::Build).to receive(:distinct_count_by).and_raise(ActiveRecord::StatementInvalid)
expect(described_class.usage_activity_by_stage_secure(described_class.last_28_days_time_period)).to eq(
user_preferences_group_overview_security_dashboard: 3,
user_container_scanning_jobs: -1,
user_dast_jobs: -1,
user_dependency_scanning_jobs: -1,
user_license_management_jobs: -1,
user_sast_jobs: -1,
user_secret_detection_jobs: -1,
sast_pipeline: -1,
dependency_scanning_pipeline: -1,
container_scanning_pipeline: -1,
dast_pipeline: -1,
secret_detection_pipeline: -1,
coverage_fuzzing_pipeline: -1,
user_unique_users_all_secure_scanners: -1
)
end
end
describe 'usage_activity_by_stage_verify' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
create(:github_service)
end end
expect(described_class.usage_activity_by_stage_verify({})).to include(
projects_reporting_ci_cd_back_to_github: 2
)
expect(described_class.usage_activity_by_stage_verify(described_class.last_28_days_time_period)).to include(
projects_reporting_ci_cd_back_to_github: 1
)
end end
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