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
24c80189
Commit
24c80189
authored
Mar 10, 2021
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Merge branch 'refactor-labkit-context-to-gitlab-application-context' into 'master'"
This reverts merge request !56003
parent
db33a339
Changes
24
Show whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
43 additions
and
56 deletions
+43
-56
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+1
-1
app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb
app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb
+1
-1
app/workers/concerns/application_worker.rb
app/workers/concerns/application_worker.rb
+1
-1
app/workers/concerns/cronjob_queue.rb
app/workers/concerns/cronjob_queue.rb
+1
-1
ee/app/services/elastic/indexing_control_service.rb
ee/app/services/elastic/indexing_control_service.rb
+2
-2
ee/app/workers/concerns/elastic/indexing_control.rb
ee/app/workers/concerns/elastic/indexing_control.rb
+1
-1
ee/spec/services/elastic/indexing_control_service_spec.rb
ee/spec/services/elastic/indexing_control_service_spec.rb
+2
-2
ee/spec/workers/concerns/elastic/indexing_control_spec.rb
ee/spec/workers/concerns/elastic/indexing_control_spec.rb
+1
-1
ee/spec/workers/update_all_mirrors_worker_spec.rb
ee/spec/workers/update_all_mirrors_worker_spec.rb
+2
-2
lib/api/admin/sidekiq.rb
lib/api/admin/sidekiq.rb
+2
-2
lib/gitlab/application_context.rb
lib/gitlab/application_context.rb
+0
-7
lib/gitlab/gitaly_client.rb
lib/gitlab/gitaly_client.rb
+1
-1
lib/gitlab/grape_logging/loggers/context_logger.rb
lib/gitlab/grape_logging/loggers/context_logger.rb
+1
-1
lib/gitlab/sidekiq_queue.rb
lib/gitlab/sidekiq_queue.rb
+1
-1
spec/controllers/application_controller_spec.rb
spec/controllers/application_controller_spec.rb
+1
-1
spec/controllers/sessions_controller_spec.rb
spec/controllers/sessions_controller_spec.rb
+5
-5
spec/lib/gitlab/application_context_spec.rb
spec/lib/gitlab/application_context_spec.rb
+1
-15
spec/lib/gitlab/sidekiq_middleware/worker_context/server_spec.rb
...b/gitlab/sidekiq_middleware/worker_context/server_spec.rb
+1
-1
spec/requests/api/api_spec.rb
spec/requests/api/api_spec.rb
+2
-2
spec/spec_helper.rb
spec/spec_helper.rb
+2
-2
spec/support/shared_examples/lib/api/ci/runner_shared_examples.rb
...port/shared_examples/lib/api/ci/runner_shared_examples.rb
+2
-2
spec/support/shared_examples/requests/api/logging_application_context_shared_examples.rb
...quests/api/logging_application_context_shared_examples.rb
+10
-2
spec/workers/background_migration_worker_spec.rb
spec/workers/background_migration_worker_spec.rb
+1
-1
spec/workers/concerns/worker_context_spec.rb
spec/workers/concerns/worker_context_spec.rb
+1
-1
No files found.
app/controllers/application_controller.rb
View file @
24c80189
...
@@ -463,7 +463,7 @@ class ApplicationController < ActionController::Base
...
@@ -463,7 +463,7 @@ class ApplicationController < ActionController::Base
feature_category:
feature_category
)
do
feature_category:
feature_category
)
do
yield
yield
ensure
ensure
@current_context
=
Gitlab
::
ApplicationContext
.
current
@current_context
=
Labkit
::
Context
.
current
.
to_h
end
end
end
end
...
...
app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb
View file @
24c80189
...
@@ -8,7 +8,7 @@ module Mutations
...
@@ -8,7 +8,7 @@ module Mutations
ADMIN_MESSAGE
=
'You must be an admin to use this mutation'
ADMIN_MESSAGE
=
'You must be an admin to use this mutation'
Gitlab
::
Application
Context
::
KNOWN_KEYS
.
each
do
|
key
|
Labkit
::
Context
::
KNOWN_KEYS
.
each
do
|
key
|
argument
key
,
argument
key
,
GraphQL
::
STRING_TYPE
,
GraphQL
::
STRING_TYPE
,
required:
false
,
required:
false
,
...
...
app/workers/concerns/application_worker.rb
View file @
24c80189
...
@@ -18,7 +18,7 @@ module ApplicationWorker
...
@@ -18,7 +18,7 @@ module ApplicationWorker
set_queue
set_queue
def
structured_payload
(
payload
=
{})
def
structured_payload
(
payload
=
{})
context
=
Gitlab
::
ApplicationContext
.
current
.
merge
(
context
=
Labkit
::
Context
.
current
.
to_h
.
merge
(
'class'
=>
self
.
class
.
name
,
'class'
=>
self
.
class
.
name
,
'job_status'
=>
'running'
,
'job_status'
=>
'running'
,
'queue'
=>
self
.
class
.
queue
,
'queue'
=>
self
.
class
.
queue
,
...
...
app/workers/concerns/cronjob_queue.rb
View file @
24c80189
...
@@ -15,7 +15,7 @@ module CronjobQueue
...
@@ -15,7 +15,7 @@ module CronjobQueue
# Cronjobs never get scheduled with arguments, so this is safe to
# Cronjobs never get scheduled with arguments, so this is safe to
# override
# override
def
context_for_arguments
(
_args
)
def
context_for_arguments
(
_args
)
return
if
Gitlab
::
ApplicationContext
.
current_context_include?
(
:caller_id
)
return
if
Gitlab
::
ApplicationContext
.
current_context_include?
(
'meta.caller_id'
)
Gitlab
::
ApplicationContext
.
new
(
caller_id:
"Cronjob"
)
Gitlab
::
ApplicationContext
.
new
(
caller_id:
"Cronjob"
)
end
end
...
...
ee/app/services/elastic/indexing_control_service.rb
View file @
24c80189
...
@@ -6,7 +6,7 @@ module Elastic
...
@@ -6,7 +6,7 @@ module Elastic
# This class should only be used with sidekiq workers which extend Elastic::IndexingControl module
# This class should only be used with sidekiq workers which extend Elastic::IndexingControl module
class
IndexingControlService
class
IndexingControlService
LIMIT
=
1000
LIMIT
=
1000
PROJECT_CONTEXT_KEY
=
"
#{
Gitlab
::
Application
Context
::
LOG_KEY
}
.project"
PROJECT_CONTEXT_KEY
=
"
#{
Labkit
::
Context
::
LOG_KEY
}
.project"
def
initialize
(
klass
)
def
initialize
(
klass
)
raise
ArgumentError
,
"passed class must extend Elastic::IndexingControl"
unless
klass
.
include?
(
Elastic
::
IndexingControl
)
raise
ArgumentError
,
"passed class must extend Elastic::IndexingControl"
unless
klass
.
include?
(
Elastic
::
IndexingControl
)
...
@@ -93,7 +93,7 @@ module Elastic
...
@@ -93,7 +93,7 @@ module Elastic
end
end
def
send_to_processing_queue
(
job
)
def
send_to_processing_queue
(
job
)
Gitlab
::
ApplicationContext
.
with_raw
_context
(
job
[
'context'
])
do
Labkit
::
Context
.
with
_context
(
job
[
'context'
])
do
klass
.
perform_async
(
*
job
[
'args'
])
klass
.
perform_async
(
*
job
[
'args'
])
end
end
end
end
...
...
ee/app/workers/concerns/elastic/indexing_control.rb
View file @
24c80189
...
@@ -51,7 +51,7 @@ module Elastic
...
@@ -51,7 +51,7 @@ module Elastic
end
end
def
current_context
def
current_context
Gitlab
::
ApplicationContext
.
current
Labkit
::
Context
.
current
.
to_h
end
end
end
end
end
end
ee/spec/services/elastic/indexing_control_service_spec.rb
View file @
24c80189
...
@@ -20,7 +20,7 @@ RSpec.describe Elastic::IndexingControlService, :clean_gitlab_redis_shared_state
...
@@ -20,7 +20,7 @@ RSpec.describe Elastic::IndexingControlService, :clean_gitlab_redis_shared_state
end
end
let
(
:stored_context
)
do
let
(
:stored_context
)
do
{
"
#{
Gitlab
::
Application
Context
::
LOG_KEY
}
.project"
=>
'gitlab-org/gitlab'
}
{
"
#{
Labkit
::
Context
::
LOG_KEY
}
.project"
=>
'gitlab-org/gitlab'
}
end
end
let
(
:worker_args
)
{
[
1
,
2
]
}
let
(
:worker_args
)
{
[
1
,
2
]
}
...
@@ -133,7 +133,7 @@ RSpec.describe Elastic::IndexingControlService, :clean_gitlab_redis_shared_state
...
@@ -133,7 +133,7 @@ RSpec.describe Elastic::IndexingControlService, :clean_gitlab_redis_shared_state
subject
.
add_to_waiting_queue!
(
j
,
worker_context
)
subject
.
add_to_waiting_queue!
(
j
,
worker_context
)
end
end
expect
(
Gitlab
::
ApplicationContext
).
to
receive
(
:with_raw
_context
).
with
(
stored_context
).
exactly
(
jobs
.
count
).
times
.
and_call_original
expect
(
Labkit
::
Context
).
to
receive
(
:with
_context
).
with
(
stored_context
).
exactly
(
jobs
.
count
).
times
.
and_call_original
expect
(
worker_class
).
to
receive
(
:perform_async
).
exactly
(
jobs
.
count
).
times
expect
(
worker_class
).
to
receive
(
:perform_async
).
exactly
(
jobs
.
count
).
times
expect
{
subject
.
resume_processing!
}.
to
change
{
subject
.
has_jobs_in_waiting_queue?
}.
from
(
true
).
to
(
false
)
expect
{
subject
.
resume_processing!
}.
to
change
{
subject
.
has_jobs_in_waiting_queue?
}.
from
(
true
).
to
(
false
)
...
...
ee/spec/workers/concerns/elastic/indexing_control_spec.rb
View file @
24c80189
...
@@ -75,7 +75,7 @@ RSpec.describe Elastic::IndexingControl do
...
@@ -75,7 +75,7 @@ RSpec.describe Elastic::IndexingControl do
expect_any_instance_of
(
Gitlab
::
Elastic
::
Indexer
).
not_to
receive
(
:run
)
expect_any_instance_of
(
Gitlab
::
Elastic
::
Indexer
).
not_to
receive
(
:run
)
expect
(
Elastic
::
IndexingControlService
).
to
receive
(
:add_to_waiting_queue!
).
with
(
worker
.
class
,
worker_args
,
worker_context
)
expect
(
Elastic
::
IndexingControlService
).
to
receive
(
:add_to_waiting_queue!
).
with
(
worker
.
class
,
worker_args
,
worker_context
)
Gitlab
::
ApplicationContext
.
with_raw
_context
(
worker_context
)
do
Labkit
::
Context
.
with
_context
(
worker_context
)
do
worker
.
perform
(
*
worker_args
)
worker
.
perform
(
*
worker_args
)
end
end
end
end
...
...
ee/spec/workers/update_all_mirrors_worker_spec.rb
View file @
24c80189
...
@@ -32,10 +32,10 @@ RSpec.describe UpdateAllMirrorsWorker do
...
@@ -32,10 +32,10 @@ RSpec.describe UpdateAllMirrorsWorker do
outer_context
=
nil
outer_context
=
nil
Gitlab
::
ApplicationContext
.
with_context
(
project:
build
(
:project
))
do
Gitlab
::
ApplicationContext
.
with_context
(
project:
build
(
:project
))
do
outer_context
=
Gitlab
::
ApplicationContext
.
current
outer_context
=
Labkit
::
Context
.
current
.
to_h
expect
(
worker
).
to
receive
(
:schedule_mirrors!
)
do
expect
(
worker
).
to
receive
(
:schedule_mirrors!
)
do
inner_context
=
Gitlab
::
ApplicationContext
.
current
inner_context
=
Labkit
::
Context
.
current
.
to_h
# `schedule_mirrors!` needs to return an integer.
# `schedule_mirrors!` needs to return an integer.
0
0
...
...
lib/api/admin/sidekiq.rb
View file @
24c80189
...
@@ -12,11 +12,11 @@ module API
...
@@ -12,11 +12,11 @@ module API
namespace
'queues'
do
namespace
'queues'
do
desc
'Drop jobs matching the given metadata from the Sidekiq queue'
desc
'Drop jobs matching the given metadata from the Sidekiq queue'
params
do
params
do
Gitlab
::
Application
Context
::
KNOWN_KEYS
.
each
do
|
key
|
Labkit
::
Context
::
KNOWN_KEYS
.
each
do
|
key
|
optional
key
,
type:
String
,
allow_blank:
false
optional
key
,
type:
String
,
allow_blank:
false
end
end
at_least_one_of
(
*
Gitlab
::
Application
Context
::
KNOWN_KEYS
)
at_least_one_of
(
*
Labkit
::
Context
::
KNOWN_KEYS
)
end
end
delete
':queue_name'
do
delete
':queue_name'
do
result
=
result
=
...
...
lib/gitlab/application_context.rb
View file @
24c80189
...
@@ -7,9 +7,6 @@ module Gitlab
...
@@ -7,9 +7,6 @@ module Gitlab
Attribute
=
Struct
.
new
(
:name
,
:type
)
Attribute
=
Struct
.
new
(
:name
,
:type
)
LOG_KEY
=
Labkit
::
Context
::
LOG_KEY
KNOWN_KEYS
=
Labkit
::
Context
::
KNOWN_KEYS
APPLICATION_ATTRIBUTES
=
[
APPLICATION_ATTRIBUTES
=
[
Attribute
.
new
(
:project
,
Project
),
Attribute
.
new
(
:project
,
Project
),
Attribute
.
new
(
:namespace
,
Namespace
),
Attribute
.
new
(
:namespace
,
Namespace
),
...
@@ -25,10 +22,6 @@ module Gitlab
...
@@ -25,10 +22,6 @@ module Gitlab
application_context
.
use
(
&
block
)
application_context
.
use
(
&
block
)
end
end
def
self
.
with_raw_context
(
attributes
=
{},
&
block
)
Labkit
::
Context
.
with_context
(
attributes
,
&
block
)
end
def
self
.
push
(
args
)
def
self
.
push
(
args
)
application_context
=
new
(
**
args
)
application_context
=
new
(
**
args
)
Labkit
::
Context
.
push
(
application_context
.
to_lazy_hash
)
Labkit
::
Context
.
push
(
application_context
.
to_lazy_hash
)
...
...
lib/gitlab/gitaly_client.rb
View file @
24c80189
...
@@ -215,7 +215,7 @@ module Gitlab
...
@@ -215,7 +215,7 @@ module Gitlab
'client_name'
=>
CLIENT_NAME
'client_name'
=>
CLIENT_NAME
}
}
context_data
=
Gitlab
::
ApplicationContext
.
current
context_data
=
Labkit
::
Context
.
current
&
.
to_h
feature_stack
=
Thread
.
current
[
:gitaly_feature_stack
]
feature_stack
=
Thread
.
current
[
:gitaly_feature_stack
]
feature
=
feature_stack
&&
feature_stack
[
0
]
feature
=
feature_stack
&&
feature_stack
[
0
]
...
...
lib/gitlab/grape_logging/loggers/context_logger.rb
View file @
24c80189
...
@@ -6,7 +6,7 @@ module Gitlab
...
@@ -6,7 +6,7 @@ module Gitlab
module
Loggers
module
Loggers
class
ContextLogger
<
::
GrapeLogging
::
Loggers
::
Base
class
ContextLogger
<
::
GrapeLogging
::
Loggers
::
Base
def
parameters
(
_
,
_
)
def
parameters
(
_
,
_
)
Gitlab
::
ApplicationContext
.
current
Labkit
::
Context
.
current
.
to_h
end
end
end
end
end
end
...
...
lib/gitlab/sidekiq_queue.rb
View file @
24c80189
...
@@ -21,7 +21,7 @@ module Gitlab
...
@@ -21,7 +21,7 @@ module Gitlab
job_search_metadata
=
job_search_metadata
=
search_metadata
search_metadata
.
stringify_keys
.
stringify_keys
.
slice
(
*
Gitlab
::
Application
Context
::
KNOWN_KEYS
)
.
slice
(
*
Labkit
::
Context
::
KNOWN_KEYS
)
.
transform_keys
{
|
key
|
"meta.
#{
key
}
"
}
.
transform_keys
{
|
key
|
"meta.
#{
key
}
"
}
.
compact
.
compact
...
...
spec/controllers/application_controller_spec.rb
View file @
24c80189
...
@@ -900,7 +900,7 @@ RSpec.describe ApplicationController do
...
@@ -900,7 +900,7 @@ RSpec.describe ApplicationController do
feature_category
:issue_tracking
feature_category
:issue_tracking
def
index
def
index
Gitlab
::
ApplicationContext
.
with_raw
_context
do
|
context
|
Labkit
::
Context
.
with
_context
do
|
context
|
render
json:
context
.
to_h
render
json:
context
.
to_h
end
end
end
end
...
...
spec/controllers/sessions_controller_spec.rb
View file @
24c80189
...
@@ -524,7 +524,7 @@ RSpec.describe SessionsController do
...
@@ -524,7 +524,7 @@ RSpec.describe SessionsController do
it
'sets the username and caller_id in the context'
do
it
'sets the username and caller_id in the context'
do
expect
(
controller
).
to
receive
(
:destroy
).
and_wrap_original
do
|
m
,
*
args
|
expect
(
controller
).
to
receive
(
:destroy
).
and_wrap_original
do
|
m
,
*
args
|
expect
(
Gitlab
::
ApplicationContext
.
current
)
expect
(
Labkit
::
Context
.
current
.
to_h
)
.
to
include
(
'meta.user'
=>
user
.
username
,
.
to
include
(
'meta.user'
=>
user
.
username
,
'meta.caller_id'
=>
'SessionsController#destroy'
)
'meta.caller_id'
=>
'SessionsController#destroy'
)
...
@@ -538,9 +538,9 @@ RSpec.describe SessionsController do
...
@@ -538,9 +538,9 @@ RSpec.describe SessionsController do
context
'when not signed in'
do
context
'when not signed in'
do
it
'sets the caller_id in the context'
do
it
'sets the caller_id in the context'
do
expect
(
controller
).
to
receive
(
:new
).
and_wrap_original
do
|
m
,
*
args
|
expect
(
controller
).
to
receive
(
:new
).
and_wrap_original
do
|
m
,
*
args
|
expect
(
Gitlab
::
ApplicationContext
.
current
)
expect
(
Labkit
::
Context
.
current
.
to_h
)
.
to
include
(
'meta.caller_id'
=>
'SessionsController#new'
)
.
to
include
(
'meta.caller_id'
=>
'SessionsController#new'
)
expect
(
Gitlab
::
ApplicationContext
.
current
)
expect
(
Labkit
::
Context
.
current
.
to_h
)
.
not_to
include
(
'meta.user'
)
.
not_to
include
(
'meta.user'
)
m
.
call
(
*
args
)
m
.
call
(
*
args
)
...
@@ -557,9 +557,9 @@ RSpec.describe SessionsController do
...
@@ -557,9 +557,9 @@ RSpec.describe SessionsController do
it
'sets the caller_id in the context'
do
it
'sets the caller_id in the context'
do
allow_any_instance_of
(
User
).
to
receive
(
:lock_access!
).
and_wrap_original
do
|
m
,
*
args
|
allow_any_instance_of
(
User
).
to
receive
(
:lock_access!
).
and_wrap_original
do
|
m
,
*
args
|
expect
(
Gitlab
::
ApplicationContext
.
current
)
expect
(
Labkit
::
Context
.
current
.
to_h
)
.
to
include
(
'meta.caller_id'
=>
'SessionsController#create'
)
.
to
include
(
'meta.caller_id'
=>
'SessionsController#create'
)
expect
(
Gitlab
::
ApplicationContext
.
current
)
expect
(
Labkit
::
Context
.
current
.
to_h
)
.
not_to
include
(
'meta.user'
)
.
not_to
include
(
'meta.user'
)
m
.
call
(
*
args
)
m
.
call
(
*
args
)
...
...
spec/lib/gitlab/application_context_spec.rb
View file @
24c80189
...
@@ -27,20 +27,6 @@ RSpec.describe Gitlab::ApplicationContext do
...
@@ -27,20 +27,6 @@ RSpec.describe Gitlab::ApplicationContext do
end
end
end
end
describe
'.with_raw_context'
do
it
'yields the block'
do
expect
{
|
b
|
described_class
.
with_raw_context
({},
&
b
)
}.
to
yield_control
end
it
'passes the attributes unaltered on to labkit'
do
attrs
=
{
foo: :bar
}
expect
(
Labkit
::
Context
).
to
receive
(
:with_context
).
with
(
attrs
)
described_class
.
with_raw_context
(
attrs
)
{}
end
end
describe
'.push'
do
describe
'.push'
do
it
'passes the expected context on to labkit'
do
it
'passes the expected context on to labkit'
do
fake_proc
=
duck_type
(
:call
)
fake_proc
=
duck_type
(
:call
)
...
@@ -124,7 +110,7 @@ RSpec.describe Gitlab::ApplicationContext do
...
@@ -124,7 +110,7 @@ RSpec.describe Gitlab::ApplicationContext do
it
'does not cause queries'
do
it
'does not cause queries'
do
context
=
described_class
.
new
(
project:
create
(
:project
),
namespace:
create
(
:group
,
:nested
),
user:
create
(
:user
))
context
=
described_class
.
new
(
project:
create
(
:project
),
namespace:
create
(
:group
,
:nested
),
user:
create
(
:user
))
expect
{
context
.
use
{
Gitlab
::
ApplicationContext
.
current
}
}.
not_to
exceed_query_limit
(
0
)
expect
{
context
.
use
{
Labkit
::
Context
.
current
.
to_h
}
}.
not_to
exceed_query_limit
(
0
)
end
end
end
end
end
end
spec/lib/gitlab/sidekiq_middleware/worker_context/server_spec.rb
View file @
24c80189
...
@@ -18,7 +18,7 @@ RSpec.describe Gitlab::SidekiqMiddleware::WorkerContext::Server do
...
@@ -18,7 +18,7 @@ RSpec.describe Gitlab::SidekiqMiddleware::WorkerContext::Server do
worker_context
user:
nil
worker_context
user:
nil
def
perform
(
identifier
,
*
args
)
def
perform
(
identifier
,
*
args
)
self
.
class
.
contexts
.
merge!
(
identifier
=>
Gitlab
::
ApplicationContext
.
current
)
self
.
class
.
contexts
.
merge!
(
identifier
=>
Labkit
::
Context
.
current
.
to_h
)
end
end
end
end
end
end
...
...
spec/requests/api/api_spec.rb
View file @
24c80189
...
@@ -105,7 +105,7 @@ RSpec.describe API::API do
...
@@ -105,7 +105,7 @@ RSpec.describe API::API do
it
'logs all application context fields'
do
it
'logs all application context fields'
do
allow_any_instance_of
(
Gitlab
::
GrapeLogging
::
Loggers
::
ContextLogger
).
to
receive
(
:parameters
)
do
allow_any_instance_of
(
Gitlab
::
GrapeLogging
::
Loggers
::
ContextLogger
).
to
receive
(
:parameters
)
do
Gitlab
::
ApplicationContext
.
current
.
tap
do
|
log_context
|
Labkit
::
Context
.
current
.
to_h
.
tap
do
|
log_context
|
expect
(
log_context
).
to
match
(
'correlation_id'
=>
an_instance_of
(
String
),
expect
(
log_context
).
to
match
(
'correlation_id'
=>
an_instance_of
(
String
),
'meta.caller_id'
=>
'/api/:version/projects/:id/issues'
,
'meta.caller_id'
=>
'/api/:version/projects/:id/issues'
,
'meta.remote_ip'
=>
an_instance_of
(
String
),
'meta.remote_ip'
=>
an_instance_of
(
String
),
...
@@ -121,7 +121,7 @@ RSpec.describe API::API do
...
@@ -121,7 +121,7 @@ RSpec.describe API::API do
it
'skips fields that do not apply'
do
it
'skips fields that do not apply'
do
allow_any_instance_of
(
Gitlab
::
GrapeLogging
::
Loggers
::
ContextLogger
).
to
receive
(
:parameters
)
do
allow_any_instance_of
(
Gitlab
::
GrapeLogging
::
Loggers
::
ContextLogger
).
to
receive
(
:parameters
)
do
Gitlab
::
ApplicationContext
.
current
.
tap
do
|
log_context
|
Labkit
::
Context
.
current
.
to_h
.
tap
do
|
log_context
|
expect
(
log_context
).
to
match
(
'correlation_id'
=>
an_instance_of
(
String
),
expect
(
log_context
).
to
match
(
'correlation_id'
=>
an_instance_of
(
String
),
'meta.caller_id'
=>
'/api/:version/users'
,
'meta.caller_id'
=>
'/api/:version/users'
,
'meta.remote_ip'
=>
an_instance_of
(
String
),
'meta.remote_ip'
=>
an_instance_of
(
String
),
...
...
spec/spec_helper.rb
View file @
24c80189
...
@@ -304,10 +304,10 @@ RSpec.configure do |config|
...
@@ -304,10 +304,10 @@ RSpec.configure do |config|
RequestStore
.
clear!
RequestStore
.
clear!
end
end
config
.
around
(
:example
,
:context_aware
)
do
|
example
|
config
.
around
do
|
example
|
# Wrap each example in it's own context to make sure the contexts don't
# Wrap each example in it's own context to make sure the contexts don't
# leak
# leak
Gitlab
::
ApplicationContext
.
with_raw
_context
{
example
.
run
}
Labkit
::
Context
.
with
_context
{
example
.
run
}
end
end
config
.
around
do
|
example
|
config
.
around
do
|
example
|
...
...
spec/support/shared_examples/lib/api/ci/runner_shared_examples.rb
View file @
24c80189
# frozen_string_literal: true
# frozen_string_literal: true
RSpec
.
shared_examples
'API::CI::Runner application context metadata'
do
|
api_route
|
RSpec
.
shared_examples
'API::CI::Runner application context metadata'
do
|
api_route
|
it
'contains correct context metadata'
,
:context_aware
do
it
'contains correct context metadata'
do
# Avoids popping the context from the thread so we can
# Avoids popping the context from the thread so we can
# check its content after the request.
# check its content after the request.
allow
(
Labkit
::
Context
).
to
receive
(
:pop
)
allow
(
Labkit
::
Context
).
to
receive
(
:pop
)
send_request
send_request
Gitlab
::
ApplicationContext
.
with_raw
_context
do
|
context
|
Labkit
::
Context
.
with
_context
do
|
context
|
expected_context
=
{
expected_context
=
{
'meta.caller_id'
=>
api_route
,
'meta.caller_id'
=>
api_route
,
'meta.user'
=>
job
.
user
.
username
,
'meta.user'
=>
job
.
user
.
username
,
...
...
spec/support/shared_examples/requests/api/logging_application_context_shared_examples.rb
View file @
24c80189
# frozen_string_literal: true
# frozen_string_literal: true
RSpec
.
shared_examples
'storing arguments in the application context'
do
RSpec
.
shared_examples
'storing arguments in the application context'
do
it
'places the expected params in the application context'
,
:context_aware
do
around
do
|
example
|
Labkit
::
Context
.
with_context
{
example
.
run
}
end
it
'places the expected params in the application context'
do
# Stub the clearing of the context so we can validate it later
# Stub the clearing of the context so we can validate it later
# The `around` block above makes sure we do clean it up later
allow
(
Labkit
::
Context
).
to
receive
(
:pop
)
allow
(
Labkit
::
Context
).
to
receive
(
:pop
)
subject
subject
expect
(
Gitlab
::
ApplicationContext
.
current
).
to
include
(
log_hash
(
expected_params
))
Labkit
::
Context
.
with_context
do
|
context
|
expect
(
context
.
to_h
)
.
to
include
(
log_hash
(
expected_params
))
end
end
end
def
log_hash
(
hash
)
def
log_hash
(
hash
)
...
...
spec/workers/background_migration_worker_spec.rb
View file @
24c80189
...
@@ -101,7 +101,7 @@ RSpec.describe BackgroundMigrationWorker, :clean_gitlab_redis_shared_state do
...
@@ -101,7 +101,7 @@ RSpec.describe BackgroundMigrationWorker, :clean_gitlab_redis_shared_state do
it
'sets the class that will be executed as the caller_id'
do
it
'sets the class that will be executed as the caller_id'
do
expect
(
Gitlab
::
BackgroundMigration
).
to
receive
(
:perform
)
do
expect
(
Gitlab
::
BackgroundMigration
).
to
receive
(
:perform
)
do
expect
(
Gitlab
::
ApplicationContext
.
current
).
to
include
(
'meta.caller_id'
=>
'Foo'
)
expect
(
Labkit
::
Context
.
current
.
to_h
).
to
include
(
'meta.caller_id'
=>
'Foo'
)
end
end
worker
.
perform
(
'Foo'
,
[
10
,
20
])
worker
.
perform
(
'Foo'
,
[
10
,
20
])
...
...
spec/workers/concerns/worker_context_spec.rb
View file @
24c80189
...
@@ -103,7 +103,7 @@ RSpec.describe WorkerContext do
...
@@ -103,7 +103,7 @@ RSpec.describe WorkerContext do
describe
'#with_context'
do
describe
'#with_context'
do
it
'allows modifying context when the job is running'
do
it
'allows modifying context when the job is running'
do
worker
.
new
.
with_context
(
user:
build_stubbed
(
:user
,
username:
'jane-doe'
))
do
worker
.
new
.
with_context
(
user:
build_stubbed
(
:user
,
username:
'jane-doe'
))
do
expect
(
Gitlab
::
ApplicationContext
.
current
).
to
include
(
'meta.user'
=>
'jane-doe'
)
expect
(
Labkit
::
Context
.
current
.
to_h
).
to
include
(
'meta.user'
=>
'jane-doe'
)
end
end
end
end
...
...
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