Commit 2717fd17 authored by Marius Bobin's avatar Marius Bobin

Merge branch 'bvl-bump-labkit' into 'master'

Remove dependency on KNOWN_KEYS constant to bump gitlab-labkit to 0.22.0

See merge request gitlab-org/gitlab!79744
parents 7ba56ef2 8098101a
...@@ -310,7 +310,7 @@ gem 'pg_query', '~> 2.1' ...@@ -310,7 +310,7 @@ gem 'pg_query', '~> 2.1'
gem 'premailer-rails', '~> 1.10.3' gem 'premailer-rails', '~> 1.10.3'
# LabKit: Tracing and Correlation # LabKit: Tracing and Correlation
gem 'gitlab-labkit', '~> 0.21.3' gem 'gitlab-labkit', '~> 0.22.0'
# Thrift is a dependency of gitlab-labkit, we want a version higher than 0.14.0 # Thrift is a dependency of gitlab-labkit, we want a version higher than 0.14.0
# because of https://gitlab.com/gitlab-org/gitlab/-/issues/321900 # because of https://gitlab.com/gitlab-org/gitlab/-/issues/321900
gem 'thrift', '>= 0.14.0' gem 'thrift', '>= 0.14.0'
......
...@@ -470,11 +470,11 @@ GEM ...@@ -470,11 +470,11 @@ GEM
fog-json (~> 1.2.0) fog-json (~> 1.2.0)
mime-types mime-types
ms_rest_azure (~> 0.12.0) ms_rest_azure (~> 0.12.0)
gitlab-labkit (0.21.3) gitlab-labkit (0.22.0)
actionpack (>= 5.0.0, < 7.0.0) actionpack (>= 5.0.0, < 7.0.0)
activesupport (>= 5.0.0, < 7.0.0) activesupport (>= 5.0.0, < 7.0.0)
grpc (>= 1.37) grpc (>= 1.37)
jaeger-client (~> 1.1) jaeger-client (~> 1.1.0)
opentracing (~> 0.4) opentracing (~> 0.4)
pg_query (~> 2.1) pg_query (~> 2.1)
redis (> 3.0.0, < 5.0.0) redis (> 3.0.0, < 5.0.0)
...@@ -1470,7 +1470,7 @@ DEPENDENCIES ...@@ -1470,7 +1470,7 @@ DEPENDENCIES
gitlab-dangerfiles (~> 2.8.0) gitlab-dangerfiles (~> 2.8.0)
gitlab-experiment (~> 0.7.0) gitlab-experiment (~> 0.7.0)
gitlab-fog-azure-rm (~> 1.2.0) gitlab-fog-azure-rm (~> 1.2.0)
gitlab-labkit (~> 0.21.3) gitlab-labkit (~> 0.22.0)
gitlab-license (~> 2.1.0) gitlab-license (~> 2.1.0)
gitlab-license_finder (~> 6.0) gitlab-license_finder (~> 6.0)
gitlab-mail_room (~> 0.0.9) gitlab-mail_room (~> 0.0.9)
......
...@@ -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::ApplicationContext::KNOWN_KEYS.each do |key| ::Gitlab::ApplicationContext.known_keys.each do |key|
argument key, argument key,
GraphQL::Types::String, GraphQL::Types::String,
required: false, required: false,
......
...@@ -4,6 +4,20 @@ module EE ...@@ -4,6 +4,20 @@ module EE
module Gitlab module Gitlab
module ApplicationContext module ApplicationContext
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
extend ActiveSupport::Concern
EE_KNOWN_KEYS = [
:subscription_plan
].freeze
class_methods do
extend ::Gitlab::Utils::Override
override :known_keys
def known_keys
super + EE_KNOWN_KEYS
end
end
override :to_lazy_hash override :to_lazy_hash
def to_lazy_hash def to_lazy_hash
......
...@@ -9,7 +9,17 @@ module Gitlab ...@@ -9,7 +9,17 @@ module Gitlab
Attribute = Struct.new(:name, :type) Attribute = Struct.new(:name, :type)
LOG_KEY = Labkit::Context::LOG_KEY LOG_KEY = Labkit::Context::LOG_KEY
KNOWN_KEYS = Labkit::Context::KNOWN_KEYS KNOWN_KEYS = [
:user,
:project,
:root_namespace,
:client_id,
:caller_id,
:remote_ip,
:related_class,
:feature_category
].freeze
private_constant :KNOWN_KEYS
APPLICATION_ATTRIBUTES = [ APPLICATION_ATTRIBUTES = [
Attribute.new(:project, Project), Attribute.new(:project, Project),
...@@ -22,6 +32,10 @@ module Gitlab ...@@ -22,6 +32,10 @@ module Gitlab
Attribute.new(:feature_category, String) Attribute.new(:feature_category, String)
].freeze ].freeze
def self.known_keys
KNOWN_KEYS
end
def self.with_context(args, &block) def self.with_context(args, &block)
application_context = new(**args) application_context = new(**args)
application_context.use(&block) application_context.use(&block)
......
...@@ -8,7 +8,7 @@ module Gitlab ...@@ -8,7 +8,7 @@ module Gitlab
InvalidQueueError = Class.new(StandardError) InvalidQueueError = Class.new(StandardError)
WORKER_KEY = 'worker_class' WORKER_KEY = 'worker_class'
ALLOWED_KEYS = Gitlab::ApplicationContext::KNOWN_KEYS + [WORKER_KEY] ALLOWED_KEYS = Gitlab::ApplicationContext.known_keys.map(&:to_s) + [WORKER_KEY]
attr_reader :queue_name attr_reader :queue_name
...@@ -53,7 +53,7 @@ module Gitlab ...@@ -53,7 +53,7 @@ module Gitlab
private private
def transform_key(key) def transform_key(key)
if Gitlab::ApplicationContext::KNOWN_KEYS.include?(key) if Gitlab::ApplicationContext.known_keys.include?(key.to_sym)
"meta.#{key}" "meta.#{key}"
elsif key == WORKER_KEY elsif key == WORKER_KEY
'class' 'class'
......
...@@ -125,6 +125,17 @@ RSpec.describe Gitlab::ApplicationContext do ...@@ -125,6 +125,17 @@ RSpec.describe Gitlab::ApplicationContext do
.to include(project: project.full_path, root_namespace: project.full_path_components.first) .to include(project: project.full_path, root_namespace: project.full_path_components.first)
end end
it 'contains known keys' do
context = described_class.new(project: project)
# Make sure all possible keys would be included
allow(context).to receive_message_chain(:set_values, :include?).and_return(true)
# If a newly added key is added to the context hash, we need to list it in
# the known keys constant. This spec ensures that we do.
expect(context.to_lazy_hash.keys).to contain_exactly(*described_class.known_keys)
end
describe 'setting the client' do describe 'setting the client' do
let_it_be(:remote_ip) { '127.0.0.1' } let_it_be(:remote_ip) { '127.0.0.1' }
let_it_be(:runner) { create(:ci_runner) } let_it_be(:runner) { create(:ci_runner) }
......
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