Class: Contrast::Components::ContrastService::Interface

Inherits:
Object
  • Object
show all
Includes:
Contrast::Components::ComponentBase, Interface
Defined in:
lib/contrast/components/contrast_service.rb

Overview

A wrapper build around the Common Agent Configuration project to allow for access of the values contained in its parent_configuration_spec.yaml. Specifically, this allows for querying the state of the connection to the Service, as well as sending a message to the Service.

Constant Summary collapse

DEFAULT_SERVICE_LOG =
'contrast_service.log'
LOCALHOST =

The Rails ActionDispatch regexp for localhost IP + literal localhost github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/request.rb#L32

Regexp.union [/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/, /^::1$/, /^0:0:0:0:0:0:0:1(%.*)?$/, /^localhost$/]

Instance Method Summary collapse

Methods included from Interface

included

Methods included from Contrast::Components::ComponentBase

included

Instance Method Details

#hostObject



38
39
40
# File 'lib/contrast/components/contrast_service.rb', line 38

def host
  @_host ||= (CONFIG.root.agent.service.host || Contrast::Config::ServiceConfiguration::DEFAULT_HOST).to_s
end

#logger_pathObject



54
55
56
# File 'lib/contrast/components/contrast_service.rb', line 54

def logger_path
  @_logger_path ||= CONFIG.root.agent.service.logger.path || DEFAULT_SERVICE_LOG
end

#portObject



42
43
44
# File 'lib/contrast/components/contrast_service.rb', line 42

def port
  @_port ||= (CONFIG.root.agent.service.port || Contrast::Config::ServiceConfiguration::DEFAULT_PORT).to_i
end

#socket_pathObject



46
47
48
# File 'lib/contrast/components/contrast_service.rb', line 46

def socket_path
  @_socket_path ||= CONFIG.root.agent.service.socket
end

#use_bundled_service?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/contrast/components/contrast_service.rb', line 25

def use_bundled_service?
  # Validates the config to decide if it's suitable for starting
  # the bundled service
  @_use_bundled_service ||= begin
    # Requirement says "must be true" but that
    # should be "must not be false" -- oops.
    !false?(CONFIG.root.agent.start_bundled_service) &&
        # Either a valid host or a valid socket
        # Path validity is the service's problem
        (LOCALHOST.match?(host) || !!socket_path)
  end
end

#use_tcp?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/contrast/components/contrast_service.rb', line 50

def use_tcp?
  socket_path.nil?
end