Commit cf76776d authored by Rémy Coutable's avatar Rémy Coutable

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
parents 796bdf1d 76c7b83d
...@@ -20,6 +20,7 @@ v 8.12.0 (unreleased) ...@@ -20,6 +20,7 @@ v 8.12.0 (unreleased)
- Change merge_error column from string to text type - Change merge_error column from string to text type
- Reduce contributions calendar data payload (ClemMakesApps) - Reduce contributions calendar data payload (ClemMakesApps)
- Add `web_url` field to issue, merge request, and snippet API objects (Ben Boeckel) - 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) - 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) - Set path for all JavaScript cookies to honor GitLab's subdirectory setting !5627 (Mike Greiling)
- Fix blame table layout width - Fix blame table layout width
......
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
...@@ -28,14 +28,10 @@ ...@@ -28,14 +28,10 @@
%th COMMAND %th COMMAND
%tbody %tbody
- @sidekiq_processes.each do |process| - @sidekiq_processes.each do |process|
- next unless process.match(/(sidekiq \d+\.\d+\.\d+.+$)/)
- data = process.strip.split(' ')
%tr %tr
%td= gitlab_config.user %td= gitlab_config.user
- 5.times do - parse_sidekiq_ps(process).each do |value|
%td= data.shift %td= value
%td= data.join(' ')
.clearfix .clearfix
%p %p
%i.fa.fa-exclamation-circle %i.fa.fa-exclamation-circle
......
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
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