Commit 31bb128e authored by Doug Stull's avatar Doug Stull Committed by Rémy Coutable

Flatten counts for usage data to be only integers

- the version app expects the data in the counts field to be only
  type integer.
- we have already addressed the issue on the version side,
  but should also address it here by backfilling that change
  upstream into gitlab
parent fa829e7f
......@@ -61,13 +61,15 @@ module EE
# rubocop: disable CodeReuse/ActiveRecord
def projects_mirrored_with_pipelines_enabled
count(::Project.joins(:project_feature).where(
mirror: true,
mirror_trigger_builds: true,
project_features: {
builds_access_level: ::ProjectFeature::ENABLED
}
))
count(
::Project.joins(:project_feature).where(
mirror: true,
mirror_trigger_builds: true,
project_features: {
builds_access_level: ::ProjectFeature::ENABLED
}
)
)
end
# rubocop: enable CodeReuse/ActiveRecord
......@@ -79,11 +81,13 @@ module EE
{
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
))
service_desk_issues: count(
::Issue.where(
project: projects_with_service_desk,
author: ::User.support_bot,
confidential: true
)
)
}
end
# rubocop: enable CodeReuse/ActiveRecord
......@@ -109,8 +113,8 @@ module EE
def user_preferences_usage
super.tap do |user_prefs_usage|
user_prefs_usage.merge!(
group_overview_details: count(::User.active.group_view_details),
group_overview_security_dashboard: count(::User.active.group_view_security_dashboard)
user_preferences_group_overview_details: count(::User.active.group_view_details),
user_preferences_group_overview_security_dashboard: count(::User.active.group_view_security_dashboard)
)
end
end
......@@ -120,37 +124,37 @@ module EE
users_with_projects_added = count(UsersOpsDashboardProject.distinct_users(::User.active))
{
default_dashboard: users_with_ops_dashboard_as_default,
users_with_projects_added: users_with_projects_added
operations_dashboard_default_dashboard: users_with_ops_dashboard_as_default,
operations_dashboard_users_with_projects_added: users_with_projects_added
}
end
override :system_usage_data
def system_usage_data
usage_data = super
usage_data[:counts] = usage_data[:counts].merge({
dependency_list_usages_total: ::Gitlab::UsageCounters::DependencyList.usage_totals[:total],
epics: count(::Epic),
feature_flags: count(Operations::FeatureFlag),
geo_nodes: count(::GeoNode),
incident_issues: count_incident_issues,
ldap_group_links: count(::LdapGroupLink),
ldap_keys: count(::LDAPKey),
ldap_users: count(::User.ldap),
operations_dashboard: operations_dashboard_usage,
pod_logs_usages_total: ::Gitlab::UsageCounters::PodLogs.usage_totals[:total],
projects_enforcing_code_owner_approval: count(::Project.without_deleted.non_archived.requiring_code_owner_approval),
projects_mirrored_with_pipelines_enabled: projects_mirrored_with_pipelines_enabled,
projects_reporting_ci_cd_back_to_github: count(::GithubService.without_defaults.active),
projects_with_packages: count(::Packages::Package.select('distinct project_id')),
projects_with_prometheus_alerts: count(PrometheusAlert.distinct_projects),
projects_with_tracing_enabled: count(ProjectTracingSetting)
}).merge(service_desk_counts)
.merge(security_products_usage)
.merge(epics_deepest_relationship_level)
usage_data
super.tap do |usage_data|
usage_data[:counts].merge!({
dependency_list_usages_total: ::Gitlab::UsageCounters::DependencyList.usage_totals[:total],
epics: count(::Epic),
feature_flags: count(Operations::FeatureFlag),
geo_nodes: count(::GeoNode),
incident_issues: count_incident_issues,
ldap_group_links: count(::LdapGroupLink),
ldap_keys: count(::LDAPKey),
ldap_users: count(::User.ldap),
operations_dashboard: operations_dashboard_usage,
pod_logs_usages_total: ::Gitlab::UsageCounters::PodLogs.usage_totals[:total],
projects_enforcing_code_owner_approval: count(::Project.without_deleted.non_archived.requiring_code_owner_approval),
projects_mirrored_with_pipelines_enabled: projects_mirrored_with_pipelines_enabled,
projects_reporting_ci_cd_back_to_github: count(::GithubService.without_defaults.active),
projects_with_packages: count(::Packages::Package.select('distinct project_id')),
projects_with_prometheus_alerts: count(PrometheusAlert.distinct_projects),
projects_with_tracing_enabled: count(ProjectTracingSetting)
},
service_desk_counts,
security_products_usage,
epics_deepest_relationship_level,
operations_dashboard_usage)
end
end
override :jira_usage
......@@ -162,7 +166,7 @@ module EE
end
def epics_deepest_relationship_level
{ epics_deepest_relationship_level: ::Epic.deepest_relationship_level }
{ epics_deepest_relationship_level: ::Epic.deepest_relationship_level.to_i }
end
def count_incident_issues
......
......@@ -95,6 +95,10 @@ describe Gitlab::UsageData do
expect(count_data.keys).to include(:epics_deepest_relationship_level)
end
it 'has integer value for epic relationship level' do
expect(count_data[:epics_deepest_relationship_level]).to be_a_kind_of(Integer)
end
it 'gathers security products usage data' do
expect(count_data[:container_scanning_jobs]).to eq(1)
expect(count_data[:dast_jobs]).to eq(1)
......@@ -103,11 +107,9 @@ describe Gitlab::UsageData do
expect(count_data[:sast_jobs]).to eq(1)
end
it 'gathers group overview preferences usage data' do
expect(subject[:counts][:user_preferences]).to eq(
group_overview_details: User.active.count - 2, # we have exactly 2 active users with security dashboard set
group_overview_security_dashboard: 2
)
it 'gathers group overview preferences usage data', :aggregate_failures do
expect(subject[:counts][:user_preferences_group_overview_details]).to eq(User.active.count - 2) # we have exactly 2 active users with security dashboard set
expect(subject[:counts][:user_preferences_group_overview_security_dashboard]).to eq 2
end
end
......@@ -217,14 +219,14 @@ describe Gitlab::UsageData do
it 'gathers data on operations dashboard' do
expect(subject.keys).to include(*%i(
default_dashboard
users_with_projects_added
operations_dashboard_default_dashboard
operations_dashboard_users_with_projects_added
))
end
it 'bases counts on active users' do
expect(subject[:default_dashboard]).to eq(1)
expect(subject[:users_with_projects_added]).to eq(2)
it 'bases counts on active users', :aggregate_failures do
expect(subject[:operations_dashboard_default_dashboard]).to eq(1)
expect(subject[:operations_dashboard_users_with_projects_added]).to eq(2)
end
end
......
......@@ -37,7 +37,7 @@ module Gitlab
usage_data
end
# rubocop:disable Metrics/AbcSize
# rubocop: disable Metrics/AbcSize
# rubocop: disable CodeReuse/ActiveRecord
def system_usage_data
{
......@@ -96,14 +96,16 @@ module Gitlab
todos: count(Todo),
uploads: count(Upload),
web_hooks: count(WebHook)
}.merge(services_usage)
.merge(approximate_counts)
.merge(usage_counters)
}.tap do |data|
data[:counts][:user_preferences] = user_preferences_usage
end
}.merge(
services_usage,
approximate_counts,
usage_counters,
user_preferences_usage
)
}
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable Metrics/AbcSize
def cycle_analytics_usage_data
Gitlab::CycleAnalytics::UsageData.new.to_json
......@@ -137,15 +139,15 @@ module Gitlab
# @return [Array<#totals>] An array of objects that respond to `#totals`
def usage_data_counters
[
Gitlab::UsageDataCounters::WikiPageCounter,
Gitlab::UsageDataCounters::WebIdeCounter,
Gitlab::UsageDataCounters::NoteCounter,
Gitlab::UsageDataCounters::SnippetCounter,
Gitlab::UsageDataCounters::SearchCounter,
Gitlab::UsageDataCounters::CycleAnalyticsCounter,
Gitlab::UsageDataCounters::ProductivityAnalyticsCounter,
Gitlab::UsageDataCounters::SourceCodeCounter,
Gitlab::UsageDataCounters::MergeRequestCounter
Gitlab::UsageDataCounters::WikiPageCounter,
Gitlab::UsageDataCounters::WebIdeCounter,
Gitlab::UsageDataCounters::NoteCounter,
Gitlab::UsageDataCounters::SnippetCounter,
Gitlab::UsageDataCounters::SearchCounter,
Gitlab::UsageDataCounters::CycleAnalyticsCounter,
Gitlab::UsageDataCounters::ProductivityAnalyticsCounter,
Gitlab::UsageDataCounters::SourceCodeCounter,
Gitlab::UsageDataCounters::MergeRequestCounter
]
end
......
......@@ -38,7 +38,7 @@ describe Gitlab::UsageData do
subject { described_class.data }
it 'gathers usage data' do
it 'gathers usage data', :aggregate_failures do
expect(subject.keys).to include(*%i(
active_user_count
counts
......@@ -151,7 +151,8 @@ describe Gitlab::UsageData do
todos
uploads
web_hooks
user_preferences
user_preferences_group_overview_details
user_preferences_group_overview_security_dashboard
).push(*smau_keys)
count_data = subject[:counts]
......@@ -163,7 +164,7 @@ describe Gitlab::UsageData do
expect(expected_keys - count_data.keys).to be_empty
end
it 'gathers projects data correctly' do
it 'gathers projects data correctly', :aggregate_failures do
count_data = subject[:counts]
expect(count_data[:projects]).to eq(4)
......@@ -209,11 +210,8 @@ describe Gitlab::UsageData do
describe 'the results of calling #totals on all objects in the array' do
subject { described_class.usage_data_counters.map(&:totals) }
it do
is_expected
.to all(be_a Hash)
.and all(have_attributes(keys: all(be_a Symbol), values: all(be_a Integer)))
end
it { is_expected.to all(be_a Hash) }
it { is_expected.to all(have_attributes(keys: all(be_a Symbol), values: all(be_a Integer))) }
end
it 'does not have any conflicts' do
......@@ -226,7 +224,7 @@ describe Gitlab::UsageData do
describe '#features_usage_data_ce' do
subject { described_class.features_usage_data_ce }
it 'gathers feature usage data' do
it 'gathers feature usage data', :aggregate_failures do
expect(subject[:mattermost_enabled]).to eq(Gitlab.config.mattermost.enabled)
expect(subject[:signup_enabled]).to eq(Gitlab::CurrentSettings.allow_signup?)
expect(subject[:ldap_enabled]).to eq(Gitlab.config.ldap.enabled)
......@@ -242,7 +240,7 @@ describe Gitlab::UsageData do
describe '#components_usage_data' do
subject { described_class.components_usage_data }
it 'gathers components usage data' do
it 'gathers components usage data', :aggregate_failures do
expect(subject[:gitlab_pages][:enabled]).to eq(Gitlab.config.pages.enabled)
expect(subject[:gitlab_pages][:version]).to eq(Gitlab::Pages::VERSION)
expect(subject[:git][:version]).to eq(Gitlab::Git.version)
......@@ -258,7 +256,7 @@ describe Gitlab::UsageData do
describe '#license_usage_data' do
subject { described_class.license_usage_data }
it 'gathers license data' do
it 'gathers license data', :aggregate_failures do
expect(subject[:uuid]).to eq(Gitlab::CurrentSettings.uuid)
expect(subject[:version]).to eq(Gitlab::VERSION)
expect(subject[:installation_type]).to eq('gitlab-development-kit')
......@@ -290,11 +288,11 @@ describe Gitlab::UsageData do
end
describe '#approximate_counts' do
it 'gets approximate counts for selected models' do
it 'gets approximate counts for selected models', :aggregate_failures do
create(:label)
expect(Gitlab::Database::Count).to receive(:approximate_counts)
.with(described_class::APPROXIMATE_COUNT_MODELS).once.and_call_original
.with(described_class::APPROXIMATE_COUNT_MODELS).once.and_call_original
counts = described_class.approximate_counts.values
......@@ -302,14 +300,12 @@ describe Gitlab::UsageData do
expect(counts.any? { |count| count < 0 }).to be_falsey
end
it 'returns default values if counts can not be retrieved' do
it 'returns default values if counts can not be retrieved', :aggregate_failures do
described_class::APPROXIMATE_COUNT_MODELS.map do |model|
model.name.underscore.pluralize.to_sym
end
expect(Gitlab::Database::Count).to receive(:approximate_counts)
.and_return({})
expect(Gitlab::Database::Count).to receive(:approximate_counts).and_return({})
expect(described_class.approximate_counts.values.uniq).to eq([-1])
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