lib/new_relic/agent/configuration/manager.rb in newrelic_rpm-3.5.4.35.beta vs lib/new_relic/agent/configuration/manager.rb in newrelic_rpm-3.5.5.38
- old
+ new
@@ -1,7 +1,8 @@
require 'forwardable'
require 'new_relic/agent/configuration/defaults'
+require 'new_relic/agent/configuration/mask_defaults'
require 'new_relic/agent/configuration/yaml_source'
require 'new_relic/agent/configuration/server_source'
require 'new_relic/agent/configuration/environment_source'
module NewRelic
@@ -20,20 +21,22 @@
def apply_config(source, level=0)
invoke_callbacks(:add, source)
@config_stack.insert(level, source.freeze)
reset_cache
+ log_config(:add, source)
end
def remove_config(source=nil)
if block_given?
@config_stack.delete_if {|c| yield c }
else
@config_stack.delete(source)
end
reset_cache
invoke_callbacks(:remove, source)
+ log_config(:remove, source)
end
def replace_or_add_config(source, level=0)
idx = @config_stack.map{|s| s.class}.index(source.class)
@config_stack.delete_at(idx) if idx
@@ -81,35 +84,52 @@
end
end
end
end
- def flattened_config
+ def flattened
@config_stack.reverse.inject({}) do |flat,layer|
thawed_layer = layer.dup
thawed_layer.each do |k,v|
begin
thawed_layer[k] = instance_eval(&v) if v.respond_to?(:call)
rescue => e
- NewRelic::Control.instance.log.debug("#{e.class.name} : #{e.message} - when accessing config key #{k}")
+ ::NewRelic::Agent.logger.debug("#{e.class.name} : #{e.message} - when accessing config key #{k}")
thawed_layer[k] = nil
end
thawed_layer.delete(:config)
end
flat.merge(thawed_layer)
end
end
+ def apply_mask(hash)
+ MASK_DEFAULTS. \
+ select {|_, proc| proc.call}. \
+ each {|key, _| hash.delete(key) }
+ hash
+ end
+
+ def to_collector_hash
+ DottedHash.new(apply_mask(flattened)).to_hash
+ end
+
def app_names
case self[:app_name]
when Array then self[:app_name]
when String then self[:app_name].split(';')
else []
end
end
def reset_cache
@cache = Hash.new {|hash,key| hash[key] = self.fetch(key) }
+ end
+
+ def log_config(direction, source)
+ ::NewRelic::Agent.logger.debug(
+ "Updating config (#{direction}) from #{source.class}. Results:",
+ flattened.inspect)
end
end
end
end
end