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
feature_category:
feature_category
)
do
yield
ensure
@current_context
=
Gitlab
::
ApplicationContext
.
current
@current_context
=
Labkit
::
Context
.
current
.
to_h
end
end
...
...
app/graphql/mutations/admin/sidekiq_queues/delete_jobs.rb
View file @
24c80189
...
...
@@ -8,7 +8,7 @@ module Mutations
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
,
GraphQL
::
STRING_TYPE
,
required:
false
,
...
...
app/workers/concerns/application_worker.rb
View file @
24c80189
...
...
@@ -18,7 +18,7 @@ module ApplicationWorker
set_queue
def
structured_payload
(
payload
=
{})
context
=
Gitlab
::
ApplicationContext
.
current
.
merge
(
context
=
Labkit
::
Context
.
current
.
to_h
.
merge
(
'class'
=>
self
.
class
.
name
,
'job_status'
=>
'running'
,
'queue'
=>
self
.
class
.
queue
,
...
...
app/workers/concerns/cronjob_queue.rb
View file @
24c80189
...
...
@@ -15,7 +15,7 @@ module CronjobQueue
# Cronjobs never get scheduled with arguments, so this is safe to
# override
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"
)
end
...
...
ee/app/services/elastic/indexing_control_service.rb
View file @
24c80189
...
...
@@ -6,7 +6,7 @@ module Elastic
# This class should only be used with sidekiq workers which extend Elastic::IndexingControl module
class
IndexingControlService
LIMIT
=
1000
PROJECT_CONTEXT_KEY
=
"
#{
Gitlab
::
Application
Context
::
LOG_KEY
}
.project"
PROJECT_CONTEXT_KEY
=
"
#{
Labkit
::
Context
::
LOG_KEY
}
.project"
def
initialize
(
klass
)
raise
ArgumentError
,
"passed class must extend Elastic::IndexingControl"
unless
klass
.
include?
(
Elastic
::
IndexingControl
)
...
...
@@ -93,7 +93,7 @@ module Elastic
end
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'
])
end
end
...
...
ee/app/workers/concerns/elastic/indexing_control.rb
View file @
24c80189
...
...
@@ -51,7 +51,7 @@ module Elastic
end
def
current_context
Gitlab
::
ApplicationContext
.
current
Labkit
::
Context
.
current
.
to_h
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
end
let
(
:stored_context
)
do
{
"
#{
Gitlab
::
Application
Context
::
LOG_KEY
}
.project"
=>
'gitlab-org/gitlab'
}
{
"
#{
Labkit
::
Context
::
LOG_KEY
}
.project"
=>
'gitlab-org/gitlab'
}
end
let
(
:worker_args
)
{
[
1
,
2
]
}
...
...
@@ -133,7 +133,7 @@ RSpec.describe Elastic::IndexingControlService, :clean_gitlab_redis_shared_state
subject
.
add_to_waiting_queue!
(
j
,
worker_context
)
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
{
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
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
)
Gitlab
::
ApplicationContext
.
with_raw
_context
(
worker_context
)
do
Labkit
::
Context
.
with
_context
(
worker_context
)
do
worker
.
perform
(
*
worker_args
)
end
end
...
...
ee/spec/workers/update_all_mirrors_worker_spec.rb
View file @
24c80189
...
...
@@ -32,10 +32,10 @@ RSpec.describe UpdateAllMirrorsWorker do
outer_context
=
nil
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
inner_context
=
Gitlab
::
ApplicationContext
.
current
inner_context
=
Labkit
::
Context
.
current
.
to_h
# `schedule_mirrors!` needs to return an integer.
0
...
...
lib/api/admin/sidekiq.rb
View file @
24c80189
...
...
@@ -12,11 +12,11 @@ module API
namespace
'queues'
do
desc
'Drop jobs matching the given metadata from the Sidekiq queue'
params
do
Gitlab
::
Application
Context
::
KNOWN_KEYS
.
each
do
|
key
|
Labkit
::
Context
::
KNOWN_KEYS
.
each
do
|
key
|
optional
key
,
type:
String
,
allow_blank:
false
end
at_least_one_of
(
*
Gitlab
::
Application
Context
::
KNOWN_KEYS
)
at_least_one_of
(
*
Labkit
::
Context
::
KNOWN_KEYS
)
end
delete
':queue_name'
do
result
=
...
...
lib/gitlab/application_context.rb
View file @
24c80189
...
...
@@ -7,9 +7,6 @@ module Gitlab
Attribute
=
Struct
.
new
(
:name
,
:type
)
LOG_KEY
=
Labkit
::
Context
::
LOG_KEY
KNOWN_KEYS
=
Labkit
::
Context
::
KNOWN_KEYS
APPLICATION_ATTRIBUTES
=
[
Attribute
.
new
(
:project
,
Project
),
Attribute
.
new
(
:namespace
,
Namespace
),
...
...
@@ -25,10 +22,6 @@ module Gitlab
application_context
.
use
(
&
block
)
end
def
self
.
with_raw_context
(
attributes
=
{},
&
block
)
Labkit
::
Context
.
with_context
(
attributes
,
&
block
)
end
def
self
.
push
(
args
)
application_context
=
new
(
**
args
)
Labkit
::
Context
.
push
(
application_context
.
to_lazy_hash
)
...
...
lib/gitlab/gitaly_client.rb
View file @
24c80189
...
...
@@ -215,7 +215,7 @@ module Gitlab
'client_name'
=>
CLIENT_NAME
}
context_data
=
Gitlab
::
ApplicationContext
.
current
context_data
=
Labkit
::
Context
.
current
&
.
to_h
feature_stack
=
Thread
.
current
[
:gitaly_feature_stack
]
feature
=
feature_stack
&&
feature_stack
[
0
]
...
...
lib/gitlab/grape_logging/loggers/context_logger.rb
View file @
24c80189
...
...
@@ -6,7 +6,7 @@ module Gitlab
module
Loggers
class
ContextLogger
<
::
GrapeLogging
::
Loggers
::
Base
def
parameters
(
_
,
_
)
Gitlab
::
ApplicationContext
.
current
Labkit
::
Context
.
current
.
to_h
end
end
end
...
...
lib/gitlab/sidekiq_queue.rb
View file @
24c80189
...
...
@@ -21,7 +21,7 @@ module Gitlab
job_search_metadata
=
search_metadata
.
stringify_keys
.
slice
(
*
Gitlab
::
Application
Context
::
KNOWN_KEYS
)
.
slice
(
*
Labkit
::
Context
::
KNOWN_KEYS
)
.
transform_keys
{
|
key
|
"meta.
#{
key
}
"
}
.
compact
...
...
spec/controllers/application_controller_spec.rb
View file @
24c80189
...
...
@@ -900,7 +900,7 @@ RSpec.describe ApplicationController do
feature_category
:issue_tracking
def
index
Gitlab
::
ApplicationContext
.
with_raw
_context
do
|
context
|
Labkit
::
Context
.
with
_context
do
|
context
|
render
json:
context
.
to_h
end
end
...
...
spec/controllers/sessions_controller_spec.rb
View file @
24c80189
...
...
@@ -524,7 +524,7 @@ RSpec.describe SessionsController do
it
'sets the username and caller_id in the context'
do
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
,
'meta.caller_id'
=>
'SessionsController#destroy'
)
...
...
@@ -538,9 +538,9 @@ RSpec.describe SessionsController do
context
'when not signed in'
do
it
'sets the caller_id in the context'
do
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'
)
expect
(
Gitlab
::
ApplicationContext
.
current
)
expect
(
Labkit
::
Context
.
current
.
to_h
)
.
not_to
include
(
'meta.user'
)
m
.
call
(
*
args
)
...
...
@@ -557,9 +557,9 @@ RSpec.describe SessionsController 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
|
expect
(
Gitlab
::
ApplicationContext
.
current
)
expect
(
Labkit
::
Context
.
current
.
to_h
)
.
to
include
(
'meta.caller_id'
=>
'SessionsController#create'
)
expect
(
Gitlab
::
ApplicationContext
.
current
)
expect
(
Labkit
::
Context
.
current
.
to_h
)
.
not_to
include
(
'meta.user'
)
m
.
call
(
*
args
)
...
...
spec/lib/gitlab/application_context_spec.rb
View file @
24c80189
...
...
@@ -27,20 +27,6 @@ RSpec.describe Gitlab::ApplicationContext do
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
it
'passes the expected context on to labkit'
do
fake_proc
=
duck_type
(
:call
)
...
...
@@ -124,7 +110,7 @@ RSpec.describe Gitlab::ApplicationContext do
it
'does not cause queries'
do
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
spec/lib/gitlab/sidekiq_middleware/worker_context/server_spec.rb
View file @
24c80189
...
...
@@ -18,7 +18,7 @@ RSpec.describe Gitlab::SidekiqMiddleware::WorkerContext::Server do
worker_context
user:
nil
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
...
...
spec/requests/api/api_spec.rb
View file @
24c80189
...
...
@@ -105,7 +105,7 @@ RSpec.describe API::API do
it
'logs all application context fields'
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
),
'meta.caller_id'
=>
'/api/:version/projects/:id/issues'
,
'meta.remote_ip'
=>
an_instance_of
(
String
),
...
...
@@ -121,7 +121,7 @@ RSpec.describe API::API do
it
'skips fields that do not apply'
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
),
'meta.caller_id'
=>
'/api/:version/users'
,
'meta.remote_ip'
=>
an_instance_of
(
String
),
...
...
spec/spec_helper.rb
View file @
24c80189
...
...
@@ -304,10 +304,10 @@ RSpec.configure do |config|
RequestStore
.
clear!
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
# leak
Gitlab
::
ApplicationContext
.
with_raw
_context
{
example
.
run
}
Labkit
::
Context
.
with
_context
{
example
.
run
}
end
config
.
around
do
|
example
|
...
...
spec/support/shared_examples/lib/api/ci/runner_shared_examples.rb
View file @
24c80189
# frozen_string_literal: true
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
# check its content after the request.
allow
(
Labkit
::
Context
).
to
receive
(
:pop
)
send_request
Gitlab
::
ApplicationContext
.
with_raw
_context
do
|
context
|
Labkit
::
Context
.
with
_context
do
|
context
|
expected_context
=
{
'meta.caller_id'
=>
api_route
,
'meta.user'
=>
job
.
user
.
username
,
...
...
spec/support/shared_examples/requests/api/logging_application_context_shared_examples.rb
View file @
24c80189
# frozen_string_literal: true
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
# The `around` block above makes sure we do clean it up later
allow
(
Labkit
::
Context
).
to
receive
(
:pop
)
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
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
it
'sets the class that will be executed as the caller_id'
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
worker
.
perform
(
'Foo'
,
[
10
,
20
])
...
...
spec/workers/concerns/worker_context_spec.rb
View file @
24c80189
...
...
@@ -103,7 +103,7 @@ RSpec.describe WorkerContext do
describe
'#with_context'
do
it
'allows modifying context when the job is running'
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
...
...
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