Commit ab67b5c4 authored by Patrick Bajao's avatar Patrick Bajao Committed by Bob Van Landuyt

Move merge_requests_users metric to stage section

The `merge_requests_users` metric is specific to create stage so
it's more appropriate to move it to the appropriate section.
parent dd3378e6
---
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 ...@@ -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 | | `ci_triggers` | `usage_activity_by_stage` | `verify` | | | Triggers enabled |
| `clusters_applications_runner` | `usage_activity_by_stage` | `verify` | | | Unique clusters with Runner 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 | | `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 | | `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 | | `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 | | `node_memory_total_bytes` | `topology > nodes` | `enablement` | | | The total available memory of this node |
......
...@@ -360,6 +360,7 @@ RSpec.describe Gitlab::UsageData do ...@@ -360,6 +360,7 @@ RSpec.describe Gitlab::UsageData do
keys: 1, keys: 1,
merge_requests: 6, merge_requests: 6,
projects_enforcing_code_owner_approval: 0, projects_enforcing_code_owner_approval: 0,
merge_requests_users: 0,
merge_requests_with_optional_codeowners: 2, merge_requests_with_optional_codeowners: 2,
merge_requests_with_required_codeowners: 4, merge_requests_with_required_codeowners: 4,
projects_imported_from_github: 1, projects_imported_from_github: 1,
......
...@@ -159,8 +159,7 @@ module Gitlab ...@@ -159,8 +159,7 @@ module Gitlab
usage_counters, usage_counters,
user_preferences_usage, user_preferences_usage,
ingress_modsecurity_usage, ingress_modsecurity_usage,
container_expiration_policies_usage, container_expiration_policies_usage
merge_requests_usage(last_28_days_time_period)
).tap do |data| ).tap do |data|
data[:snippets] = data[:personal_snippets] + data[:project_snippets] data[:snippets] = data[:personal_snippets] + data[:project_snippets]
end end
...@@ -405,23 +404,19 @@ module Gitlab ...@@ -405,23 +404,19 @@ module Gitlab
end end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def merge_requests_usage(time_period) def merge_requests_users(time_period)
query = query =
Event Event
.where(target_type: Event::TARGET_TYPES[:merge_request].to_s) .where(target_type: Event::TARGET_TYPES[:merge_request].to_s)
.where(time_period) .where(time_period)
merge_request_users = distinct_count( distinct_count(
query, query,
:author_id, :author_id,
batch_size: 5_000, # Based on query performance, this is the optimal batch size. batch_size: 5_000, # Based on query performance, this is the optimal batch size.
start: User.minimum(:id), start: User.minimum(:id),
finish: User.maximum(:id) finish: User.maximum(:id)
) )
{
merge_requests_users: merge_request_users
}
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
...@@ -477,9 +472,10 @@ module Gitlab ...@@ -477,9 +472,10 @@ module Gitlab
end end
# rubocop: enable CodeReuse/ActiveRecord # 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) 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 end
# Omitted because no user, creator or author associated: `campaigns_imported_from_github`, `ldap_group_links` # 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 ...@@ -77,6 +77,22 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end end
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 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| %i(alt_usage_data redis_usage_data distinct_count count).each do |method|
expect(described_class).not_to receive(method) expect(described_class).not_to receive(method)
...@@ -662,7 +678,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -662,7 +678,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end end
end end
describe '.merge_requests_usage' do describe '.merge_requests_users' do
let(:time_period) { { created_at: 2.days.ago..Time.current } } let(:time_period) { { created_at: 2.days.ago..Time.current } }
let(:merge_request) { create(:merge_request) } let(:merge_request) { create(:merge_request) }
let(:other_user) { create(:user) } let(:other_user) { create(:user) }
...@@ -679,9 +695,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -679,9 +695,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end end
it 'returns the distinct count of users using merge requests (via events table) within the specified time period' do 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( expect(described_class.merge_requests_users(time_period)).to eq(2)
merge_requests_users: 2
)
end end
end end
......
...@@ -78,7 +78,6 @@ module UsageDataHelpers ...@@ -78,7 +78,6 @@ module UsageDataHelpers
labels labels
lfs_objects lfs_objects
merge_requests merge_requests
merge_requests_users
milestone_lists milestone_lists
milestones milestones
notes 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