diff options
author | Rémy Coutable <remy@rymai.me> | 2016-09-09 09:53:24 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-09-09 09:53:24 +0000 |
commit | cf76776d03885c02b58df07dbca42bc455f4a841 (patch) | |
tree | 9a69192ea7604268c596cafd7b4f8e93608483d7 | |
parent | 796bdf1dcb86b5e77fc054208afc632f75518605 (diff) | |
parent | 76c7b83dd5e345583fbaa26d9462a1bec7107a60 (diff) | |
download | gitlab-ce-cf76776d03885c02b58df07dbca42bc455f4a841.tar.gz |
Merge branch 'sidekiq-ps-parsing' into 'master'
* Moves splitting of `ps` result to helper.
* Users a regexp to extract the different parts
The result of `ps` at least depends on the _LANG_ and the distance of
_start_ to _now_ (start time then the day + hour then month+day)
I've tested with _LANG=en_US.UTF-8_ and _LANG=de_CH.UTF-8_
Closes #20632
See merge request !6245
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/helpers/sidekiq_helper.rb | 19 | ||||
-rw-r--r-- | app/views/admin/background_jobs/show.html.haml | 8 | ||||
-rw-r--r-- | spec/helpers/sidekiq_helper_spec.rb | 40 |
4 files changed, 62 insertions, 6 deletions
diff --git a/CHANGELOG b/CHANGELOG index 21a2661515d..4d1bb29a0b2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -20,6 +20,7 @@ v 8.12.0 (unreleased) - Change merge_error column from string to text type - Reduce contributions calendar data payload (ClemMakesApps) - Add `web_url` field to issue, merge request, and snippet API objects (Ben Boeckel) + - Move parsing of sidekiq ps into helper !6245 (pascalbetz) - Expose `sha` and `merge_commit_sha` in merge request API (Ben Boeckel) - Set path for all JavaScript cookies to honor GitLab's subdirectory setting !5627 (Mike Greiling) - Fix blame table layout width diff --git a/app/helpers/sidekiq_helper.rb b/app/helpers/sidekiq_helper.rb new file mode 100644 index 00000000000..d440edc55ba --- /dev/null +++ b/app/helpers/sidekiq_helper.rb @@ -0,0 +1,19 @@ +module SidekiqHelper + SIDEKIQ_PS_REGEXP = /\A + (?<pid>\d+)\s+ + (?<cpu>[\d\.,]+)\s+ + (?<mem>[\d\.,]+)\s+ + (?<state>[DRSTWXZNLsl\+<]+)\s+ + (?<start>.+)\s+ + (?<command>sidekiq.*\])\s+ + \z/x + + def parse_sidekiq_ps(line) + match = line.match(SIDEKIQ_PS_REGEXP) + if match + match[1..6] + else + %w[? ? ? ? ? ?] + end + end +end diff --git a/app/views/admin/background_jobs/show.html.haml b/app/views/admin/background_jobs/show.html.haml index 4f680b507c4..05855db963a 100644 --- a/app/views/admin/background_jobs/show.html.haml +++ b/app/views/admin/background_jobs/show.html.haml @@ -28,14 +28,10 @@ %th COMMAND %tbody - @sidekiq_processes.each do |process| - - next unless process.match(/(sidekiq \d+\.\d+\.\d+.+$)/) - - data = process.strip.split(' ') %tr %td= gitlab_config.user - - 5.times do - %td= data.shift - %td= data.join(' ') - + - parse_sidekiq_ps(process).each do |value| + %td= value .clearfix %p %i.fa.fa-exclamation-circle diff --git a/spec/helpers/sidekiq_helper_spec.rb b/spec/helpers/sidekiq_helper_spec.rb new file mode 100644 index 00000000000..d60839b78ec --- /dev/null +++ b/spec/helpers/sidekiq_helper_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe SidekiqHelper do + describe 'parse_sidekiq_ps' do + it 'parses line with time' do + line = '55137 10,0 2,1 S+ 2:30pm sidekiq 4.1.4 gitlab [0 of 25 busy] ' + parts = helper.parse_sidekiq_ps(line) + + expect(parts).to eq(['55137', '10,0', '2,1', 'S+', '2:30pm', 'sidekiq 4.1.4 gitlab [0 of 25 busy]']) + end + + it 'parses line with date' do + line = '55137 10,0 2,1 S+ Aug 4 sidekiq 4.1.4 gitlab [0 of 25 busy] ' + parts = helper.parse_sidekiq_ps(line) + + expect(parts).to eq(['55137', '10,0', '2,1', 'S+', 'Aug 4', 'sidekiq 4.1.4 gitlab [0 of 25 busy]']) + end + + it 'parses line with two digit date' do + line = '55137 10,0 2,1 S+ Aug 04 sidekiq 4.1.4 gitlab [0 of 25 busy] ' + parts = helper.parse_sidekiq_ps(line) + + expect(parts).to eq(['55137', '10,0', '2,1', 'S+', 'Aug 04', 'sidekiq 4.1.4 gitlab [0 of 25 busy]']) + end + + it 'parses line with dot as float separator' do + line = '55137 10.0 2.1 S+ 2:30pm sidekiq 4.1.4 gitlab [0 of 25 busy] ' + parts = helper.parse_sidekiq_ps(line) + + expect(parts).to eq(['55137', '10.0', '2.1', 'S+', '2:30pm', 'sidekiq 4.1.4 gitlab [0 of 25 busy]']) + end + + it 'does fail gracefully on line not matching the format' do + line = '55137 10.0 2.1 S+ 2:30pm something' + parts = helper.parse_sidekiq_ps(line) + + expect(parts).to eq(['?', '?', '?', '?', '?', '?']) + end + end +end |