Merge branch '21378-error-500-after-8-11-update-on-system-infos-page' into 'master'
Handle unavailable system info ## What does this MR do? Handle the case where we can't get system info without blowing up. As this is the first tab in the monitoring section, it's difficult to get to the other tabs if this page throws a 500. Also be more specific about the info we want, so we don't fail on something we don't care about (like `/proc/net/dev`). ## Why was this MR needed? grsecurity can prevent users from reading `/proc`, which is what Vmstat uses to find CPU and memory info. ## What are the relevant issue numbers? Closes #21378. See merge request !5989
This commit is contained in:
commit
532489dc04
6 changed files with 60 additions and 16 deletions
|
@ -15,6 +15,9 @@ v 8.12.0 (unreleased)
|
|||
- Use the default branch for displaying the project icon instead of master !5792 (Hannes Rosenögger)
|
||||
- Adds response mime type to transaction metric action when it's not HTML
|
||||
|
||||
v 8.11.3 (unreleased)
|
||||
- Allow system info page to handle case where info is unavailable
|
||||
|
||||
v 8.11.2 (unreleased)
|
||||
- Show "Create Merge Request" widget for push events to fork projects on the source project
|
||||
|
||||
|
|
2
Gemfile
2
Gemfile
|
@ -349,5 +349,5 @@ gem 'paranoia', '~> 2.0'
|
|||
gem 'health_check', '~> 2.1.0'
|
||||
|
||||
# System information
|
||||
gem 'vmstat', '~> 2.1.1'
|
||||
gem 'vmstat', '~> 2.2'
|
||||
gem 'sys-filesystem', '~> 1.1.6'
|
||||
|
|
|
@ -772,7 +772,7 @@ GEM
|
|||
coercible (~> 1.0)
|
||||
descendants_tracker (~> 0.0, >= 0.0.3)
|
||||
equalizer (~> 0.0, >= 0.0.9)
|
||||
vmstat (2.1.1)
|
||||
vmstat (2.2.0)
|
||||
warden (1.2.6)
|
||||
rack (>= 1.0)
|
||||
web-console (2.3.0)
|
||||
|
@ -980,7 +980,7 @@ DEPENDENCIES
|
|||
unicorn-worker-killer (~> 0.4.2)
|
||||
version_sorter (~> 2.1.0)
|
||||
virtus (~> 1.0.1)
|
||||
vmstat (~> 2.1.1)
|
||||
vmstat (~> 2.2)
|
||||
web-console (~> 2.0)
|
||||
webmock (~> 1.21.0)
|
||||
wikicloth (= 0.8.1)
|
||||
|
|
|
@ -29,7 +29,8 @@ class Admin::SystemInfoController < Admin::ApplicationController
|
|||
]
|
||||
|
||||
def show
|
||||
system_info = Vmstat.snapshot
|
||||
@cpus = Vmstat.cpu rescue nil
|
||||
@memory = Vmstat.memory rescue nil
|
||||
mounts = Sys::Filesystem.mounts
|
||||
|
||||
@disks = []
|
||||
|
@ -50,10 +51,5 @@ class Admin::SystemInfoController < Admin::ApplicationController
|
|||
rescue Sys::Filesystem::Error
|
||||
end
|
||||
end
|
||||
|
||||
@cpus = system_info.cpus.length
|
||||
|
||||
@mem_used = system_info.memory.active_bytes
|
||||
@mem_total = system_info.memory.total_bytes
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,12 +9,20 @@
|
|||
.light-well
|
||||
%h4 CPU
|
||||
.data
|
||||
%h1= "#{@cpus} cores"
|
||||
- if @cpus
|
||||
%h1= "#{@cpus.length} cores"
|
||||
- else
|
||||
= icon('warning', class: 'text-warning')
|
||||
Unable to collect CPU info
|
||||
.col-sm-4
|
||||
.light-well
|
||||
%h4 Memory
|
||||
.data
|
||||
%h1= "#{number_to_human_size(@mem_used)} / #{number_to_human_size(@mem_total)}"
|
||||
- if @memory
|
||||
%h1= "#{number_to_human_size(@memory.active_bytes)} / #{number_to_human_size(@memory.total_bytes)}"
|
||||
- else
|
||||
= icon('warning', class: 'text-warning')
|
||||
Unable to collect memory info
|
||||
.col-sm-4
|
||||
.light-well
|
||||
%h4 Disks
|
||||
|
|
|
@ -6,12 +6,49 @@ describe 'Admin System Info' do
|
|||
end
|
||||
|
||||
describe 'GET /admin/system_info' do
|
||||
it 'shows system info page' do
|
||||
visit admin_system_info_path
|
||||
let(:cpu) { double(:cpu, length: 2) }
|
||||
let(:memory) { double(:memory, active_bytes: 4294967296, total_bytes: 17179869184) }
|
||||
|
||||
expect(page).to have_content 'CPU'
|
||||
expect(page).to have_content 'Memory'
|
||||
expect(page).to have_content 'Disks'
|
||||
context 'when all info is available' do
|
||||
before do
|
||||
allow(Vmstat).to receive(:cpu).and_return(cpu)
|
||||
allow(Vmstat).to receive(:memory).and_return(memory)
|
||||
visit admin_system_info_path
|
||||
end
|
||||
|
||||
it 'shows system info page' do
|
||||
expect(page).to have_content 'CPU 2 cores'
|
||||
expect(page).to have_content 'Memory 4 GB / 16 GB'
|
||||
expect(page).to have_content 'Disks'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when CPU info is not available' do
|
||||
before do
|
||||
allow(Vmstat).to receive(:cpu).and_raise(Errno::ENOENT)
|
||||
allow(Vmstat).to receive(:memory).and_return(memory)
|
||||
visit admin_system_info_path
|
||||
end
|
||||
|
||||
it 'shows system info page with no CPU info' do
|
||||
expect(page).to have_content 'CPU Unable to collect CPU info'
|
||||
expect(page).to have_content 'Memory 4 GB / 16 GB'
|
||||
expect(page).to have_content 'Disks'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when memory info is not available' do
|
||||
before do
|
||||
allow(Vmstat).to receive(:cpu).and_return(cpu)
|
||||
allow(Vmstat).to receive(:memory).and_raise(Errno::ENOENT)
|
||||
visit admin_system_info_path
|
||||
end
|
||||
|
||||
it 'shows system info page with no CPU info' do
|
||||
expect(page).to have_content 'CPU 2 cores'
|
||||
expect(page).to have_content 'Memory Unable to collect memory info'
|
||||
expect(page).to have_content 'Disks'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue