Commit c15031bb authored by Thong Kuah's avatar Thong Kuah

Merge branch '208697-usage-ping-timeouts-on-security_products_usage-for-large-hosts' into 'master'

Resolve "Usage Ping timeouts on security_products_usage for large hosts"

Closes #208697

See merge request gitlab-org/gitlab!26296
parents 61e3e6c2 5d397c42
---
title: Resolve Usage Ping timeouts on security_products_usage for large hosts
merge_request: 26296
author:
type: fixed
......@@ -112,18 +112,17 @@ module EE
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def security_products_usage
results = count(::Ci::Build.where(name: SECURE_PRODUCT_TYPES.keys).group(:name), fallback: Hash.new(-1), batch: false)
license_scan_count = results.delete("license_scanning")
if license_scan_count && results["license_management"]
results["license_management"] += license_scan_count
results = SECURE_PRODUCT_TYPES.each_with_object({}) do |(secure_type, attribs), response|
response[attribs[:name]] = count(::Ci::Build.where(name: secure_type), fallback: attribs.fetch(:fallback, -1)) # rubocop:disable CodeReuse/ActiveRecord
end
results.each_with_object({}) { |(key, value), response| response[SECURE_PRODUCT_TYPES[key.to_sym][:name]] = value }
# handle license rename https://gitlab.com/gitlab-org/gitlab/issues/8911
license_scan_count = results.delete(:license_scanning_jobs)
results[:license_management_jobs] += license_scan_count
results
end
# rubocop: enable CodeReuse/ActiveRecord
# Note: when adding a preference, check if it's mapped to an attribute of a User model. If so, name
# the base key part after a corresponding User model attribute, use its possible values as suffix values.
......
......@@ -123,6 +123,12 @@ describe Gitlab::UsageData do
expect(count_data[:sast_jobs]).to eq(1)
end
it 'correctly shows failure for combined license management' do
allow(Gitlab::Database::BatchCount).to receive(:batch_count).and_raise(ActiveRecord::StatementInvalid)
expect(count_data[:license_management_jobs]).to eq(-1)
end
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
......
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