Commit c73b6a1c authored by Stan Hu's avatar Stan Hu

Merge branch 'aiionx/gitlab-shell-aiionx-post_receive_jid' into 'master'

Update post receive worker so it logs a unique JID in sidekiq

Taken from !50.

Instead of

```
2016-04-14T03:07:32.373Z 5285 TID-osycgmlyo PostReceive JID- INFO: start
2016-04-14T03:07:32.374Z 5285 TID-osycgmlyo PostReceive JID- INFO: arguments: [...]
2016-04-14T03:07:32.534Z 5285 TID-osycgmlyo PostReceive JID- INFO: done: 0.161 sec
```

Have this log

```
2016-04-14T03:07:32.373Z 5285 TID-osycgmlyo PostReceive JID-54b0b2f6616cae37e3e87f8a INFO: start
2016-04-14T03:07:32.374Z 5285 TID-osycgmlyo PostReceive JID-54b0b2f6616cae37e3e87f8a INFO: arguments: [...]
2016-04-14T03:07:32.534Z 5285 TID-osycgmlyo PostReceive JID-54b0b2f6616cae37e3e87f8a INFO: done: 0.161 sec
```


This way sidekiq can Log a unique JID in the sidekiq.log for PostReceive.
So when parsing the logs (with logstash for example) you know it belongs to that unique job.

This puts the logs in a uniform manner like the other workers that are pushed to redis (which do have a JID)
For example the ProjectWebHookWorker

```
2016-04-14T03:13:07.917Z 5285 TID-osycsh7z0 ProjectWebHookWorker JID-800085fb3cf7241fdeecc6ec INFO: start
2016-04-14T03:13:07.918Z 5285 TID-osycsh7z0 ProjectWebHookWorker JID-800085fb3cf7241fdeecc6ec INFO: arguments: [...]
2016-04-14T03:13:12.500Z 5285 TID-osycsh7z0 ProjectWebHookWorker JID-800085fb3cf7241fdeecc6ec INFO: done: 4.583 sec
```


See merge request !55
parents 4a8db75d 750fd3f8
...@@ -2,6 +2,10 @@ v3.0.0 ...@@ -2,6 +2,10 @@ v3.0.0
- Remove list-remote-tags command (Robert Schilling) - Remove list-remote-tags command (Robert Schilling)
- Remove rm-tag command (Robert Schilling) - Remove rm-tag command (Robert Schilling)
- Remove create-branch and rm-branch commands (Robert Schilling) - Remove create-branch and rm-branch commands (Robert Schilling)
- Update PostReceive worker so it logs a unique JID in Sidekiq
v2.7.2
- Do not prune objects during 'git gc'
v2.7.1 v2.7.1
- Add new command to list tags from a remote repo - Add new command to list tags from a remote repo
......
...@@ -2,14 +2,16 @@ require_relative 'gitlab_init' ...@@ -2,14 +2,16 @@ require_relative 'gitlab_init'
require_relative 'gitlab_net' require_relative 'gitlab_net'
require 'json' require 'json'
require 'base64' require 'base64'
require 'securerandom'
class GitlabPostReceive class GitlabPostReceive
attr_reader :config, :repo_path, :changes attr_reader :config, :repo_path, :changes, :jid
def initialize(repo_path, actor, changes) def initialize(repo_path, actor, changes)
@config = GitlabConfig.new @config = GitlabConfig.new
@repo_path, @actor = repo_path.strip, actor @repo_path, @actor = repo_path.strip, actor
@changes = changes @changes = changes
@jid = SecureRandom.hex(12)
end end
def exec def exec
...@@ -71,7 +73,7 @@ class GitlabPostReceive ...@@ -71,7 +73,7 @@ class GitlabPostReceive
changes = Base64.encode64(@changes) changes = Base64.encode64(@changes)
queue = "#{config.redis_namespace}:queue:post_receive" queue = "#{config.redis_namespace}:queue:post_receive"
msg = JSON.dump({ 'class' => 'PostReceive', 'args' => [@repo_path, @actor, changes] }) msg = JSON.dump({ 'class' => 'PostReceive', 'args' => [@repo_path, @actor, changes], 'jid' => @jid })
if system(*config.redis_command, 'rpush', queue, msg, if system(*config.redis_command, 'rpush', queue, msg,
err: '/dev/null', out: '/dev/null') err: '/dev/null', out: '/dev/null')
return true return true
......
...@@ -50,7 +50,7 @@ describe GitlabPostReceive do ...@@ -50,7 +50,7 @@ describe GitlabPostReceive do
expect(gitlab_post_receive).to receive(:system).with( expect(gitlab_post_receive).to receive(:system).with(
*[ *[
*%w(env -i redis-cli rpush resque:gitlab:queue:post_receive), *%w(env -i redis-cli rpush resque:gitlab:queue:post_receive),
%Q/{"class":"PostReceive","args":["#{repo_path}","#{actor}",#{base64_changes.inspect}]}/, %Q/{"class":"PostReceive","args":["#{repo_path}","#{actor}",#{base64_changes.inspect}],"jid":"#{gitlab_post_receive.jid}"}/,
{ err: "/dev/null", out: "/dev/null" } { err: "/dev/null", out: "/dev/null" }
] ]
).and_return(true) ).and_return(true)
......
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