Class: Datadog::CI::Transport::HTTP
- Inherits:
-
Object
- Object
- Datadog::CI::Transport::HTTP
- Defined in:
- lib/datadog/ci/transport/http.rb
Defined Under Namespace
Classes: ErrorResponse
Constant Summary collapse
- DEFAULT_TIMEOUT =
30
- MAX_RETRIES =
3
- INITIAL_BACKOFF =
1
- MAX_BACKOFF =
30
- MAX_RETRY_TIME =
50
- NON_RETRIABLE_ERRORS =
Errors that should not be retried - fail fast
[ Timeout::Error, # Don't slow down customers with timeouts Errno::EINVAL, # Invalid argument Net::HTTPBadResponse # Malformed response - likely persistent issue ].freeze
- RETRIABLE_ERRORS =
Errors that can be retried - transient network issues
[ Errno::ECONNRESET, # Connection reset by peer EOFError, # Unexpected connection close SocketError # DNS/network issues ].freeze
Instance Attribute Summary collapse
-
#compress ⇒ Object
readonly
Returns the value of attribute compress.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(host:, port:, timeout: DEFAULT_TIMEOUT, ssl: true, compress: false) ⇒ HTTP
constructor
A new instance of HTTP.
- #request(path:, payload:, headers:, verb: "post", retries: MAX_RETRIES, backoff: INITIAL_BACKOFF, accept_compressed_response: false) ⇒ Object
Constructor Details
#initialize(host:, port:, timeout: DEFAULT_TIMEOUT, ssl: true, compress: false) ⇒ HTTP
Returns a new instance of HTTP.
43 44 45 46 47 48 49 |
# File 'lib/datadog/ci/transport/http.rb', line 43 def initialize(host:, port:, timeout: DEFAULT_TIMEOUT, ssl: true, compress: false) @host = host @port = port @timeout = timeout @ssl = ssl.nil? || ssl @compress = compress.nil? ? false : compress end |
Instance Attribute Details
#compress ⇒ Object (readonly)
Returns the value of attribute compress.
16 17 18 |
# File 'lib/datadog/ci/transport/http.rb', line 16 def compress @compress end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
16 17 18 |
# File 'lib/datadog/ci/transport/http.rb', line 16 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
16 17 18 |
# File 'lib/datadog/ci/transport/http.rb', line 16 def port @port end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
16 17 18 |
# File 'lib/datadog/ci/transport/http.rb', line 16 def ssl @ssl end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
16 17 18 |
# File 'lib/datadog/ci/transport/http.rb', line 16 def timeout @timeout end |
Instance Method Details
#request(path:, payload:, headers:, verb: "post", retries: MAX_RETRIES, backoff: INITIAL_BACKOFF, accept_compressed_response: false) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/datadog/ci/transport/http.rb', line 51 def request( path:, payload:, headers:, verb: "post", retries: MAX_RETRIES, backoff: INITIAL_BACKOFF, accept_compressed_response: false ) response = nil duration_ms = Core::Utils::Time.measure(:float_millisecond) do if compress headers[Ext::Transport::HEADER_CONTENT_ENCODING] = Ext::Transport::CONTENT_ENCODING_GZIP payload = Gzip.compress(payload) end if accept_compressed_response headers[Ext::Transport::HEADER_ACCEPT_ENCODING] = Ext::Transport::CONTENT_ENCODING_GZIP end Datadog.logger.debug do "Sending #{verb} request: host=#{host}; port=#{port}; ssl_enabled=#{ssl}; " \ "compression_enabled=#{compress}; path=#{path}; payload_size=#{payload.size}" end response = perform_http_call(path: path, payload: payload, headers: headers, verb: verb, retries: retries, backoff: backoff) Datadog.logger.debug do "Received server response: #{response.inspect}" end end # @type var response: Datadog::CI::Transport::Adapters::Net::Response # @type var duration_ms: Float # set some stats about the request response.request_compressed = compress response.request_size = payload.bytesize response.duration_ms = duration_ms response end |