Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
270ed1e3
Commit
270ed1e3
authored
Mar 13, 2020
by
Peter Leitzen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add structured logging for sidekiq workers
parent
a001ed04
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
1 deletion
+51
-1
app/workers/concerns/application_worker.rb
app/workers/concerns/application_worker.rb
+11
-0
spec/workers/concerns/application_worker_spec.rb
spec/workers/concerns/application_worker_spec.rb
+40
-1
No files found.
app/workers/concerns/application_worker.rb
View file @
270ed1e3
...
@@ -13,6 +13,17 @@ module ApplicationWorker
...
@@ -13,6 +13,17 @@ module ApplicationWorker
included
do
included
do
set_queue
set_queue
def
structured_payload
(
payload
=
{})
context
=
Labkit
::
Context
.
current
.
to_h
.
merge
(
'class'
=>
self
.
class
,
'job_status'
=>
'running'
,
'queue'
=>
self
.
class
.
queue
,
'jid'
=>
jid
)
payload
.
stringify_keys
.
merge
(
context
)
end
end
end
class_methods
do
class_methods
do
...
...
spec/workers/concerns/application_worker_spec.rb
View file @
270ed1e3
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
require
'spec_helper'
require
'spec_helper'
describe
ApplicationWorker
do
describe
ApplicationWorker
do
let
(
:worker
)
do
let
_it_be
(
:worker
)
do
Class
.
new
do
Class
.
new
do
def
self
.
name
def
self
.
name
'Gitlab::Foo::Bar::DummyWorker'
'Gitlab::Foo::Bar::DummyWorker'
...
@@ -13,12 +13,51 @@ describe ApplicationWorker do
...
@@ -13,12 +13,51 @@ describe ApplicationWorker do
end
end
end
end
let
(
:instance
)
{
worker
.
new
}
describe
'Sidekiq options'
do
describe
'Sidekiq options'
do
it
'sets the queue name based on the class name'
do
it
'sets the queue name based on the class name'
do
expect
(
worker
.
sidekiq_options
[
'queue'
]).
to
eq
(
'foo_bar_dummy'
)
expect
(
worker
.
sidekiq_options
[
'queue'
]).
to
eq
(
'foo_bar_dummy'
)
end
end
end
end
describe
'#structured_payload'
do
let
(
:payload
)
{
{}
}
subject
(
:result
)
{
instance
.
structured_payload
(
payload
)
}
it
'adds worker related payload'
do
instance
.
jid
=
'a jid'
expect
(
result
).
to
include
(
'class'
=>
worker
.
class
,
'job_status'
=>
'running'
,
'queue'
=>
worker
.
queue
,
'jid'
=>
instance
.
jid
)
end
it
'adds labkit context'
do
user
=
build_stubbed
(
:user
,
username:
'jane-doe'
)
instance
.
with_context
(
user:
user
)
do
expect
(
result
).
to
include
(
'meta.user'
=>
user
.
username
)
end
end
it
'adds custom payload converting stringified keys'
do
payload
[
:message
]
=
'some message'
expect
(
result
).
to
include
(
'message'
=>
payload
[
:message
])
end
it
'does not override predefined context keys with custom payload'
do
payload
[
'class'
]
=
'custom value'
expect
(
result
).
to
include
(
'class'
=>
worker
.
class
)
end
end
describe
'.queue_namespace'
do
describe
'.queue_namespace'
do
it
'sets the queue name based on the class name'
do
it
'sets the queue name based on the class name'
do
worker
.
queue_namespace
:some_namespace
worker
.
queue_namespace
:some_namespace
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment