Commit 87f5aeff authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'issue_215364_move_usage_data' into 'master'

Move service desk usage data to core

See merge request gitlab-org/gitlab!37080
parents 778d32b7 ff243edb
---
title: Move service desk usage data to core
merge_request: 37080
author:
type: changed
...@@ -97,7 +97,6 @@ module EE ...@@ -97,7 +97,6 @@ module EE
} }
end end
# rubocop: disable CodeReuse/ActiveRecord
def approval_rules_counts def approval_rules_counts
{ {
approval_project_rules: count(ApprovalProjectRule), approval_project_rules: count(ApprovalProjectRule),
...@@ -105,24 +104,6 @@ module EE ...@@ -105,24 +104,6 @@ module EE
} }
end end
def service_desk_counts
projects_with_service_desk = ::Project.where(service_desk_enabled: true)
{
service_desk_enabled_projects: count(projects_with_service_desk),
service_desk_issues: count(
::Issue.where(
project: projects_with_service_desk,
author: ::User.support_bot,
confidential: true
),
start: issue_minimum_id,
finish: issue_maximum_id
)
}
end
# rubocop: enable CodeReuse/ActiveRecord
def security_products_usage def security_products_usage
results = SECURE_PRODUCT_TYPES.each_with_object({}) do |(secure_type, attribs), response| results = SECURE_PRODUCT_TYPES.each_with_object({}) do |(secure_type, attribs), response|
response[attribs[:name]] = count(::Ci::Build.where(name: secure_type)) # rubocop:disable CodeReuse/ActiveRecord response[attribs[:name]] = count(::Ci::Build.where(name: secure_type)) # rubocop:disable CodeReuse/ActiveRecord
...@@ -195,7 +176,6 @@ module EE ...@@ -195,7 +176,6 @@ module EE
template_repositories: count(::Project.with_repos_templates) + count(::Project.with_groups_level_repos_templates) template_repositories: count(::Project.with_repos_templates) + count(::Project.with_groups_level_repos_templates)
}, },
requirements_counts, requirements_counts,
service_desk_counts,
security_products_usage, security_products_usage,
epics_deepest_relationship_level, epics_deepest_relationship_level,
operations_dashboard_usage) operations_dashboard_usage)
...@@ -298,9 +278,7 @@ module EE ...@@ -298,9 +278,7 @@ module EE
milestone_lists: distinct_count(::List.milestone.where(time_period), :user_id), milestone_lists: distinct_count(::List.milestone.where(time_period), :user_id),
projects_jira_active: distinct_count(::Project.with_active_jira_services.where(time_period), :creator_id), projects_jira_active: distinct_count(::Project.with_active_jira_services.where(time_period), :creator_id),
projects_jira_dvcs_cloud_active: distinct_count(::Project.with_active_jira_services.with_jira_dvcs_cloud.where(time_period), :creator_id), projects_jira_dvcs_cloud_active: distinct_count(::Project.with_active_jira_services.with_jira_dvcs_cloud.where(time_period), :creator_id),
projects_jira_dvcs_server_active: distinct_count(::Project.with_active_jira_services.with_jira_dvcs_server.where(time_period), :creator_id), projects_jira_dvcs_server_active: distinct_count(::Project.with_active_jira_services.with_jira_dvcs_server.where(time_period), :creator_id)
service_desk_enabled_projects: distinct_count_service_desk_enabled_projects(time_period),
service_desk_issues: count(::Issue.service_desk.where(time_period))
}) })
end end
...@@ -347,6 +325,7 @@ module EE ...@@ -347,6 +325,7 @@ module EE
super.merge(results) super.merge(results)
end end
# rubocop:enable CodeReuse/ActiveRecord
private private
...@@ -362,14 +341,6 @@ module EE ...@@ -362,14 +341,6 @@ module EE
end end
end end
def distinct_count_service_desk_enabled_projects(time_period)
project_creator_id_start = user_minimum_id
project_creator_id_finish = user_maximum_id
distinct_count(::Project.service_desk_enabled.where(time_period), :creator_id, start: project_creator_id_start, finish: project_creator_id_finish)
end
# rubocop:enable CodeReuse/ActiveRecord
def ldap_config_present_for_any_provider?(configuration_item) def ldap_config_present_for_any_provider?(configuration_item)
ldap_available_servers.any? { |server_config| server_config[configuration_item.to_s] } ldap_available_servers.any? { |server_config| server_config[configuration_item.to_s] }
end end
......
...@@ -218,19 +218,6 @@ RSpec.describe Gitlab::UsageData do ...@@ -218,19 +218,6 @@ RSpec.describe Gitlab::UsageData do
end end
end end
describe '.service_desk_counts' do
subject { described_class.service_desk_counts }
let(:project) { create(:project, :service_desk_enabled) }
it 'gathers Service Desk data' do
create_list(:issue, 2, confidential: true, author: User.support_bot, project: project)
expect(subject).to eq(service_desk_enabled_projects: 1,
service_desk_issues: 2)
end
end
describe 'code owner approval required' do describe 'code owner approval required' do
before do before do
create(:protected_branch, code_owner_approval_required: true) create(:protected_branch, code_owner_approval_required: true)
...@@ -459,7 +446,6 @@ RSpec.describe Gitlab::UsageData do ...@@ -459,7 +446,6 @@ RSpec.describe Gitlab::UsageData do
for_defined_days_back do for_defined_days_back do
user = create(:user) user = create(:user)
project = create(:project, creator: user) project = create(:project, creator: user)
create(:issue, project: project, author: User.support_bot)
board = create(:board, project: project) board = create(:board, project: project)
create(:user_list, board: board, user: user) create(:user_list, board: board, user: user)
create(:milestone_list, board: board, milestone: create(:milestone, project: project), user: user) create(:milestone_list, board: board, milestone: create(:milestone, project: project), user: user)
...@@ -476,9 +462,7 @@ RSpec.describe Gitlab::UsageData do ...@@ -476,9 +462,7 @@ RSpec.describe Gitlab::UsageData do
milestone_lists: 2, milestone_lists: 2,
projects_jira_active: 2, projects_jira_active: 2,
projects_jira_dvcs_cloud_active: 2, projects_jira_dvcs_cloud_active: 2,
projects_jira_dvcs_server_active: 2, projects_jira_dvcs_server_active: 2
service_desk_enabled_projects: 2,
service_desk_issues: 2
) )
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:plan]).to include( expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:plan]).to include(
assignee_lists: 1, assignee_lists: 1,
...@@ -487,9 +471,7 @@ RSpec.describe Gitlab::UsageData do ...@@ -487,9 +471,7 @@ RSpec.describe Gitlab::UsageData do
milestone_lists: 1, milestone_lists: 1,
projects_jira_active: 1, projects_jira_active: 1,
projects_jira_dvcs_cloud_active: 1, projects_jira_dvcs_cloud_active: 1,
projects_jira_dvcs_server_active: 1, projects_jira_dvcs_server_active: 1
service_desk_enabled_projects: 1,
service_desk_issues: 1
) )
end end
end end
......
...@@ -159,7 +159,8 @@ module Gitlab ...@@ -159,7 +159,8 @@ 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,
service_desk_counts
).tap do |data| ).tap do |data|
data[:snippets] = data[:personal_snippets] + data[:project_snippets] data[:snippets] = data[:personal_snippets] + data[:project_snippets]
end end
...@@ -527,7 +528,9 @@ module Gitlab ...@@ -527,7 +528,9 @@ module Gitlab
issues: distinct_count(::Issue.where(time_period), :author_id), issues: distinct_count(::Issue.where(time_period), :author_id),
notes: distinct_count(::Note.where(time_period), :author_id), notes: distinct_count(::Note.where(time_period), :author_id),
projects: distinct_count(::Project.where(time_period), :creator_id), projects: distinct_count(::Project.where(time_period), :creator_id),
todos: distinct_count(::Todo.where(time_period), :author_id) todos: distinct_count(::Todo.where(time_period), :author_id),
service_desk_enabled_projects: distinct_count_service_desk_enabled_projects(time_period),
service_desk_issues: count(::Issue.service_desk.where(time_period))
} }
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
...@@ -615,6 +618,30 @@ module Gitlab ...@@ -615,6 +618,30 @@ module Gitlab
private private
def distinct_count_service_desk_enabled_projects(time_period)
project_creator_id_start = user_minimum_id
project_creator_id_finish = user_maximum_id
distinct_count(::Project.service_desk_enabled.where(time_period), :creator_id, start: project_creator_id_start, finish: project_creator_id_finish) # rubocop: disable CodeReuse/ActiveRecord
end
# rubocop: disable CodeReuse/ActiveRecord
def service_desk_counts
projects_with_service_desk = ::Project.where(service_desk_enabled: true)
{
service_desk_enabled_projects: count(projects_with_service_desk),
service_desk_issues: count(
::Issue.where(
project: projects_with_service_desk,
author: ::User.support_bot,
confidential: true
)
)
}
end
# rubocop: enable CodeReuse/ActiveRecord
def unique_visit_service def unique_visit_service
strong_memoize(:unique_visit_service) do strong_memoize(:unique_visit_service) do
::Gitlab::Analytics::UniqueVisits.new ::Gitlab::Analytics::UniqueVisits.new
......
...@@ -155,13 +155,13 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -155,13 +155,13 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
expect(described_class.uncached_data[:usage_activity_by_stage][:manage]).to include( expect(described_class.uncached_data[:usage_activity_by_stage][:manage]).to include(
events: 2, events: 2,
groups: 2, groups: 2,
users_created: Gitlab.ee? ? 6 : 5, users_created: 6,
omniauth_providers: ['google_oauth2'] omniauth_providers: ['google_oauth2']
) )
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:manage]).to include( expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:manage]).to include(
events: 1, events: 1,
groups: 1, groups: 1,
users_created: Gitlab.ee? ? 4 : 3, users_created: 4,
omniauth_providers: ['google_oauth2'] omniauth_providers: ['google_oauth2']
) )
end end
...@@ -203,21 +203,26 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -203,21 +203,26 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
user = create(:user) user = create(:user)
project = create(:project, creator: user) project = create(:project, creator: user)
issue = create(:issue, project: project, author: user) issue = create(:issue, project: project, author: user)
create(:issue, project: project, author: User.support_bot)
create(:note, project: project, noteable: issue, author: user) create(:note, project: project, noteable: issue, author: user)
create(:todo, project: project, target: issue, author: user) create(:todo, project: project, target: issue, author: user)
end end
expect(described_class.uncached_data[:usage_activity_by_stage][:plan]).to include( expect(described_class.uncached_data[:usage_activity_by_stage][:plan]).to include(
issues: 2, issues: 3,
notes: 2, notes: 2,
projects: 2, projects: 2,
todos: 2 todos: 2,
service_desk_enabled_projects: 2,
service_desk_issues: 2
) )
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:plan]).to include( expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:plan]).to include(
issues: 1, issues: 2,
notes: 1, notes: 1,
projects: 1, projects: 1,
todos: 1 todos: 1,
service_desk_enabled_projects: 1,
service_desk_issues: 1
) )
end end
end end
...@@ -974,4 +979,17 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -974,4 +979,17 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
}) })
end end
end end
describe '.service_desk_counts' do
subject { described_class.send(:service_desk_counts) }
let(:project) { create(:project, :service_desk_enabled) }
it 'gathers Service Desk data' do
create_list(:issue, 2, :confidential, author: User.support_bot, project: project)
expect(subject).to eq(service_desk_enabled_projects: 1,
service_desk_issues: 2)
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