Commit 50f221fe authored by Piotr Skorupa's avatar Piotr Skorupa Committed by Michael Kozono

Deprecate and replace MR with approval rules metric

This:
- Sets counts.merged_merge_requests_using_approval_rules
as broken according with the metric lifecycle guidelines.
- Adds a new metric
counts.merged_merge_requests_using_approval_rules_distinct, which uses
distinct_count using metric instrumentation classes.
- Moves the original metric to `ee`, since it only applies to EE.

Changelog: fixed
EE: true
parent 379bdf7c
......@@ -7,14 +7,13 @@ product_stage: manage
product_group: group::compliance
product_category: compliance_management
value_type: number
status: active
status: broken
repair_issue_url: https://gitlab.com/gitlab-data/analytics/-/issues/11466
time_frame: all
data_source: database
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
performance_indicator_type: []
......
---
key_path: counts.merged_merge_requests_using_approval_rules_distinct
name: count_distinct_merge_requests_using_approval_rules
description: Count of distinct merge requests merged using approval rules
product_section: dev
product_stage: manage
product_group: group::compliance
product_category: compliance_management
value_type: number
status: active
milestone: "14.8"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/78664
time_frame: all
data_source: database
data_category: optional
instrumentation_class: CountDistinctMergedMergeRequestsUsingApprovalRulesMetric
performance_indicator_type: []
distribution:
- ee
tier:
- premium
- ultimate
......@@ -211,6 +211,7 @@ module EE
merged_merge_requests_using_approval_rules: count(::MergeRequest.merged.joins(:approval_rules), # rubocop: disable CodeReuse/ActiveRecord
start: minimum_id(::MergeRequest),
finish: maximum_id(::MergeRequest)),
merged_merge_requests_using_approval_rules_distinct: add_metric('CountDistinctMergedMergeRequestsUsingApprovalRulesMetric', time_frame: 'all'),
projects_mirrored_with_pipelines_enabled: count(::Project.mirrored_with_enabled_pipelines),
projects_reporting_ci_cd_back_to_github: count(::Integrations::Github.active),
status_page_projects: count(::StatusPage::ProjectSetting.enabled),
......
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Instrumentations
class CountDistinctMergedMergeRequestsUsingApprovalRulesMetric < DatabaseMetric
operation :distinct_count
start { MergeRequest.minimum(:id) }
finish { MergeRequest.maximum(:id) }
relation { MergeRequest.merged.joins(:approval_rules) } # rubocop: disable CodeReuse/ActiveRecord
cache_start_and_finish_as :merge_request
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountDistinctMergedMergeRequestsUsingApprovalRulesMetric do
let_it_be(:merge_request) { create(:merge_request, :merged) }
let_it_be(:approval_rule_1) { create(:approval_merge_request_rule, merge_request: merge_request) }
let_it_be(:approval_rule_2) { create(:approval_merge_request_rule, merge_request: merge_request) }
let_it_be(:other_merge_request) { create(:merge_request) }
let_it_be(:approval_rule_3) { create(:approval_merge_request_rule, merge_request: other_merge_request) }
let_it_be(:other_merged_merge_request) { create(:merge_request, :merged) }
let(:expected_value) { 1 }
let(:expected_query) { 'SELECT COUNT(DISTINCT "merge_requests"."id") FROM "merge_requests" INNER JOIN "approval_merge_request_rules" ON "approval_merge_request_rules"."merge_request_id" = "merge_requests"."id" WHERE ("merge_requests"."state_id" IN (3))' }
it_behaves_like 'a correct instrumented metric value and query', { time_frame: 'all' }
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