Commit 879d1679 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'pb-move-merge-requests-users-metric' into 'master'

Move merge_requests_users metric to stage section

See merge request gitlab-org/gitlab!35593
parents a055c03a ab67b5c4
---
title: Move merge_requests_users metric to stage section
merge_request: 35593
author:
type: changed
......@@ -665,6 +665,7 @@ appear to be associated to any of the services running, since they all appear to
| `ci_triggers` | `usage_activity_by_stage` | `verify` | | | Triggers enabled |
| `clusters_applications_runner` | `usage_activity_by_stage` | `verify` | | | Unique clusters with Runner enabled |
| `projects_reporting_ci_cd_back_to_github: 0` | `usage_activity_by_stage` | `verify` | | | Unique projects with a GitHub pipeline enabled |
| `merge_requests_users` | `usage_activity_by_stage_monthly` | `create` | | | Unique count of users who used a merge request |
| `nodes` | `topology` | `enablement` | | | The list of server nodes on which GitLab components are running |
| `duration_s` | `topology` | `enablement` | | | Time it took to collect topology data |
| `node_memory_total_bytes` | `topology > nodes` | `enablement` | | | The total available memory of this node |
......
......@@ -360,6 +360,7 @@ RSpec.describe Gitlab::UsageData do
keys: 1,
merge_requests: 6,
projects_enforcing_code_owner_approval: 0,
merge_requests_users: 0,
merge_requests_with_optional_codeowners: 2,
merge_requests_with_required_codeowners: 4,
projects_imported_from_github: 1,
......
......@@ -159,8 +159,7 @@ module Gitlab
usage_counters,
user_preferences_usage,
ingress_modsecurity_usage,
container_expiration_policies_usage,
merge_requests_usage(last_28_days_time_period)
container_expiration_policies_usage
).tap do |data|
data[:snippets] = data[:personal_snippets] + data[:project_snippets]
end
......@@ -405,23 +404,19 @@ module Gitlab
end
# rubocop: disable CodeReuse/ActiveRecord
def merge_requests_usage(time_period)
def merge_requests_users(time_period)
query =
Event
.where(target_type: Event::TARGET_TYPES[:merge_request].to_s)
.where(time_period)
merge_request_users = distinct_count(
distinct_count(
query,
:author_id,
batch_size: 5_000, # Based on query performance, this is the optimal batch size.
start: User.minimum(:id),
finish: User.maximum(:id)
)
{
merge_requests_users: merge_request_users
}
end
# rubocop: enable CodeReuse/ActiveRecord
......@@ -477,9 +472,10 @@ module Gitlab
end
# rubocop: enable CodeReuse/ActiveRecord
# Omitted because no user, creator or author associated: `lfs_objects`, `pool_repositories`, `web_hooks`
def usage_activity_by_stage_create(time_period)
{}
{}.tap do |h|
h[:merge_requests_users] = merge_requests_users(time_period) if time_period.present?
end
end
# Omitted because no user, creator or author associated: `campaigns_imported_from_github`, `ldap_group_links`
......
......@@ -77,6 +77,22 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
end
context 'for create' do
it 'include usage_activity_by_stage data' do
expect(described_class.uncached_data[:usage_activity_by_stage][:create])
.not_to include(
:merge_requests_users
)
end
it 'includes monthly usage_activity_by_stage data' do
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:create])
.to include(
:merge_requests_users
)
end
end
it 'ensures recorded_at is set before any other usage data calculation' do
%i(alt_usage_data redis_usage_data distinct_count count).each do |method|
expect(described_class).not_to receive(method)
......@@ -662,7 +678,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
end
describe '.merge_requests_usage' do
describe '.merge_requests_users' do
let(:time_period) { { created_at: 2.days.ago..Time.current } }
let(:merge_request) { create(:merge_request) }
let(:other_user) { create(:user) }
......@@ -679,9 +695,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
it 'returns the distinct count of users using merge requests (via events table) within the specified time period' do
expect(described_class.merge_requests_usage(time_period)).to eq(
merge_requests_users: 2
)
expect(described_class.merge_requests_users(time_period)).to eq(2)
end
end
......
......@@ -78,7 +78,6 @@ module UsageDataHelpers
labels
lfs_objects
merge_requests
merge_requests_users
milestone_lists
milestones
notes
......
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