Class: TingYun::Configuration::ServerSource

Inherits:
DottedHash
  • Object
show all
Defined in:
lib/ting_yun/configuration/server_source.rb

Constant Summary collapse

TOP_LEVEL_KEYS =

These keys appear outside of the agent_config hash in the connect response, but should still be merged in as config settings to the main agent configuration.

[
    "applicationId",
    "tingyunIdSecret",
    "enabled",
    "appSessionKey",
    "dataSentInterval",
    "apdex_t",
    "config"
]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DottedHash

#inspect, symbolize, #to_hash

Constructor Details

#initialize(connect_reply) ⇒ ServerSource

Returns a new instance of ServerSource.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ting_yun/configuration/server_source.rb', line 30

def initialize(connect_reply)
  merged_settings = {}

  merge_top_level_keys(merged_settings, connect_reply)
  merge_agent_config_hash(merged_settings, connect_reply)
  filter_keys(merged_settings)
  # apply_feature_gates(merged_settings, connect_reply, existing_config)

  # The value under this key is a hash mapping transaction name strings
  # to apdex_t values. We don't want the nested hash to be flattened
  # as part of the call to super below, so it skips going through
  # merged_settings.
  # self[:web_transactions_apdex] = connect_reply['web_transactions_apdex']

  # This causes keys in merged_settings to be symbolized and flattened
  super(merged_settings)
end

Class Method Details

.add_top_level_keys_for_testing(add_array) ⇒ Object



22
23
24
# File 'lib/ting_yun/configuration/server_source.rb', line 22

def self.add_top_level_keys_for_testing(add_array)
  TOP_LEVEL_KEYS.concat add_array
end

.remove_top_level_keys_for_testing(remove_arry) ⇒ Object



26
27
28
# File 'lib/ting_yun/configuration/server_source.rb', line 26

def self.remove_top_level_keys_for_testing(remove_arry)
  remove_arry.each{|i| TOP_LEVEL_KEYS.delete(i)}
end

Instance Method Details

#filter_keys(merged_settings) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ting_yun/configuration/server_source.rb', line 69

def filter_keys(merged_settings)
  merged_settings.delete_if do |key, _|
    setting_spec = DEFAULTS[key.to_sym]
    if setting_spec
      if setting_spec[:allowed_from_server]
        false # it's allowed, so don't delete it
      else
        TingYun::Agent.logger.warn("Ignoring server-sent config for '#{key}' - this setting cannot be set from the server")
        true # delete it
      end
    else
      TingYun::Agent.logger.debug("Ignoring unrecognized config key from server: '#{key}'")
      true
    end
  end
end

#fix_transaction_threshold(merged_settings) ⇒ Object



62
63
64
65
66
67
# File 'lib/ting_yun/configuration/server_source.rb', line 62

def fix_transaction_threshold(merged_settings)
  # when value is "apdex_f" remove the config and defer to default
  if merged_settings['transaction_tracer.transaction_threshold'] =~ /apdex_f/i
    merged_settings.delete('transaction_tracer.transaction_threshold')
  end
end

#merge_agent_config_hash(merged_settings, connect_reply) ⇒ Object



56
57
58
59
60
# File 'lib/ting_yun/configuration/server_source.rb', line 56

def merge_agent_config_hash(merged_settings, connect_reply)
  if connect_reply['config']
    merged_settings.merge!(connect_reply['config'])
  end
end

#merge_top_level_keys(merged_settings, connect_reply) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/ting_yun/configuration/server_source.rb', line 48

def merge_top_level_keys(merged_settings, connect_reply)
  TOP_LEVEL_KEYS.each do |key_name|
    if connect_reply[key_name]
      merged_settings[key_name] = connect_reply[key_name]
    end
  end
end