Commit 085e1f89 authored by Sean McGivern's avatar Sean McGivern

Handle unavailable system info

For Linux with the grsecurity patches applied, paths in `/proc` may not
be readable, so handle those cases and show a message rather than
blowing up.
parent b2bf01f4
...@@ -10,6 +10,9 @@ v 8.12.0 (unreleased) ...@@ -10,6 +10,9 @@ v 8.12.0 (unreleased)
- Added tests for diff notes - Added tests for diff notes
- Added 'only_allow_merge_if_build_succeeds' project setting in the API. !5930 (Duck) - Added 'only_allow_merge_if_build_succeeds' project setting in the API. !5930 (Duck)
v 8.11.3 (unreleased)
- Allow system info page to handle case where info is unavailable
v 8.11.2 (unreleased) v 8.11.2 (unreleased)
- Show "Create Merge Request" widget for push events to fork projects on the source project - Show "Create Merge Request" widget for push events to fork projects on the source project
......
...@@ -29,7 +29,8 @@ class Admin::SystemInfoController < Admin::ApplicationController ...@@ -29,7 +29,8 @@ class Admin::SystemInfoController < Admin::ApplicationController
] ]
def show def show
system_info = Vmstat.snapshot @cpus = Vmstat.cpu rescue nil
@memory = Vmstat.memory rescue nil
mounts = Sys::Filesystem.mounts mounts = Sys::Filesystem.mounts
@disks = [] @disks = []
...@@ -50,10 +51,5 @@ class Admin::SystemInfoController < Admin::ApplicationController ...@@ -50,10 +51,5 @@ class Admin::SystemInfoController < Admin::ApplicationController
rescue Sys::Filesystem::Error rescue Sys::Filesystem::Error
end end
end end
@cpus = system_info.cpus.length
@mem_used = system_info.memory.active_bytes
@mem_total = system_info.memory.total_bytes
end end
end end
...@@ -9,12 +9,20 @@ ...@@ -9,12 +9,20 @@
.light-well .light-well
%h4 CPU %h4 CPU
.data .data
%h1= "#{@cpus} cores" - if @cpus
%h1= "#{@cpus.length} cores"
- else
%i.fa.fa-warning.text-warning
Unable to collect CPU info
.col-sm-4 .col-sm-4
.light-well .light-well
%h4 Memory %h4 Memory
.data .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
%i.fa.fa-warning.text-warning
Unable to collect memory info
.col-sm-4 .col-sm-4
.light-well .light-well
%h4 Disks %h4 Disks
......
...@@ -6,12 +6,49 @@ describe 'Admin System Info' do ...@@ -6,12 +6,49 @@ describe 'Admin System Info' do
end end
describe 'GET /admin/system_info' do describe 'GET /admin/system_info' do
it 'shows system info page' do let(:cpu) { double(:cpu, length: 2) }
visit admin_system_info_path let(:memory) { double(:memory, active_bytes: 4294967296, total_bytes: 17179869184) }
expect(page).to have_content 'CPU' context 'when all info is available' do
expect(page).to have_content 'Memory' before do
expect(page).to have_content 'Disks' 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 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