Class: NewRelic::Agent::Configuration::DefaultSource
- Inherits:
-
Object
- Object
- NewRelic::Agent::Configuration::DefaultSource
- Extended by:
- Forwardable
- Defined in:
- lib/new_relic/agent/configuration/default_source.rb
Constant Summary collapse
- DEFAULT_LOG_DIR =
'log/'.freeze
- SEMICOLON =
';'.freeze
Instance Attribute Summary collapse
- #defaults ⇒ Object readonly
Class Method Summary collapse
- .agent_enabled ⇒ Object
- .api_host ⇒ Object
- .app_name ⇒ Object
- .audit_log_path ⇒ Object
- .config_path ⇒ Object
-
.config_search_paths ⇒ Object
rubocop:disable Metrics/AbcSize.
- .convert_to_constant_list(raw_value) ⇒ Object
- .convert_to_hash(value) ⇒ Object
- .convert_to_list(value) ⇒ Object
- .convert_to_list_on_semicolon(value) ⇒ Object
- .convert_to_regexp_list(raw_value) ⇒ Object
- .dispatcher ⇒ Object
- .enforce_fallback(allowed_values: nil, fallback: nil) ⇒ Object
- .framework ⇒ Object
- .host ⇒ Object
- .profiling_available ⇒ Object
- .thread_profiler_enabled ⇒ Object
- .transaction_tracer_transaction_threshold ⇒ Object
- .transform_for(key) ⇒ Object
Instance Method Summary collapse
- #default_values ⇒ Object
-
#initialize ⇒ DefaultSource
constructor
A new instance of DefaultSource.
Constructor Details
#initialize ⇒ DefaultSource
Returns a new instance of DefaultSource.
42 43 44 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 42 def initialize @defaults = default_values end |
Instance Attribute Details
#defaults ⇒ Object (readonly)
37 38 39 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 37 def defaults @defaults end |
Class Method Details
.agent_enabled ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 124 def self.agent_enabled proc { NewRelic::Agent.config[:enabled] && (NewRelic::Agent.config[:test_mode] || NewRelic::Agent.config[:monitor_mode]) && NewRelic::Agent::Autostart.agent_should_start? } end |
.api_host ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 182 def self.api_host # only used for deployment task proc do api_version = if NewRelic::Agent.config[:api_key].nil? || NewRelic::Agent.config[:api_key].empty? 'rpm' else 'api' end api_region = 'eu.' if String(NewRelic::Agent.config[:license_key]).start_with?('eu') "#{api_version}.#{api_region}newrelic.com" end end |
.app_name ⇒ Object
144 145 146 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 144 def self.app_name proc { NewRelic::Control.instance.env } end |
.audit_log_path ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 134 def self.audit_log_path proc { log_file_path = NewRelic::Agent.config[:log_file_path] wants_stdout = (log_file_path.casecmp(NewRelic::STANDARD_OUT) == 0) audit_log_dir = wants_stdout ? DEFAULT_LOG_DIR : log_file_path File.join(audit_log_dir, 'newrelic_audit.log') } end |
.config_path ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 94 def self.config_path proc { found_path = NewRelic::Agent.config[:config_search_paths].detect do |file| File.(file) if File.exist?(file) end found_path || NewRelic::EMPTY_STR } end |
.config_search_paths ⇒ Object
rubocop:disable Metrics/AbcSize
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 59 def self.config_search_paths # rubocop:disable Metrics/AbcSize proc { yaml = 'newrelic.yml' config_yaml = File.join('config', yaml) erb = 'newrelic.yml.erb' config_erb = File.join('config', erb) paths = [config_yaml, yaml, config_erb, erb] if NewRelic::Control.instance.root paths << File.join(NewRelic::Control.instance.root, config_yaml) paths << File.join(NewRelic::Control.instance.root, yaml) paths << File.join(NewRelic::Control.instance.root, config_erb) paths << File.join(NewRelic::Control.instance.root, erb) end if ENV['HOME'] paths << File.join(ENV['HOME'], '.newrelic', yaml) paths << File.join(ENV['HOME'], yaml) paths << File.join(ENV['HOME'], '.newrelic', erb) paths << File.join(ENV['HOME'], erb) end # If we're packaged for warbler, we can tell from GEM_HOME # the following line needs else branch coverage if ENV['GEM_HOME'] && ENV['GEM_HOME'].end_with?('.jar!') # rubocop:disable Style/SafeNavigation app_name = File.basename(ENV['GEM_HOME'], '.jar!') paths << File.join(ENV['GEM_HOME'], app_name, config_yaml) paths << File.join(ENV['GEM_HOME'], app_name, config_erb) end paths } end |
.convert_to_constant_list(raw_value) ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 239 def self.convert_to_constant_list(raw_value) return NewRelic::EMPTY_ARRAY if raw_value.nil? || raw_value.empty? constants = convert_to_list(raw_value).map! do |class_name| const = ::NewRelic::LanguageSupport.constantize(class_name) NewRelic::Agent.logger.warn("Ignoring invalid constant '#{class_name}' in #{raw_value}") unless const const end constants.compact! constants end |
.convert_to_hash(value) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 214 def self.convert_to_hash(value) return value if value.is_a?(Hash) if value.is_a?(String) return value.split(',').each_with_object({}) do |item, hash| key, value = item.split('=') hash[key] = value end end raise ArgumentError.new( "Config value '#{value}' of " \ "class #{value.class} couldn't be turned into a Hash." ) end |
.convert_to_list(value) ⇒ Object
203 204 205 206 207 208 209 210 211 212 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 203 def self.convert_to_list(value) case value when String value.split(/\s*,\s*/) when Array value else raise ArgumentError.new("Config value '#{value}' couldn't be turned into a list.") end end |
.convert_to_list_on_semicolon(value) ⇒ Object
231 232 233 234 235 236 237 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 231 def self.convert_to_list_on_semicolon(value) case value when Array then value when String then value.split(SEMICOLON) else NewRelic::EMPTY_ARRAY end end |
.convert_to_regexp_list(raw_value) ⇒ Object
196 197 198 199 200 201 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 196 def self.convert_to_regexp_list(raw_value) value_list = convert_to_list(raw_value) value_list.map do |value| /#{value}/ end end |
.dispatcher ⇒ Object
148 149 150 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 148 def self.dispatcher proc { NewRelic::Control.instance.local_env.discovered_dispatcher } end |
.enforce_fallback(allowed_values: nil, fallback: nil) ⇒ Object
251 252 253 254 255 256 257 258 259 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 251 def self.enforce_fallback(allowed_values: nil, fallback: nil) proc do |configured_value| if allowed_values.any? { |v| v =~ /#{configured_value}/i } configured_value else fallback end end end |
.framework ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 103 def self.framework proc { case when defined?(::NewRelic::TEST) then :test when defined?(::Rails::VERSION) case Rails::VERSION::MAJOR when 3 :rails3 when 4..7 :rails_notifications else ::NewRelic::Agent.logger.warn("Detected untested Rails version #{Rails::VERSION::STRING}") :rails_notifications end when defined?(::Sinatra) && defined?(::Sinatra::Base) then :sinatra when defined?(::NewRelic::IA) then :external else :ruby end } end |
.host ⇒ Object
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 171 def self.host proc do regex = /\A(?<identifier>.+?)x/ if matches = regex.match(String(NewRelic::Agent.config[:license_key])) "collector.#{matches['identifier']}.nr-data.net" else 'collector.newrelic.com' end end end |
.profiling_available ⇒ Object
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 160 def self.profiling_available proc { begin require 'ruby-prof' true rescue LoadError false end } end |
.thread_profiler_enabled ⇒ Object
152 153 154 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 152 def self.thread_profiler_enabled proc { NewRelic::Agent::Threading::BacktraceService.is_supported? } end |
.transaction_tracer_transaction_threshold ⇒ Object
156 157 158 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 156 def self.transaction_tracer_transaction_threshold proc { NewRelic::Agent.config[:apdex_t] * 4 } end |
.transform_for(key) ⇒ Object
54 55 56 57 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 54 def self.transform_for(key) default_settings = ::NewRelic::Agent::Configuration::DEFAULTS[key] default_settings[:transform] if default_settings end |
Instance Method Details
#default_values ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/new_relic/agent/configuration/default_source.rb', line 46 def default_values result = {} ::NewRelic::Agent::Configuration::DEFAULTS.each do |key, value| result[key] = value[:default] end result end |