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

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

Overview

Endpoint negotiation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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



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

def initialize(_settings, agent_settings, logger: Datadog.logger, suppress_logging: {})
  @logger = logger
  @transport_root = Datadog::Core::Remote::Transport::HTTP.root(agent_settings: agent_settings, logger: logger)
  @logged = suppress_logging
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
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
61
62
63
64
# File 'lib/datadog/core/remote/negotiation.rb', line 18

def endpoint?(path)
  # Cloudwise 环境不支持 /info 端点,直接返回 false
  # 避免向 Cloudwise 服务器发送不支持的请求
  return false if cloudwise_mode?

  res = @transport_root.send_info

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

    return false
  end

  if res.not_found?
    unless @logged[:no_info_endpoint]
      logger.warn { "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]
      logger.warn { "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]
      logger.warn { "agent reachable but does not report #{path}" }
      @logged[:no_config_endpoint] = true
    end

    return false
  end

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

  true
end