Skip to content
Snippets Groups Projects
Commit f2cfa2a5 authored by DJ Mountney's avatar DJ Mountney
Browse files

Support proc as deprecation target

parent 8080505e
No related branches found
No related tags found
No related merge requests found
......@@ -2,4 +2,4 @@
title: Deprecate node['prometheus'] rather than have it completely removed
merge_request: 3582
author:
type: added
type: bug
......@@ -126,4 +126,4 @@
}
# TODO: Remove Dreprecation in GitLab 13
default['prometheus'] = Gitlab::Deprecations::NodeAttribute.new(default['monitoring'], "node['prometheus']", "node['monitoring']")
default['prometheus'] = Gitlab::Deprecations::NodeAttribute.new(proc { node['monitoring'] }, "node['prometheus']", "node['monitoring']")
......@@ -122,7 +122,8 @@
def method_missing(method_name, *args, &block)
deprecated_msg(caller[0..3])
(@target.respond_to?(method_name) && @target.send(method_name, *args, &block)) || super
current_target = target
(current_target.respond_to?(method_name, true) && current_target.send(method_name, *args, &block)) || super
end
def respond_to_missing?(method_name, include_private = false)
......@@ -126,7 +127,11 @@
end
def respond_to_missing?(method_name, include_private = false)
@target.send(:respond_to_missing?, method_name, include_private) || super
target.send(:respond_to_missing?, method_name, include_private) || super
end
def nil?
target.nil?
end
def inspect
......@@ -130,7 +135,13 @@
end
def inspect
@target.inspect
target.inspect
end
def target
return @target.call if @target.respond_to?(:call)
@target
end
private
......
......@@ -147,5 +147,7 @@
def service_status(service, value = nil)
rservice = service.tr('_', '-')
service_path = if Gitlab[:node].attribute?(rservice)
service_path = if Gitlab[:node]['monitoring']&.attribute?(rservice)
['monitoring', rservice]
elsif Gitlab[:node].attribute?(rservice)
[rservice]
......@@ -151,6 +153,4 @@
[rservice]
elsif Gitlab[:node]['monitoring']&.attribute?(rservice)
['monitoring', rservice]
else
['gitlab', rservice]
end
......
......@@ -127,10 +127,10 @@
end
describe 'NodeAttribute' do
it 'Logs deprecations for passed variables' do
it 'Logs deprecations for passed variables and proxies to new object' do
config = { 'monitoring' => { 'test' => 'test-value' } }
config['prometheus'] = Gitlab::Deprecations::NodeAttribute.new(config['monitoring'], "config['prometheus']", "config['monitoring']")
expect(LoggingHelper).to receive(:deprecation).with(/Accessing config\['prometheus'\] is deprecated/)
expect(config['prometheus']['test']).to eq('test-value')
end
......@@ -131,8 +131,16 @@
config = { 'monitoring' => { 'test' => 'test-value' } }
config['prometheus'] = Gitlab::Deprecations::NodeAttribute.new(config['monitoring'], "config['prometheus']", "config['monitoring']")
expect(LoggingHelper).to receive(:deprecation).with(/Accessing config\['prometheus'\] is deprecated/)
expect(config['prometheus']['test']).to eq('test-value')
end
it 'Logs deprecations for passed variables and proxies to new Proc if provided' do
config = { 'monitoring' => { 'test' => 'test-value' } }
config['prometheus'] = Gitlab::Deprecations::NodeAttribute.new(proc { config['monitoring'] }, "config['prometheus']", "config['monitoring']")
expect(LoggingHelper).to receive(:deprecation).with(/Accessing config\['prometheus'\] is deprecated/)
expect(config['prometheus']['test']).to eq('test-value')
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment