Class: Fluent::DatadogOutput::DatadogHTTPClient

Inherits:
DatadogClient show all
Defined in:
lib/fluent/plugin/out_datadog.rb

Overview

HTTP datadog client

Instance Method Summary collapse

Methods inherited from DatadogClient

#send_retries

Constructor Details

#initialize(logger, use_ssl, no_ssl_validation, host, ssl_port, port, use_compression, api_key) ⇒ DatadogHTTPClient



299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/fluent/plugin/out_datadog.rb', line 299

def initialize(logger, use_ssl, no_ssl_validation, host, ssl_port, port, use_compression, api_key)
  @logger = logger
  protocol = use_ssl ? "https" : "http"
  port = use_ssl ? ssl_port : port
  @uri = URI("#{protocol}://#{host}:#{port.to_s}/v1/input/#{api_key}")
  logger.info("Starting HTTP connection to #{protocol}://#{host}:#{port.to_s} with compression " + (use_compression ? "enabled" : "disabled"))
  @client = Net::HTTP::Persistent.new("fluent-plugin-datadog-logcollector")
  @client.verify_mode = OpenSSL::SSL::VERIFY_NONE if no_ssl_validation
  @client.override_headers["Content-Type"] = "application/json"
  if use_compression
    @client.override_headers["Content-Encoding"] = "gzip"
  end
end

Instance Method Details

#closeObject



326
327
328
# File 'lib/fluent/plugin/out_datadog.rb', line 326

def close
  @client.shutdown
end

#send(payload) ⇒ Object



313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/fluent/plugin/out_datadog.rb', line 313

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
  if res_code >= 500
    raise RetryableError.new "Unable to send payload: #{res_code} #{response.message}"
  end
  if res_code >= 400
    @logger.error("Unable to send payload due to client error: #{res_code} #{response.message}")
  end
end