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
feature_category: feature_category) do
yield
ensure
@current_context = Labkit::Context.current.to_h
@current_context = Gitlab::ApplicationContext.current
end
end
......
......@@ -18,7 +18,7 @@ module ApplicationWorker
set_queue
def structured_payload(payload = {})
context = Labkit::Context.current.to_h.merge(
context = Gitlab::ApplicationContext.current.merge(
'class' => self.class.name,
'job_status' => 'running',
'queue' => self.class.queue,
......
......@@ -51,7 +51,7 @@ module Elastic
end
def current_context
Labkit::Context.current.to_h
Gitlab::ApplicationContext.current
end
end
end
......@@ -32,10 +32,10 @@ RSpec.describe UpdateAllMirrorsWorker do
outer_context = nil
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
inner_context = Labkit::Context.current.to_h
inner_context = Gitlab::ApplicationContext.current
# `schedule_mirrors!` needs to return an integer.
0
......
......@@ -215,7 +215,7 @@ module Gitlab
'client_name' => CLIENT_NAME
}
context_data = Labkit::Context.current&.to_h
context_data = Gitlab::ApplicationContext.current
feature_stack = Thread.current[:gitaly_feature_stack]
feature = feature_stack && feature_stack[0]
......
......@@ -6,7 +6,7 @@ module Gitlab
module Loggers
class ContextLogger < ::GrapeLogging::Loggers::Base
def parameters(_, _)
Labkit::Context.current.to_h
Gitlab::ApplicationContext.current
end
end
end
......
......@@ -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(Labkit::Context.current.to_h)
expect(Gitlab::ApplicationContext.current)
.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(Labkit::Context.current.to_h)
expect(Gitlab::ApplicationContext.current)
.to include('meta.caller_id' => 'SessionsController#new')
expect(Labkit::Context.current.to_h)
expect(Gitlab::ApplicationContext.current)
.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(Labkit::Context.current.to_h)
expect(Gitlab::ApplicationContext.current)
.to include('meta.caller_id' => 'SessionsController#create')
expect(Labkit::Context.current.to_h)
expect(Gitlab::ApplicationContext.current)
.not_to include('meta.user')
m.call(*args)
......
......@@ -110,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 { 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
......@@ -18,7 +18,7 @@ RSpec.describe Gitlab::SidekiqMiddleware::WorkerContext::Server do
worker_context user: nil
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
......
......@@ -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
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),
'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
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),
'meta.caller_id' => '/api/:version/users',
'meta.remote_ip' => an_instance_of(String),
......
......@@ -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(Labkit::Context.current.to_h).to include('meta.caller_id' => 'Foo')
expect(Gitlab::ApplicationContext.current).to include('meta.caller_id' => 'Foo')
end
worker.perform('Foo', [10, 20])
......
......@@ -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(Labkit::Context.current.to_h).to include('meta.user' => 'jane-doe')
expect(Gitlab::ApplicationContext.current).to include('meta.user' => 'jane-doe')
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