lib/new_relic/agent/configuration/manager.rb in newrelic_rpm-8.2.0 vs lib/new_relic/agent/configuration/manager.rb in newrelic_rpm-8.3.0
- old
+ new
@@ -29,46 +29,46 @@
@cache.keys
end
def initialize
reset_to_defaults
- @callbacks = Hash.new {|hash,key| hash[key] = [] }
+ @callbacks = Hash.new { |hash, key| hash[key] = [] }
end
- def add_config_for_testing(source, level=0)
+ def add_config_for_testing(source, level = 0)
raise 'Invalid config type for testing' unless [Hash, DottedHash].include?(source.class)
invoke_callbacks(:add, source)
@configs_for_testing << [source.freeze, level]
reset_cache
log_config(:add, source)
end
def remove_config_type(sym)
source = case sym
when :security_policy then @security_policy_source
- when :high_security then @high_security_source
- when :environment then @environment_source
- when :server then @server_source
- when :manual then @manual_source
- when :yaml then @yaml_source
- when :default then @default_source
+ when :high_security then @high_security_source
+ when :environment then @environment_source
+ when :server then @server_source
+ when :manual then @manual_source
+ when :yaml then @yaml_source
+ when :default then @default_source
end
remove_config(source)
end
def remove_config(source)
case source
when SecurityPolicySource then @security_policy_source = nil
- when HighSecuritySource then @high_security_source = nil
- when EnvironmentSource then @environment_source = nil
- when ServerSource then @server_source = nil
- when ManualSource then @manual_source = nil
- when YamlSource then @yaml_source = nil
- when DefaultSource then @default_source = nil
+ when HighSecuritySource then @high_security_source = nil
+ when EnvironmentSource then @environment_source = nil
+ when ServerSource then @server_source = nil
+ when ManualSource then @manual_source = nil
+ when YamlSource then @yaml_source = nil
+ when DefaultSource then @default_source = nil
else
- @configs_for_testing.delete_if {|src,lvl| src == source}
+ @configs_for_testing.delete_if { |src, lvl| src == source }
end
reset_cache
invoke_callbacks(:remove, source)
log_config(:remove, source)
@@ -80,16 +80,16 @@
invoke_callbacks(:add, source)
case source
when SecurityPolicySource then @security_policy_source = source
- when HighSecuritySource then @high_security_source = source
- when EnvironmentSource then @environment_source = source
- when ServerSource then @server_source = source
- when ManualSource then @manual_source = source
- when YamlSource then @yaml_source = source
- when DefaultSource then @default_source = source
+ when HighSecuritySource then @high_security_source = source
+ when EnvironmentSource then @environment_source = source
+ when ServerSource then @server_source = source
+ when ManualSource then @manual_source = source
+ when YamlSource then @yaml_source = source
+ when DefaultSource then @default_source = source
else
NewRelic::Agent.logger.warn("Invalid config format; config will be ignored: #{source}")
end
reset_cache
@@ -189,13 +189,13 @@
def finished_configuring?
!@server_source.nil?
end
def flattened
- config_stack.reverse.inject({}) do |flat,layer|
+ config_stack.reverse.inject({}) do |flat, layer|
thawed_layer = layer.to_hash.dup
- thawed_layer.each do |k,v|
+ thawed_layer.each do |k, v|
begin
thawed_layer[k] = instance_eval(&v) if v.respond_to?(:call)
rescue => e
::NewRelic::Agent.logger.debug("#{e.class.name} : #{e.message} - when accessing config key #{k}")
thawed_layer[k] = nil
@@ -205,13 +205,13 @@
flat.merge(thawed_layer.to_hash)
end
end
def apply_mask(hash)
- MASK_DEFAULTS. \
- select {|_, proc| proc.call}. \
- each {|key, _| hash.delete(key) }
+ MASK_DEFAULTS \
+ .select { |_, proc| proc.call } \
+ .each { |key, _| hash.delete(key) }
hash
end
def to_collector_hash
DottedHash.new(apply_mask(flattened)).to_hash.delete_if do |k, v|
@@ -226,13 +226,13 @@
end
end
end
MALFORMED_LABELS_WARNING = "Skipping malformed labels configuration"
- PARSING_LABELS_FAILURE = "Failure during parsing labels. Ignoring and carrying on with connect."
+ PARSING_LABELS_FAILURE = "Failure during parsing labels. Ignoring and carrying on with connect."
- MAX_LABEL_COUNT = 64
+ MAX_LABEL_COUNT = 64
MAX_LABEL_LENGTH = 255
def parsed_labels
case NewRelic::Agent.config[:labels]
when String
@@ -250,11 +250,11 @@
label_pairs = break_label_string_into_pairs(labels)
make_label_hash(label_pairs, labels)
end
def break_label_string_into_pairs(labels)
- stripped_labels = labels.strip.sub(/^;*/,'').sub(/;*$/,'')
+ stripped_labels = labels.strip.sub(/^;*/, '').sub(/;*$/, '')
stripped_labels.split(';').map do |pair|
pair.split(':').map(&:strip)
end
end
@@ -266,46 +266,46 @@
end
end
def valid_label_item?(item)
case item
- when String then !item.empty?
+ when String then !item.empty?
when Numeric then true
- when true then true
- when false then true
+ when true then true
+ when false then true
else false
end
end
def make_label_hash(pairs, labels = nil)
# This can accept a hash, so force it down to an array of pairs first
pairs = Array(pairs)
unless valid_label_pairs?(pairs)
- NewRelic::Agent.logger.warn("#{MALFORMED_LABELS_WARNING}: #{labels||pairs}")
+ NewRelic::Agent.logger.warn("#{MALFORMED_LABELS_WARNING}: #{labels || pairs}")
return []
end
pairs = limit_number_of_labels(pairs)
pairs = remove_duplicates(pairs)
pairs.map do |key, value|
{
- 'label_type' => truncate(key),
+ 'label_type' => truncate(key),
'label_value' => truncate(value.to_s, key)
}
end
end
- def truncate(text, key=nil)
+ def truncate(text, key = nil)
if text.length > MAX_LABEL_LENGTH
if key
msg = "The value for the label '#{key}' is longer than the allowed #{MAX_LABEL_LENGTH} and will be truncated. Value = '#{text}'"
else
msg = "Label name longer than the allowed #{MAX_LABEL_LENGTH} will be truncated. Name = '#{text}'"
end
NewRelic::Agent.logger.warn(msg)
- text[0..MAX_LABEL_LENGTH-1]
+ text[0..MAX_LABEL_LENGTH - 1]
else
text
end
end
@@ -329,24 +329,24 @@
end
# Generally only useful during initial construction and tests
def reset_to_defaults
@security_policy_source = nil
- @high_security_source = nil
- @environment_source = EnvironmentSource.new
- @server_source = nil
- @manual_source = nil
- @yaml_source = nil
- @default_source = DefaultSource.new
+ @high_security_source = nil
+ @environment_source = EnvironmentSource.new
+ @server_source = nil
+ @manual_source = nil
+ @yaml_source = nil
+ @default_source = DefaultSource.new
- @configs_for_testing = []
+ @configs_for_testing = []
reset_cache
end
def reset_cache
- @cache = Hash.new { |hash,key| hash[key] = self.fetch(key) }
+ @cache = Hash.new { |hash, key| hash[key] = self.fetch(key) }
end
def log_config(direction, source)
# Just generating this log message (specifically calling
# flattened.inspect) is expensive enough that we don't want to do it
@@ -357,17 +357,17 @@
end
end
def delete_all_configs_for_testing
@security_policy_source = nil
- @high_security_source = nil
- @environment_source = nil
- @server_source = nil
- @manual_source = nil
- @yaml_source = nil
- @default_source = nil
- @configs_for_testing = []
+ @high_security_source = nil
+ @environment_source = nil
+ @server_source = nil
+ @manual_source = nil
+ @yaml_source = nil
+ @default_source = nil
+ @configs_for_testing = []
end
def num_configs_for_testing
config_stack.size
end
@@ -378,15 +378,15 @@
private
def config_stack
stack = [@security_policy_source,
- @high_security_source,
- @environment_source,
- @server_source,
- @manual_source,
- @yaml_source,
- @default_source]
+ @high_security_source,
+ @environment_source,
+ @server_source,
+ @manual_source,
+ @yaml_source,
+ @default_source]
stack.compact!
@configs_for_testing.each do |config, at_start|
if at_start