Commit 0f5efcfc authored by Doug Stull's avatar Doug Stull

Add distinct user count of secure stage items to usage ping

- needed for collecting how many distinct users have triggered
  these items.
parent a89d86f0
...@@ -5,6 +5,15 @@ module EE ...@@ -5,6 +5,15 @@ module EE
module UsageData module UsageData
extend ActiveSupport::Concern extend ActiveSupport::Concern
SECURE_PRODUCT_TYPES = {
container_scanning: :container_scanning_jobs,
dast: :dast_jobs,
dependency_scanning: :dependency_scanning_jobs,
license_management: :license_management_jobs,
license_scanning: :license_scanning_jobs,
sast: :sast_jobs
}.freeze
class_methods do class_methods do
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
...@@ -92,23 +101,14 @@ module EE ...@@ -92,23 +101,14 @@ module EE
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def security_products_usage def security_products_usage
types = { results = count(::Ci::Build.where(name: SECURE_PRODUCT_TYPES.keys).group(:name), fallback: Hash.new(-1), batch: false)
container_scanning: :container_scanning_jobs,
dast: :dast_jobs,
dependency_scanning: :dependency_scanning_jobs,
license_management: :license_management_jobs,
license_scanning: :license_scanning_jobs,
sast: :sast_jobs
}
results = count(::Ci::Build.where(name: types.keys).group(:name), fallback: Hash.new(-1), batch: false)
license_scan_count = results.delete("license_scanning") license_scan_count = results.delete("license_scanning")
if license_scan_count && results["license_management"] if license_scan_count && results["license_management"]
results["license_management"] += license_scan_count results["license_management"] += license_scan_count
end end
results.each_with_object({}) { |(key, value), response| response[types[key.to_sym]] = value } results.each_with_object({}) { |(key, value), response| response[SECURE_PRODUCT_TYPES[key.to_sym]] = value }
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
...@@ -314,9 +314,13 @@ module EE ...@@ -314,9 +314,13 @@ module EE
# container_scanning_jobs, dast_jobs, dependency_scanning_jobs, license_management_jobs, sast_jobs # container_scanning_jobs, dast_jobs, dependency_scanning_jobs, license_management_jobs, sast_jobs
# Once https://gitlab.com/gitlab-org/gitlab/merge_requests/17568 is merged, this might be doable # Once https://gitlab.com/gitlab-org/gitlab/merge_requests/17568 is merged, this might be doable
def usage_activity_by_stage_secure(time_period) def usage_activity_by_stage_secure(time_period)
{ results = {
user_preferences_group_overview_security_dashboard: count(::User.active.group_view_security_dashboard.where(time_period)) user_preferences_group_overview_security_dashboard: count(::User.active.group_view_security_dashboard.where(time_period))
} }
SECURE_PRODUCT_TYPES.each_with_object(results) do |(secure_type, type_with_name), response|
response["user_#{type_with_name}".to_sym] = distinct_count(::Ci::Build.where(name: secure_type).where(time_period), :user_id)
end
end end
end end
end end
......
...@@ -348,7 +348,13 @@ describe Gitlab::UsageData do ...@@ -348,7 +348,13 @@ describe Gitlab::UsageData do
create(:user, group_view: :security_dashboard) create(:user, group_view: :security_dashboard)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:secure]).to eq( expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:secure]).to eq(
user_preferences_group_overview_security_dashboard: 1 user_preferences_group_overview_security_dashboard: 1,
user_container_scanning_jobs: 0,
user_dast_jobs: 0,
user_dependency_scanning_jobs: 0,
user_license_management_jobs: 0,
user_license_scanning_jobs: 0,
user_sast_jobs: 0
) )
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