Commit 8d4a921c authored by Alper Akgun's avatar Alper Akgun Committed by Robert Speicher

Move manage stage usage activity to CE

Also updates the documentation
parent db775720
---
title: Move manage stage usage activity to CE
merge_request: 36089
author:
type: changed
......@@ -655,6 +655,18 @@ appear to be associated to any of the services running, since they all appear to
| `projects_prometheus_active` | `usage_activity_by_stage` | `monitor` | | EE | |
| `projects_with_error_tracking_enabled` | `usage_activity_by_stage` | `monitor` | | EE | |
| `projects_with_tracing_enabled` | `usage_activity_by_stage` | `monitor` | | EE | |
| `events` | `usage_activity_by_stage` | `manage` | | CE+EE | |
| `groups` | `usage_activity_by_stage` | `manage` | | CE+EE | |
| `users_created_at` | `usage_activity_by_stage` | `manage` | | CE+EE | |
| `omniauth_providers` | `usage_activity_by_stage` | `manage` | | CE+EE | |
| `ldap_keys` | `usage_activity_by_stage` | `manage` | | EE | |
| `ldap_users` | `usage_activity_by_stage` | `manage` | | EE | |
| `value_stream_management_customized_group_stages` | `usage_activity_by_stage` | `manage` | | EE | |
| `projects_with_compliance_framework` | `usage_activity_by_stage` | `manage` | | EE | |
| `ldap_servers` | `usage_activity_by_stage` | `manage` | | EE | |
| `ldap_group_sync_enabled` | `usage_activity_by_stage` | `manage` | | EE | |
| `ldap_admin_sync_enabled` | `usage_activity_by_stage` | `manage` | | EE | |
| `group_saml_enabled` | `usage_activity_by_stage` | `manage` | | EE | |
| `keys` | `usage_activity_by_stage` | `create` | | | |
| `projects_jira_dvcs_server_active` | `usage_activity_by_stage` | `plan` | | | |
| `service_desk_enabled_projects` | `usage_activity_by_stage` | `plan` | | | |
......
......@@ -237,17 +237,13 @@ module EE
override :usage_activity_by_stage_manage
def usage_activity_by_stage_manage(time_period)
super.merge({
events: distinct_count(::Event.where(time_period), :author_id),
groups: distinct_count(::GroupMember.where(time_period), :user_id),
ldap_keys: distinct_count(::LDAPKey.where(time_period), :user_id),
ldap_users: distinct_count(::GroupMember.of_ldap_type.where(time_period), :user_id),
users_created: count(::User.where(time_period), start: user_minimum_id, finish: user_maximum_id),
value_stream_management_customized_group_stages: count(::Analytics::CycleAnalytics::GroupStage.where(custom: true)),
projects_with_compliance_framework: count(::ComplianceManagement::ComplianceFramework::ProjectSettings),
ldap_servers: ldap_available_servers.size,
ldap_group_sync_enabled: ldap_config_present_for_any_provider?(:group_base),
ldap_admin_sync_enabled: ldap_config_present_for_any_provider?(:admin_group),
omniauth_providers: filtered_omniauth_provider_names.reject { |name| name == 'group_saml' },
group_saml_enabled: omniauth_provider_names.include?('group_saml')
})
end
......@@ -356,24 +352,12 @@ module EE
end
# rubocop:enable CodeReuse/ActiveRecord
def ldap_available_servers
::Gitlab::Auth::Ldap::Config.available_servers
end
def ldap_config_present_for_any_provider?(configuration_item)
ldap_available_servers.any? { |server_config| server_config[configuration_item.to_s] }
end
def omniauth_provider_names
::Gitlab.config.omniauth.providers.map(&:name)
end
# LDAP provider names are set by customers and could include
# sensitive info (server names, etc). LDAP providers normally
# don't appear in omniauth providers but filter to ensure
# no internal details leak via usage ping.
def filtered_omniauth_provider_names
omniauth_provider_names.reject { |name| name.starts_with?('ldap') }
def ldap_available_servers
::Gitlab::Auth::Ldap::Config.available_servers
end
end
end
......
......@@ -364,59 +364,39 @@ RSpec.describe Gitlab::UsageData do
it 'includes accurate usage_activity_by_stage data' do
stub_config(
ldap:
{ enabled: true, servers: ldap_server_config },
omniauth:
{ providers: omniauth_providers }
{ enabled: true, servers: ldap_server_config }
)
for_defined_days_back do
user = create(:user)
create(:event, author: user)
create(:group_member, user: user)
create(:key, type: 'LDAPKey', user: user)
create(:group_member, ldap: true, user: user)
create(:cycle_analytics_group_stage)
create(:compliance_framework_project_setting)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:manage]).to eq(
events: 2,
groups: 2,
expect(described_class.uncached_data[:usage_activity_by_stage][:manage]).to include(
ldap_keys: 2,
ldap_users: 2,
users_created: 8,
value_stream_management_customized_group_stages: 2,
projects_with_compliance_framework: 2,
ldap_servers: 2,
ldap_group_sync_enabled: true,
ldap_admin_sync_enabled: true,
omniauth_providers: ['google_oauth2'],
group_saml_enabled: true
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:manage]).to eq(
events: 1,
groups: 1,
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:manage]).to include(
ldap_keys: 1,
ldap_users: 1,
users_created: 5,
value_stream_management_customized_group_stages: 2,
projects_with_compliance_framework: 2,
ldap_servers: 2,
ldap_group_sync_enabled: true,
ldap_admin_sync_enabled: true,
omniauth_providers: ['google_oauth2'],
group_saml_enabled: true
)
end
def omniauth_providers
[
OpenStruct.new(name: 'google_oauth2'),
OpenStruct.new(name: 'ldapmain'),
OpenStruct.new(name: 'group_saml')
]
end
def ldap_server_config
{
'main' =>
......
......@@ -486,9 +486,16 @@ module Gitlab
end
# Omitted because no user, creator or author associated: `campaigns_imported_from_github`, `ldap_group_links`
# rubocop: disable CodeReuse/ActiveRecord
def usage_activity_by_stage_manage(time_period)
{}
{
events: distinct_count(::Event.where(time_period), :author_id),
groups: distinct_count(::GroupMember.where(time_period), :user_id),
users_created: count(::User.where(time_period), start: user_minimum_id, finish: user_maximum_id),
omniauth_providers: filtered_omniauth_provider_names.reject { |name| name == 'group_saml' }
}
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def usage_activity_by_stage_monitor(time_period)
......@@ -596,6 +603,18 @@ module Gitlab
distinct_count(clusters.where(time_period), :user_id)
end
# rubocop: enable CodeReuse/ActiveRecord
def omniauth_provider_names
::Gitlab.config.omniauth.providers.map(&:name)
end
# LDAP provider names are set by customers and could include
# sensitive info (server names, etc). LDAP providers normally
# don't appear in omniauth providers but filter to ensure
# no internal details leak via usage ping.
def filtered_omniauth_provider_names
omniauth_provider_names.reject { |name| name.starts_with?('ldap') }
end
end
end
end
......
......@@ -75,6 +75,42 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
)
end
end
context 'for manage' do
it 'includes accurate usage_activity_by_stage data' do
stub_config(
omniauth:
{ providers: omniauth_providers }
)
for_defined_days_back do
user = create(:user)
create(:event, author: user)
create(:group_member, user: user)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:manage]).to include(
events: 2,
groups: 2,
users_created: Gitlab.ee? ? 6 : 5,
omniauth_providers: ['google_oauth2']
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:manage]).to include(
events: 1,
groups: 1,
users_created: Gitlab.ee? ? 4 : 3,
omniauth_providers: ['google_oauth2']
)
end
def omniauth_providers
[
OpenStruct.new(name: 'google_oauth2'),
OpenStruct.new(name: 'ldapmain'),
OpenStruct.new(name: 'group_saml')
]
end
end
end
context 'for create' do
......
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