Commit df742a89 authored by minghuan lei's avatar minghuan lei Committed by Imre Farkas

Add template repository usage to the usage ping

parent 5bb90b56
---
title: Add template repository usage to the usage ping
merge_request: 20126
author: minghuan lei
type: changed
...@@ -144,6 +144,8 @@ module EE ...@@ -144,6 +144,8 @@ module EE
scope :with_slack_slash_commands_service, -> { joins(:slack_slash_commands_service) } scope :with_slack_slash_commands_service, -> { joins(:slack_slash_commands_service) }
scope :with_prometheus_service, -> { joins(:prometheus_service) } scope :with_prometheus_service, -> { joins(:prometheus_service) }
scope :aimed_for_deletion, -> (date) { where('marked_for_deletion_at <= ?', date).without_deleted } scope :aimed_for_deletion, -> (date) { where('marked_for_deletion_at <= ?', date).without_deleted }
scope :with_repos_templates, -> { where(namespace_id: ::Gitlab::CurrentSettings.current_application_settings.custom_project_templates_group_id) }
scope :with_groups_level_repos_templates, -> { joins("INNER JOIN namespaces ON projects.namespace_id = namespaces.custom_project_templates_group_id") }
delegate :shared_runners_minutes, :shared_runners_seconds, :shared_runners_seconds_last_reset, delegate :shared_runners_minutes, :shared_runners_seconds, :shared_runners_seconds_last_reset,
to: :statistics, allow_nil: true to: :statistics, allow_nil: true
......
...@@ -138,7 +138,8 @@ module EE ...@@ -138,7 +138,8 @@ module EE
projects_with_packages: count(::Packages::Package.select('distinct project_id')), projects_with_packages: count(::Packages::Package.select('distinct project_id')),
projects_with_prometheus_alerts: count(PrometheusAlert.distinct_projects), projects_with_prometheus_alerts: count(PrometheusAlert.distinct_projects),
projects_with_tracing_enabled: count(ProjectTracingSetting), projects_with_tracing_enabled: count(ProjectTracingSetting),
projects_with_alerts_service_enabled: count(AlertsService.active) projects_with_alerts_service_enabled: count(AlertsService.active),
template_repositories: count(::Project.with_repos_templates) + count(::Project.with_groups_level_repos_templates)
}, },
service_desk_counts, service_desk_counts,
security_products_usage, security_products_usage,
......
...@@ -93,6 +93,7 @@ describe Gitlab::UsageData do ...@@ -93,6 +93,7 @@ describe Gitlab::UsageData do
design_management_designs_delete design_management_designs_delete
user_preferences_group_overview_details user_preferences_group_overview_details
user_preferences_group_overview_security_dashboard user_preferences_group_overview_security_dashboard
template_repositories
)) ))
expect(count_data[:projects_with_prometheus_alerts]).to eq(2) expect(count_data[:projects_with_prometheus_alerts]).to eq(2)
......
...@@ -2352,4 +2352,35 @@ describe Project do ...@@ -2352,4 +2352,35 @@ describe Project do
end end
end end
end end
describe 'caculate template repositories' do
let(:group1) { create(:group) }
let(:group2) { create(:group) }
let(:group2_sub1) { create(:group, parent: group2) }
let(:group2_sub2) { create(:group, parent: group2) }
before do
stub_ee_application_setting(custom_project_templates_group_id: group2.id)
group2.update(custom_project_templates_group_id: group2_sub2.id)
create(:project, group: group1)
2.times do
create(:project, group: group2)
end
3.times do
create(:project, group: group2_sub1)
end
4.times do
create(:project, group: group2_sub2)
end
end
it 'counts instance level templates' do
expect(described_class.with_repos_templates.count).to eq(2)
end
it 'counts group level templates' do
expect(described_class.with_groups_level_repos_templates.count).to eq(4)
end
end
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