Class: NewRelic::Agent::Connect::ResponseHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/connect/response_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(agent, config) ⇒ ResponseHandler

Returns a new instance of ResponseHandler.



9
10
11
12
# File 'lib/new_relic/agent/connect/response_handler.rb', line 9

def initialize(agent, config)
  @agent = agent
  @config = config
end

Instance Method Details

#add_server_side_config(config_data) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/new_relic/agent/connect/response_handler.rb', line 35

def add_server_side_config(config_data)
  if config_data['agent_config']
    ::NewRelic::Agent.logger.debug('Using config from server')
  end

  ::NewRelic::Agent.logger.debug("Server provided config: #{config_data.inspect}")
  server_config = NewRelic::Agent::Configuration::ServerSource.new(config_data, @config)
  @config.replace_or_add_config(server_config)
end

#configure_agent(config_data) ⇒ Object

Takes a hash of configuration data returned from the server and uses it to set local variables and to initialize various parts of the agent that are configured separately.

Can accommodate most arbitrary data - anything extra is ignored unless we say to do something with it here.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/new_relic/agent/connect/response_handler.rb', line 21

def configure_agent(config_data)
  return if config_data.nil?

  @agent.agent_id = config_data['agent_run_id']

  add_server_side_config(config_data)

  @agent.transaction_rules = RulesEngine.create_transaction_rules(config_data)
  @agent.stats_engine.metric_rules = RulesEngine.create_metric_rules(config_data)

  # If you're adding something else here to respond to the server-side config,
  # use Agent.instance.events.subscribe(:initial_configuration_complete) callback instead!
end