Commit f7c2edda authored by Aishwarya Subramanian's avatar Aishwarya Subramanian

Count merged MRs using approval rules in Usage Data

Adds metric to report the count of approval rules
for merged merge requests.
parent 1fc01f79
# frozen_string_literal: true
class AddIndexForMergedMergeRequests < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'idx_merge_requests_on_merged_state'
disable_ddl_transaction!
def up
add_concurrent_index :merge_requests,
:id,
where: 'state_id = 3',
name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :merge_requests, INDEX_NAME
end
end
619e788f8868a2ff602a06e0025154b0b10b17cd69edcce70378e11750d5e686
\ No newline at end of file
...@@ -19474,6 +19474,8 @@ CREATE INDEX idx_members_created_at_user_id_invite_token ON members USING btree ...@@ -19474,6 +19474,8 @@ CREATE INDEX idx_members_created_at_user_id_invite_token ON members USING btree
CREATE INDEX idx_merge_requests_on_id_and_merge_jid ON merge_requests USING btree (id, merge_jid) WHERE ((merge_jid IS NOT NULL) AND (state_id = 4)); CREATE INDEX idx_merge_requests_on_id_and_merge_jid ON merge_requests USING btree (id, merge_jid) WHERE ((merge_jid IS NOT NULL) AND (state_id = 4));
CREATE INDEX idx_merge_requests_on_merged_state ON merge_requests USING btree (id) WHERE (state_id = 3);
CREATE INDEX idx_merge_requests_on_source_project_and_branch_state_opened ON merge_requests USING btree (source_project_id, source_branch) WHERE (state_id = 1); CREATE INDEX idx_merge_requests_on_source_project_and_branch_state_opened ON merge_requests USING btree (source_project_id, source_branch) WHERE (state_id = 1);
CREATE INDEX idx_merge_requests_on_state_id_and_merge_status ON merge_requests USING btree (state_id, merge_status) WHERE ((state_id = 1) AND ((merge_status)::text = 'can_be_merged'::text)); CREATE INDEX idx_merge_requests_on_state_id_and_merge_status ON merge_requests USING btree (state_id, merge_status) WHERE ((state_id = 1) AND ((merge_status)::text = 'can_be_merged'::text));
......
---
title: Count merged MRs using approval rules in usage data
merge_request: 42911
author:
type: added
...@@ -192,6 +192,9 @@ module EE ...@@ -192,6 +192,9 @@ module EE
merge_requests_with_optional_codeowners: distinct_count(::ApprovalMergeRequestRule.code_owner_approval_optional, :merge_request_id), merge_requests_with_optional_codeowners: distinct_count(::ApprovalMergeRequestRule.code_owner_approval_optional, :merge_request_id),
merge_requests_with_overridden_project_rules: merge_requests_with_overridden_project_rules, merge_requests_with_overridden_project_rules: merge_requests_with_overridden_project_rules,
merge_requests_with_required_codeowners: distinct_count(::ApprovalMergeRequestRule.code_owner_approval_required, :merge_request_id), merge_requests_with_required_codeowners: distinct_count(::ApprovalMergeRequestRule.code_owner_approval_required, :merge_request_id),
merged_merge_requests_using_approval_rules: count(::MergeRequest.merged.joins(:approval_rules), # rubocop: disable CodeReuse/ActiveRecord
start: merge_request_minimum_id,
finish: merge_request_maximum_id),
projects_mirrored_with_pipelines_enabled: count(::Project.mirrored_with_enabled_pipelines), projects_mirrored_with_pipelines_enabled: count(::Project.mirrored_with_enabled_pipelines),
projects_reporting_ci_cd_back_to_github: count(::GithubService.active), projects_reporting_ci_cd_back_to_github: count(::GithubService.active),
status_page_projects: count(::StatusPage::ProjectSetting.enabled), status_page_projects: count(::StatusPage::ProjectSetting.enabled),
...@@ -398,6 +401,18 @@ module EE ...@@ -398,6 +401,18 @@ module EE
end end
end end
def merge_request_minimum_id
strong_memoize(:merge_request_minimum_id) do
::MergeRequest.minimum(:id)
end
end
def merge_request_maximum_id
strong_memoize(:merge_request_maximum_id) do
::MergeRequest.maximum(:id)
end
end
def ldap_config_present_for_any_provider?(configuration_item) def ldap_config_present_for_any_provider?(configuration_item)
ldap_available_servers.any? { |server_config| server_config[configuration_item.to_s] } ldap_available_servers.any? { |server_config| server_config[configuration_item.to_s] }
end end
...@@ -465,6 +480,16 @@ module EE ...@@ -465,6 +480,16 @@ module EE
) )
end end
# rubocop:enable CodeReuse/ActiveRecord # rubocop:enable CodeReuse/ActiveRecord
override :clear_memoized
def clear_memoized
super
clear_memoization(:approval_merge_request_rule_minimum_id)
clear_memoization(:approval_merge_request_rule_maximum_id)
clear_memoization(:merge_request_minimum_id)
clear_memoization(:merge_request_maximum_id)
end
end end
end end
end end
......
...@@ -225,6 +225,17 @@ RSpec.describe Gitlab::UsageData do ...@@ -225,6 +225,17 @@ RSpec.describe Gitlab::UsageData do
end end
end end
describe 'merge requests merged using approval rules' do
before do
create(:approval_merge_request_rule, merge_request: create(:merge_request, :merged))
create(:approval_merge_request_rule, merge_request: create(:merge_request))
end
it 'counts the approval rules for merged merge requests' do
expect(described_class.system_usage_data[:counts][:merged_merge_requests_using_approval_rules]).to eq(1)
end
end
describe '.operations_dashboard_usage' do describe '.operations_dashboard_usage' do
subject { described_class.operations_dashboard_usage } subject { described_class.operations_dashboard_usage }
...@@ -692,4 +703,22 @@ RSpec.describe Gitlab::UsageData do ...@@ -692,4 +703,22 @@ RSpec.describe Gitlab::UsageData do
) )
end end
end end
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
auth_providers
approval_merge_request_rule_minimum_id
approval_merge_request_rule_maximum_id
merge_request_minimum_id
merge_request_maximum_id)
values.each do |key|
expect(described_class).to receive(:clear_memoization).with(key)
end
described_class.uncached_data
end
end end
...@@ -816,8 +816,6 @@ module Gitlab ...@@ -816,8 +816,6 @@ module Gitlab
clear_memoization(:unique_visit_service) clear_memoization(:unique_visit_service)
clear_memoization(:deployment_minimum_id) clear_memoization(:deployment_minimum_id)
clear_memoization(:deployment_maximum_id) 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_minimum_id)
clear_memoization(:project_maximum_id) clear_memoization(:project_maximum_id)
clear_memoization(:auth_providers) clear_memoization(:auth_providers)
......
...@@ -28,9 +28,16 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -28,9 +28,16 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
project_minimum_id project_maximum_id project_minimum_id project_maximum_id
user_minimum_id user_maximum_id unique_visit_service user_minimum_id user_maximum_id unique_visit_service
deployment_minimum_id deployment_maximum_id deployment_minimum_id deployment_maximum_id
approval_merge_request_rule_minimum_id
approval_merge_request_rule_maximum_id
auth_providers) auth_providers)
if Gitlab.ee?
values << %i(approval_merge_request_rule_minimum_id
approval_merge_request_rule_maximum_id
merge_request_minimum_id
merge_request_maximum_id)
values.flatten!
end
values.each do |key| values.each do |key|
expect(described_class).to receive(:clear_memoization).with(key) expect(described_class).to receive(:clear_memoization).with(key)
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