Skip to content
Snippets Groups Projects
Commit 134bf962 authored by Ian Baum's avatar Ian Baum
Browse files

Merge branch 'deprecate-node-attr' into 'master'

Deprecate node['gitlab'] monitoring attributes

Closes #4522

See merge request gitlab-org/omnibus-gitlab!3583
parents 0a91247f 8b716aec
No related branches found
No related tags found
No related merge requests found
---
title: Deprecate node['gitlab'] monitoring attributes instead of removal
merge_request: 3583
author:
type: bug
Loading
Loading
@@ -74,7 +74,6 @@ key and should be renamed. The replacements are as follows
* node['gitlab']['alertmanager'] => node['monitoring']['alertmanager']
* node['gitlab']['redis-exporter'] => node['monitoring']['redis-exporter']
* node['gitlab']['node-exporter'] => node['monitoring']['node-exporter']
* node['gitlab']['redis-exporter'] => node['monitoring']['redis-exporter']
* node['gitlab']['postgres-exporter'] => node['monitoring']['postgres-exporter']
* node['gitlab']['gitlab-monitor'] => node['monitoring']['gitlab-monitor']
* node['gitlab']['grafana'] => node['monitoring']['grafana']
Loading
Loading
Loading
Loading
@@ -738,3 +738,13 @@ default['gitlab']['registry-nginx']['proxy_set_headers'] = {
default['gitlab']['storage-check']['enable'] = false
default['gitlab']['storage-check']['target'] = nil
default['gitlab']['storage-check']['log_directory'] = '/var/log/gitlab/storage-check'
# TODO: Remove Monitoring Dreprecations in GitLab 13
# https://gitlab.com/gitlab-org/omnibus-gitlab/issues/4687
default['gitlab']['prometheus'] = Gitlab::Deprecations::NodeAttribute.new(proc { node['monitoring']['prometheus'].to_h }, "node['gitlab']['prometheus']", "node['monitoring']['prometheus']")
default['gitlab']['alertmanager'] = Gitlab::Deprecations::NodeAttribute.new(proc { node['monitoring']['alertmanager'].to_h }, "node['gitlab']['alertmanager']", "node['monitoring']['alertmanager']")
default['gitlab']['redis-exporter'] = Gitlab::Deprecations::NodeAttribute.new(proc { node['monitoring']['redis-exporter'].to_h }, "node['gitlab']['redis-exporter']", "node['monitoring']['redis-exporter']")
default['gitlab']['node-exporter'] = Gitlab::Deprecations::NodeAttribute.new(proc { node['monitoring']['node-exporter'].to_h }, "node['gitlab']['node-exporter']", "node['monitoring']['node-exporter']")
default['gitlab']['postgres-exporter'] = Gitlab::Deprecations::NodeAttribute.new(proc { node['monitoring']['postgres-exporter'].to_h }, "node['gitlab']['postgres-exporter']", "node['monitoring']['postgres-exporter']")
default['gitlab']['gitlab-monitor'] = Gitlab::Deprecations::NodeAttribute.new(proc { node['monitoring']['gitlab-monitor'] .to_h }, "node['gitlab']['gitlab-monitor']", "node['monitoring']['gitlab-monitor']")
default['gitlab']['grafana'] = Gitlab::Deprecations::NodeAttribute.new(proc { node['monitoring']['grafana'].to_h }, "node['gitlab']['grafana']", "node['monitoring']['grafana']")
Loading
Loading
@@ -58,6 +58,6 @@ class PrometheusHelper
private
 
def node_service(service)
node['gitlab'][service] || node['monitoring'][service]
node['monitoring'][service] || node['gitlab'][service]
end
end
require_relative 'object_proxy'
require_relative 'helpers/logging_helper'
module Gitlab
class Deprecations
class << self
Loading
Loading
@@ -143,5 +146,36 @@ module Gitlab
messages
end
end
class NodeAttribute < ObjectProxy
def self.log_deprecations?
@log_deprecations || false
end
def self.log_deprecations=(value = true)
@log_deprecations = !!value
end
def initialize(target, var_name, new_var_name)
@target = target
@var_name = var_name
@new_var_name = new_var_name
end
def method_missing(method_name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
deprecated_msg(caller[0..2]) if NodeAttribute.log_deprecations?
super
end
private
def deprecated_msg(*called_from)
called_from = called_from.flatten
msg = "Accessing #{@var_name} is deprecated. Support will be removed in a future release. \n" \
"Please update your cookbooks to use #{@new_var_name} in place of #{@var_name}. Accessed from: \n"
called_from.each { |l| msg << "#{l}\n" }
LoggingHelper.deprecation(msg)
end
end
end
end
Loading
Loading
@@ -147,10 +147,10 @@ module Services # rubocop:disable Style/MultilineIfModifier (disabled so we can
def service_status(service, value = nil)
rservice = service.tr('_', '-')
 
service_path = if Gitlab[:node].attribute?(rservice)
[rservice]
elsif Gitlab[:node]['monitoring']&.attribute?(rservice)
service_path = if Gitlab[:node]['monitoring']&.attribute?(rservice)
['monitoring', rservice]
elsif Gitlab[:node].attribute?(rservice)
[rservice]
else
['gitlab', rservice]
end
Loading
Loading
Loading
Loading
@@ -99,10 +99,13 @@ module SettingsHelper
def from_file(_file_path)
# Throw errors for unrecognized top level calls (usually spelling mistakes)
config_strict_mode true
# Turn on node deprecation messages
Gitlab::Deprecations::NodeAttribute.log_deprecations = true
# Allow auto mash creation during from_file call
Gitlab::ConfigMash.auto_vivify { super }
ensure
config_strict_mode false
Gitlab::Deprecations::NodeAttribute.log_deprecations = false
end
 
# Enhance set so strict mode errors aren't thrown as long as the setting is witin our defined config
Loading
Loading
#
# Copyright:: Copyright (c) 2019 GitLab Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module Gitlab
# Inspired by DeprecatedInstanceVariable in https://github.com/chef/chef/blob/master/lib/chef/mixin/deprecation.rb
class ObjectProxyBase
KEEPERS ||= %w{__id__ __send__ instance_eval == equal? initialize object_id dup is_a? freeze}.freeze
instance_methods.each { |method_name| undef_method(method_name) unless KEEPERS.include?(method_name.to_s) }
end
class ObjectProxy < ObjectProxyBase
def initialize(target)
@target = target
end
def method_missing(method_name, *args, &block)
current_target = target
return current_target.send(method_name, *args, &block) if current_target.respond_to?(method_name, true)
super
end
def respond_to_missing?(method_name, include_private = false)
target.send(:respond_to_missing?, method_name, include_private) || super
end
[:nil?, :inspect].each do |method_name|
define_method(method_name) do |*args, &block|
target.send(method_name, *args, &block)
end
end
def target
# Support for defered procs/lambdas
return @target.call if @target.respond_to?(:call)
@target
end
end
end
Loading
Loading
@@ -25,8 +25,8 @@ class OmnibusHelper # rubocop:disable Style/MultilineIfModifier (disabled so we
# being split to their own dedicated cookbooks, and attributes are being moved from
# node['gitlab'][service_name] to node[service_name]. Until they've been moved, we
# need to check both.
return node['gitlab'][service_name]['enable'] if node['gitlab'].key?(service_name)
return node['monitoring'][service_name]['enable'] if node['monitoring'].key?(service_name)
return node['gitlab'][service_name]['enable'] if node['gitlab'].key?(service_name)
 
node[service_name]['enable']
end
Loading
Loading
Loading
Loading
@@ -125,4 +125,30 @@ describe Gitlab::Deprecations do
expect(described_class.identify_deprecated_config(invalid_config, ["mattermost"], mattermost_supported_keys, "10.2", "11.0")).to eq(output)
end
end
describe 'NodeAttribute' do
before do
Gitlab::Deprecations::NodeAttribute.log_deprecations = true
end
after do
Gitlab::Deprecations::NodeAttribute.log_deprecations = false
end
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
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