Commit 25f058c9 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '8317-operations-dashboard-usage-ping' into 'master'

Resolve "Add Operations Dashboard usage to Usage Ping"

Closes #8317

See merge request gitlab-org/gitlab-ee!9291
parents c06d5a9d 056020b0
......@@ -276,6 +276,7 @@ class User < ApplicationRecord
scope :by_username, -> (usernames) { iwhere(username: Array(usernames).map(&:to_s)) }
scope :for_todos, -> (todos) { where(id: todos.select(:user_id)) }
scope :with_emails, -> { preload(:emails) }
scope :with_dashboard, -> (dashboard) { where(dashboard: dashboard) }
# Limits the users to those that have TODOs, optionally in the given state.
#
......
......@@ -7,4 +7,8 @@ class UsersOpsDashboardProject < ApplicationRecord
validates :user, presence: true
validates :user_id, uniqueness: { scope: [:project_id] }
validates :project, presence: true
def self.distinct_users(users)
select('distinct user_id').joins(:user).merge(users)
end
end
---
title: Add operations dashboard usage counts to usage data
merge_request: 9291
author:
type: added
......@@ -105,6 +105,16 @@ module EE
end
end
def operations_dashboard_usage
users_with_ops_dashboard_as_default = count(::User.active.with_dashboard('operations'))
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
}
end
override :system_usage_data
def system_usage_data
usage_data = super
......@@ -121,7 +131,8 @@ module EE
projects_with_prometheus_alerts: count(PrometheusAlert.distinct_projects),
projects_with_packages: count(::Packages::Package.select('distinct project_id')),
projects_with_tracing_enabled: count(ProjectTracingSetting),
projects_enforcing_code_owner_approval: count(::Project.without_deleted.non_archived.requiring_code_owner_approval)
projects_enforcing_code_owner_approval: count(::Project.without_deleted.non_archived.requiring_code_owner_approval),
operations_dashboard: operations_dashboard_usage
}).merge(service_desk_counts).merge(security_products_usage)
# MySql does not support recursive queries so we can't retrieve epics relationship depth
......
# frozen_string_literal: true
FactoryBot.define do
factory :users_ops_dashboard_project, class: UsersOpsDashboardProject do
user factory: :user
project factory: :project
end
end
......@@ -81,6 +81,7 @@ describe Gitlab::UsageData do
projects_jira_dvcs_cloud_active
projects_jira_dvcs_server_active
feature_flags
operations_dashboard
))
expect(count_data[:projects_with_prometheus_alerts]).to eq(2)
......@@ -205,4 +206,30 @@ describe Gitlab::UsageData do
expect(described_class.system_usage_data[:counts][:projects_enforcing_code_owner_approval]).to eq(1)
end
end
describe '#operations_dashboard_usage' do
subject { described_class.operations_dashboard_usage }
before do
blocked_user = create(:user, :blocked, dashboard: 'operations')
user_with_ops_dashboard = create(:user, dashboard: 'operations')
create(:users_ops_dashboard_project, user: blocked_user)
create(:users_ops_dashboard_project, user: user_with_ops_dashboard)
create(:users_ops_dashboard_project, user: user_with_ops_dashboard)
create(:users_ops_dashboard_project)
end
it 'gathers data on operations dashboard' do
expect(subject.keys).to include(*%i(
default_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)
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