Class: Datadog::Core::Configuration::AgentSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/configuration/agent_settings.rb

Overview

Immutable container for the resulting settings

Constant Summary collapse

IPV6_REGEXP =

IPv6 regular expression from stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses Does not match IPv4 addresses.

/\A(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\z)/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter: nil, ssl: nil, hostname: nil, port: nil, uds_path: nil, timeout_seconds: nil) ⇒ AgentSettings

Returns a new instance of AgentSettings.



17
18
19
20
21
22
23
24
25
# File 'lib/datadog/core/configuration/agent_settings.rb', line 17

def initialize(adapter: nil, ssl: nil, hostname: nil, port: nil, uds_path: nil, timeout_seconds: nil)
  @adapter = adapter
  @ssl = ssl
  @hostname = hostname
  @port = port
  @uds_path = uds_path
  @timeout_seconds = timeout_seconds
  freeze
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



15
16
17
# File 'lib/datadog/core/configuration/agent_settings.rb', line 15

def adapter
  @adapter
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



15
16
17
# File 'lib/datadog/core/configuration/agent_settings.rb', line 15

def hostname
  @hostname
end

#portObject (readonly)

Returns the value of attribute port.



15
16
17
# File 'lib/datadog/core/configuration/agent_settings.rb', line 15

def port
  @port
end

#sslObject (readonly)

Returns the value of attribute ssl.



15
16
17
# File 'lib/datadog/core/configuration/agent_settings.rb', line 15

def ssl
  @ssl
end

#timeout_secondsObject (readonly)

Returns the value of attribute timeout_seconds.



15
16
17
# File 'lib/datadog/core/configuration/agent_settings.rb', line 15

def timeout_seconds
  @timeout_seconds
end

#uds_pathObject (readonly)

Returns the value of attribute uds_path.



15
16
17
# File 'lib/datadog/core/configuration/agent_settings.rb', line 15

def uds_path
  @uds_path
end

Instance Method Details

#==(other) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/datadog/core/configuration/agent_settings.rb', line 40

def ==(other)
  self.class == other.class &&
    adapter == other.adapter &&
    ssl == other.ssl &&
    hostname == other.hostname &&
    port == other.port &&
    uds_path == other.uds_path &&
    timeout_seconds == other.timeout_seconds
end

#urlObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/datadog/core/configuration/agent_settings.rb', line 27

def url
  case adapter
  when Datadog::Core::Configuration::Ext::Agent::HTTP::ADAPTER
    hostname = self.hostname
    hostname = "[#{hostname}]" if IPV6_REGEXP.match?(hostname)
    "#{ssl ? "https" : "http"}://#{hostname}:#{port}/"
  when Datadog::Core::Configuration::Ext::Agent::UnixSocket::ADAPTER
    "unix://#{uds_path}"
  else
    raise ArgumentError, "Unexpected adapter: #{adapter}"
  end
end