Commit 0ea54d53 authored by Alex Buijs's avatar Alex Buijs

Refactor Labkit::Context to Gitlab::ApplicationContext

From Labkit::Context.current.to_h
To Gitlab::ApplicationContext.current
parent 3a8360f0
...@@ -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 = Labkit::Context.current.to_h @current_context = Gitlab::ApplicationContext.current
end end
end end
......
...@@ -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 = Labkit::Context.current.to_h.merge( context = Gitlab::ApplicationContext.current.merge(
'class' => self.class.name, 'class' => self.class.name,
'job_status' => 'running', 'job_status' => 'running',
'queue' => self.class.queue, 'queue' => self.class.queue,
......
...@@ -51,7 +51,7 @@ module Elastic ...@@ -51,7 +51,7 @@ module Elastic
end end
def current_context def current_context
Labkit::Context.current.to_h Gitlab::ApplicationContext.current
end end
end end
end end
...@@ -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 = Labkit::Context.current.to_h outer_context = Gitlab::ApplicationContext.current
expect(worker).to receive(:schedule_mirrors!) do expect(worker).to receive(:schedule_mirrors!) do
inner_context = Labkit::Context.current.to_h inner_context = Gitlab::ApplicationContext.current
# `schedule_mirrors!` needs to return an integer. # `schedule_mirrors!` needs to return an integer.
0 0
......
...@@ -215,7 +215,7 @@ module Gitlab ...@@ -215,7 +215,7 @@ module Gitlab
'client_name' => CLIENT_NAME 'client_name' => CLIENT_NAME
} }
context_data = Labkit::Context.current&.to_h context_data = Gitlab::ApplicationContext.current
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]
......
...@@ -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(_, _)
Labkit::Context.current.to_h Gitlab::ApplicationContext.current
end end
end end
end end
......
...@@ -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(Labkit::Context.current.to_h) expect(Gitlab::ApplicationContext.current)
.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(Labkit::Context.current.to_h) expect(Gitlab::ApplicationContext.current)
.to include('meta.caller_id' => 'SessionsController#new') .to include('meta.caller_id' => 'SessionsController#new')
expect(Labkit::Context.current.to_h) expect(Gitlab::ApplicationContext.current)
.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(Labkit::Context.current.to_h) expect(Gitlab::ApplicationContext.current)
.to include('meta.caller_id' => 'SessionsController#create') .to include('meta.caller_id' => 'SessionsController#create')
expect(Labkit::Context.current.to_h) expect(Gitlab::ApplicationContext.current)
.not_to include('meta.user') .not_to include('meta.user')
m.call(*args) m.call(*args)
......
...@@ -110,7 +110,7 @@ RSpec.describe Gitlab::ApplicationContext do ...@@ -110,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 { Labkit::Context.current.to_h } }.not_to exceed_query_limit(0) expect { context.use { Gitlab::ApplicationContext.current } }.not_to exceed_query_limit(0)
end end
end end
end end
...@@ -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 => Labkit::Context.current.to_h) self.class.contexts.merge!(identifier => Gitlab::ApplicationContext.current)
end end
end end
end end
......
...@@ -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
Labkit::Context.current.to_h.tap do |log_context| Gitlab::ApplicationContext.current.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
Labkit::Context.current.to_h.tap do |log_context| Gitlab::ApplicationContext.current.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),
......
...@@ -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(Labkit::Context.current.to_h).to include('meta.caller_id' => 'Foo') expect(Gitlab::ApplicationContext.current).to include('meta.caller_id' => 'Foo')
end end
worker.perform('Foo', [10, 20]) worker.perform('Foo', [10, 20])
......
...@@ -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(Labkit::Context.current.to_h).to include('meta.user' => 'jane-doe') expect(Gitlab::ApplicationContext.current).to include('meta.user' => 'jane-doe')
end 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