Class: Datadog::Core::Remote::Negotiation

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/remote/negotiation.rb

Overview

Endpoint negotiation

Instance Method Summary collapse

Constructor Details

#initialize(_settings, agent_settings, suppress_logging: {}) ⇒ Negotiation



10
11
12
13
14
15
16
# File 'lib/datadog/core/remote/negotiation.rb', line 10

def initialize(_settings, agent_settings, suppress_logging: {})
  transport_options = {}
  transport_options[:agent_settings] = agent_settings if agent_settings

  @transport_root = Datadog::Core::Remote::Transport::HTTP.root(**transport_options.dup)
  @logged = suppress_logging
end

Instance Method Details

#endpoint?(path) ⇒ Boolean



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/datadog/core/remote/negotiation.rb', line 18

def endpoint?(path)
  res = @transport_root.send_info

  if res.internal_error? && network_error?(res.error)
    unless @logged[:agent_unreachable]
      Datadog.logger.error { "agent unreachable: cannot negotiate #{path}" }
      @logged[:agent_unreachable] = true
    end

    return false
  end

  if res.not_found?
    unless @logged[:no_info_endpoint]
      Datadog.logger.error { "agent reachable but has no /info endpoint: cannot negotiate #{path}" }
      @logged[:no_info_endpoint] = true
    end

    return false
  end

  unless res.ok?
    unless @logged[:unexpected_response]
      Datadog.logger.error { "agent reachable but unexpected response: cannot negotiate #{path}" }
      @logged[:unexpected_response] = true
    end

    return false
  end

  unless res.endpoints.include?(path)
    unless @logged[:no_config_endpoint]
      Datadog.logger.error { "agent reachable but does not report #{path}" }
      @logged[:no_config_endpoint] = true
    end

    return false
  end

  Datadog.logger.debug { "agent reachable and reports #{path}" }

  true
end