Class: Fluent::DatadogOutput::DatadogHTTPClient
- Inherits:
-
DatadogClient
- Object
- DatadogClient
- Fluent::DatadogOutput::DatadogHTTPClient
- Defined in:
- lib/fluent/plugin/out_datadog.rb
Overview
HTTP datadog client
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(logger, use_ssl, no_ssl_validation, host, ssl_port, port, http_proxy, use_compression, api_key, force_v1_routes = false) ⇒ DatadogHTTPClient
constructor
A new instance of DatadogHTTPClient.
- #send(payload) ⇒ Object
Methods inherited from DatadogClient
Constructor Details
#initialize(logger, use_ssl, no_ssl_validation, host, ssl_port, port, http_proxy, use_compression, api_key, force_v1_routes = false) ⇒ DatadogHTTPClient
Returns a new instance of DatadogHTTPClient.
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/fluent/plugin/out_datadog.rb', line 307 def initialize(logger, use_ssl, no_ssl_validation, host, ssl_port, port, http_proxy, use_compression, api_key, force_v1_routes = false) @logger = logger protocol = use_ssl ? "https" : "http" port = use_ssl ? ssl_port : port if force_v1_routes @uri = URI("#{protocol}://#{host}:#{port.to_s}/v1/input/#{api_key}") else @uri = URI("#{protocol}://#{host}:#{port.to_s}/api/v2/logs") end proxy_uri = :ENV if http_proxy proxy_uri = URI.parse(http_proxy) elsif ENV['HTTP_PROXY'] || ENV['http_proxy'] logger.info("Using HTTP proxy defined in `HTTP_PROXY`/`http_proxy` env vars") end logger.info("Starting HTTP connection to #{protocol}://#{host}:#{port.to_s} with compression " + (use_compression ? "enabled" : "disabled") + (force_v1_routes ? " using v1 routes" : " using v2 routes")) @client = Net::HTTP::Persistent.new name: "fluent-plugin-datadog-logcollector", proxy: proxy_uri @client.verify_mode = OpenSSL::SSL::VERIFY_NONE if no_ssl_validation unless force_v1_routes @client.override_headers["DD-API-KEY"] = api_key @client.override_headers["DD-EVP-ORIGIN"] = "fluent" @client.override_headers["DD-EVP-ORIGIN-VERSION"] = DatadogFluentPlugin::VERSION end @client.override_headers["Content-Type"] = "application/json" if use_compression @client.override_headers["Content-Encoding"] = "gzip" end if !@client.proxy_uri.nil? # Log the proxy settings as resolved by the HTTP client logger.info("Using HTTP proxy #{@client.proxy_uri.scheme}://#{@client.proxy_uri.host}:#{@client.proxy_uri.port} username: #{@client.proxy_uri.user ? "set" : "unset"}, password: #{@client.proxy_uri.password ? "set" : "unset"}") end end |
Instance Method Details
#close ⇒ Object
354 355 356 |
# File 'lib/fluent/plugin/out_datadog.rb', line 354 def close @client.shutdown end |
#send(payload) ⇒ Object
340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/fluent/plugin/out_datadog.rb', line 340 def send(payload) request = Net::HTTP::Post.new @uri.request_uri request.body = payload response = @client.request @uri, request res_code = response.code.to_i # on a backend error or on an http 429, retry with backoff if res_code >= 500 || res_code == 429 raise RetryableError.new "Unable to send payload: #{res_code} #{response.}" end if res_code >= 400 @logger.error("Unable to send payload due to client error: #{res_code} #{response.}") end end |