New Compliance metrics to implement
Problem Statement
There are several new metrics that are being requested in order to determine how users are using the Compliance features. We need to determine if these are feasible and implement them accordingly.
https://gitlab.com/gitlab-com/sales-team/field-operations/customer-success-operations/-/issues/1917 |
counts.MONTHLY.merged_merge_requests_using_approval_rules_distinct | Count of distinct merge requests merged using approval rules in the last 28 days |
https://gitlab.com/gitlab-com/sales-team/field-operations/customer-success-operations/-/issues/1917 |
MR approval rules set up per project (that require review from a security team) | How many rules are setup per project |
Purposed Implementation Plan
For Count of distinct merge requests merged using approval rules in the last 28d.
- Create metric definition
bundle exec rails generate gitlab:usage_metric_definition usage_activity_by_stage_monthly.govern.merged_merge_requests_using_approval_rules_distinct --ee --dir=28d --class_name=CountDistinctMergedMergeRequestsUsingApprovalRulesMetric
- Update this file with product section details
- We already have instrumentation class for time_frame all so by specifying time_frame: 28d we can use same instrumentation class.
- Test everything is working fine by generating payload,
payload = ServicePing::BuildPayload.new.execute
and checking newly added metrics.
For How many rules are setup per project
-
Create metric definition
-
for 28d
bundle exec rails generate gitlab:usage_metric_definition usage_activity_by_stage_monthly.govern.projects_using_approval_rule_distinct --ee --dir=28d --class_name=CountDistinctProjectsUsingApprovalRulesMetric
-
for all time frame
bundle exec rails generate gitlab:usage_metric_definition usage_activity_by_stage.govern.projects_using_approval_rule_distinct --ee --class_name=CountDistinctProjectsUsingApprovalRulesMetric --dir=all
-
Make sure for monthly metric we have
time_frame: 28d
and for all we havetime_frame: all
in yml definitions. -
Create CountDistinctProjectsUsingApprovalRulesMetric class below is the code we can use for this.
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Instrumentations
class CountApprovalProjectRulesMetric < DatabaseMetric
operation :count
relation { ApprovalProjectRule }
end
end
end
end
end
- Test payload generation and metrics data,
payload = ServicePing::BuildPayload.new.execute