Class: Sumologic::Metrics::Request
- Inherits:
-
Object
- Object
- Sumologic::Metrics::Request
- Includes:
- Defaults::Request, Logging, Utils
- Defined in:
- lib/sumologic/metrics/request.rb
Constant Summary
Constants included from Defaults::Request
Defaults::Request::HEADERS, Defaults::Request::RETRIES
Class Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Request
constructor
public: Creates a new request object to send metrics batch.
-
#post(batch) ⇒ Object
public: Posts the write key and batch of messages to the API.
Methods included from Logging
Methods included from Utils
stringify_keys, symbolize_keys, symbolize_keys!
Constructor Details
#initialize(options = {}) ⇒ Request
public: Creates a new request object to send metrics batch
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sumologic/metrics/request.rb', line 18 def initialize( = {}) @headers = [:headers] || HEADERS @retries = [:retries] || RETRIES @backoff_policy = [:backoff_policy] || Sumologic::Metrics::BackoffPolicy.new uri = URI(.fetch(:uri)) http = Net::HTTP.new(uri.host, uri.port) http.set_debug_output(logger) if logger.level == Logger::DEBUG http.use_ssl = uri.scheme == 'https' http.read_timeout = 8 http.open_timeout = 4 @path = uri.path @http = http end |
Class Attribute Details
.stub ⇒ Object
123 124 125 |
# File 'lib/sumologic/metrics/request.rb', line 123 def stub @stub || ENV['STUB'] end |
Instance Method Details
#post(batch) ⇒ Object
public: Posts the write key and batch of messages to the API.
returns - Response of the status and error if it exists
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sumologic/metrics/request.rb', line 38 def post(batch) last_response, exception = retry_with_backoff(@retries) do status_code, body, = send_request(batch) should_retry = should_retry_request?(status_code, body) [Response.new(status_code, ), should_retry] end if exception logger.error(exception.) exception.backtrace.each { |line| logger.error(line) } Response.new(-1, "Connection error: #{exception}") else last_response end end |