Commit b5570288 authored by Stan Hu's avatar Stan Hu

Hide license breakdown in /admin if user count is high

On GitLab.com, we observed statement timeouts counting the number of
active users minus guests:
https://gitlab.com/gitlab-org/gitlab/issues/32287.

To work around this problem, hide the license breakdown if the estimate
number of users exceeds 100,000.
parent 627691b0
......@@ -2,6 +2,7 @@
class Admin::DashboardController < Admin::ApplicationController
include CountHelper
helper_method :show_license_breakdown?
COUNTED_ITEMS = [Project, User, Group].freeze
......@@ -13,6 +14,10 @@ class Admin::DashboardController < Admin::ApplicationController
@groups = Group.order_id_desc.with_route.limit(10)
end
# rubocop: enable CodeReuse/ActiveRecord
def show_license_breakdown?
false
end
end
Admin::DashboardController.prepend_if_ee('EE::Admin::DashboardController')
- breadcrumb_title "Dashboard"
= render_if_exists 'admin/licenses/breakdown', license: @license
- if show_license_breakdown?
= render_if_exists 'admin/licenses/breakdown', license: @license
.admin-dashboard.prepend-top-default
.row
......
---
title: Hide license breakdown in /admin if user count is high
merge_request: 18825
author:
type: performance
......@@ -7,6 +7,8 @@ module EE
extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
LICENSE_BREAKDOWN_USER_LIMIT = 100_000
override :index
def index
super
......@@ -18,6 +20,16 @@ module EE
@admin_count = ::User.admins.count
@roles_count = ::ProjectAuthorization.roles_stats
end
# The license section may time out if the number of users is
# high. To avoid 500 errors, just hide this section. This is a
# workaround for https://gitlab.com/gitlab-org/gitlab/issues/32287.
override :show_license_breakdown?
def show_license_breakdown?
return false unless @counts.is_a?(Hash)
@counts.fetch(::User, 0) < LICENSE_BREAKDOWN_USER_LIMIT
end
end
end
end
......@@ -4,6 +4,8 @@ require 'spec_helper'
describe Admin::DashboardController do
describe '#index' do
render_views
it "allows an admin user to access the page" do
sign_in(create(:user, :admin))
......@@ -27,5 +29,31 @@ describe Admin::DashboardController do
expect(response).to have_gitlab_http_status(404)
end
it 'shows the license breakdown' do
sign_in(create(:user, :admin))
get :index
expect(response.body).to include('Users in License')
end
context 'when the user count is high' do
let(:counts) do
described_class::COUNTED_ITEMS.each_with_object({}) { |model, hash| hash[model] = described_class::LICENSE_BREAKDOWN_USER_LIMIT + 1 }
end
before do
expect(Gitlab::Database::Count).to receive(:approximate_counts).and_return(counts)
sign_in(create(:admin))
end
it 'hides the license breakdown' do
get :index
expect(response.body).not_to include('Users in License')
end
end
end
end
......@@ -17,6 +17,7 @@ describe 'admin/dashboard/index.html.haml' do
allow(view).to receive(:admin?).and_return(true)
allow(view).to receive(:current_application_settings).and_return(Gitlab::CurrentSettings.current_application_settings)
allow(view).to receive(:show_license_breakdown?).and_return(false)
end
it "shows version of GitLab Workhorse" 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