-
Notifications
You must be signed in to change notification settings - Fork 381
/
Copy pathnegotiation.rb
67 lines (52 loc) · 1.81 KB
/
negotiation.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
65
66
67
# frozen_string_literal: true
require_relative 'transport/http'
module Datadog
module Core
module Remote
# Endpoint negotiation
class Negotiation
def initialize(_settings, agent_settings, suppress_logging: {})
@transport_root = Datadog::Core::Remote::Transport::HTTP.root(agent_settings: agent_settings)
@logged = suppress_logging
end
def endpoint?(path)
res = @transport_root.send_info
if res.internal_error? && network_error?(res.error)
unless @logged[:agent_unreachable]
Datadog.logger.warn { "agent unreachable: cannot negotiate #{path}" }
@logged[:agent_unreachable] = true
end
return false
end
if res.not_found?
unless @logged[:no_info_endpoint]
Datadog.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]
Datadog.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]
Datadog.logger.warn { "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
private
def network_error?(error)
error.is_a?(Errno::ECONNREFUSED)
end
end
end
end
end