Commit 33ad943a authored by David Kim's avatar David Kim

Add projects_with_sectional_code_owner_rules to usage_data

We want to be able to answer how many projects are using sectional
codeowners feature.
parent 3807fcbf
# frozen_string_literal: true
class AddSectionAndCreatedAtCodeownerApprovalMergeRequestIndex < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
SECTION_CREATED_AT_ON_CODEOWNER_APPROVAL_MERGE_REQUEST_RULES = "index_created_at_on_codeowner_approval_merge_request_rules"
RULE_TYPE_CODEOWNERS = 2
CODEOWNER_SECTION_DEFAULT = 'codeowners'
disable_ddl_transaction!
def up
add_concurrent_index :approval_merge_request_rules, :created_at,
where: "rule_type = #{RULE_TYPE_CODEOWNERS} AND section != '#{CODEOWNER_SECTION_DEFAULT}'::text",
name: SECTION_CREATED_AT_ON_CODEOWNER_APPROVAL_MERGE_REQUEST_RULES
end
def down
remove_concurrent_index_by_name :approval_merge_request_rules, SECTION_CREATED_AT_ON_CODEOWNER_APPROVAL_MERGE_REQUEST_RULES
end
end
87d3529596f5b5adff7280be7c60e4ff290dd05c500bbeb00cda0ac5da6239e0
\ No newline at end of file
......@@ -19455,6 +19455,8 @@ CREATE UNIQUE INDEX index_container_repositories_on_project_id_and_name ON publi
CREATE INDEX index_container_repository_on_name_trigram ON public.container_repositories USING gin (name public.gin_trgm_ops);
CREATE INDEX index_created_at_on_codeowner_approval_merge_request_rules ON public.approval_merge_request_rules USING btree (created_at) WHERE ((rule_type = 2) AND (section <> 'codeowners'::text));
CREATE UNIQUE INDEX index_custom_emoji_on_namespace_id_and_name ON public.custom_emoji USING btree (namespace_id, name);
CREATE UNIQUE INDEX index_daily_build_group_report_results_unique_columns ON public.ci_daily_build_group_report_results USING btree (project_id, ref_path, date, group_name);
......
---
title: Add usage data for counting projects with sectional codeowner rules
merge_request: 37786
author:
type: added
......@@ -219,6 +219,7 @@ module EE
def usage_activity_by_stage_create(time_period)
super.merge({
projects_enforcing_code_owner_approval: distinct_count(::Project.requiring_code_owner_approval.where(time_period), :creator_id),
projects_with_sectional_code_owner_rules: projects_with_sectional_code_owner_rules(time_period),
merge_requests_with_added_rules: distinct_count(::ApprovalMergeRequestRule.where(time_period).with_added_approval_rules,
:merge_request_id,
start: approval_merge_request_rule_minimum_id,
......@@ -390,6 +391,23 @@ module EE
count(::JiraService.active.includes(:jira_tracker_data).where(jira_tracker_data: { issues_enabled: true }), start: min_id, finish: max_id)
end
# rubocop:enable CodeReuse/ActiveRecord
# rubocop:disable CodeReuse/ActiveRecord
# rubocop: disable UsageData/DistinctCountByLargeForeignKey
def projects_with_sectional_code_owner_rules(time_period)
distinct_count(
::ApprovalMergeRequestRule
.code_owner
.joins(:merge_request)
.where("section != ?", ::Gitlab::CodeOwners::Entry::DEFAULT_SECTION)
.where(time_period),
'merge_requests.target_project_id',
start: project_minimum_id,
finish: project_maximum_id
)
end
# rubocop: enable UsageData/DistinctCountByLargeForeignKey
# rubocop:enable CodeReuse/ActiveRecord
end
end
end
......
......@@ -315,7 +315,7 @@ RSpec.describe Gitlab::UsageData do
create(:approval_project_rule, protected_branches: [protected_branch], project: project)
create(:suggestion, note: create(:note, project: project))
create(:code_owner_rule, merge_request: merge_request, approvals_required: 3)
create(:code_owner_rule, merge_request: merge_request, approvals_required: 7)
create(:code_owner_rule, merge_request: merge_request, approvals_required: 7, section: 'new_section')
create(:approval_merge_request_rule, merge_request: merge_request)
create_list(:code_owner_rule, 3, approvals_required: 2)
create_list(:code_owner_rule, 2)
......@@ -325,6 +325,7 @@ RSpec.describe Gitlab::UsageData do
approval_project_rules: 6,
approval_project_rules_with_target_branch: 2,
projects_enforcing_code_owner_approval: 0,
projects_with_sectional_code_owner_rules: 2,
merge_requests_with_added_rules: 12,
merge_requests_with_optional_codeowners: 4,
merge_requests_with_required_codeowners: 8,
......@@ -337,6 +338,7 @@ RSpec.describe Gitlab::UsageData do
approval_project_rules: 6,
approval_project_rules_with_target_branch: 2,
projects_enforcing_code_owner_approval: 0,
projects_with_sectional_code_owner_rules: 1,
merge_requests_with_added_rules: 6,
merge_requests_with_optional_codeowners: 2,
merge_requests_with_required_codeowners: 4,
......
......@@ -716,6 +716,18 @@ module Gitlab
end
end
def project_minimum_id
strong_memoize(:project_minimum_id) do
::Project.minimum(:id)
end
end
def project_maximum_id
strong_memoize(:project_maximum_id) do
::Project.maximum(:id)
end
end
def clear_memoized
clear_memoization(:issue_minimum_id)
clear_memoization(:issue_maximum_id)
......@@ -726,6 +738,8 @@ module Gitlab
clear_memoization(:deployment_maximum_id)
clear_memoization(:approval_merge_request_rule_minimum_id)
clear_memoization(:approval_merge_request_rule_maximum_id)
clear_memoization(:project_minimum_id)
clear_memoization(:project_maximum_id)
end
# rubocop: disable CodeReuse/ActiveRecord
......
......@@ -25,6 +25,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
it 'clears memoized values' do
values = %i(issue_minimum_id issue_maximum_id
project_minimum_id project_maximum_id
user_minimum_id user_maximum_id unique_visit_service
deployment_minimum_id deployment_maximum_id
approval_merge_request_rule_minimum_id
......
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