Class: LogStash::Outputs::ElasticSearch::HttpClient::ManticoreAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, options = {}) ⇒ ManticoreAdapter

Returns a new instance of ManticoreAdapter.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb', line 8

def initialize(logger, options={})
  @logger = logger
  @options = options || {}
  @options[:ssl] = @options[:ssl] || {}

  # We manage our own retries directly, so let's disable them here
  @options[:automatic_retries] = 0
  # We definitely don't need cookies
  @options[:cookies] = false

  @request_options = @options[:headers] ? {:headers => @options[:headers]} : {}
  @manticore = ::Manticore::Client.new(@options)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb', line 6

def logger
  @logger
end

#manticoreObject (readonly)

Returns the value of attribute manticore.



6
7
8
# File 'lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb', line 6

def manticore
  @manticore
end

Instance Method Details

#clientObject



22
23
24
# File 'lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb', line 22

def client
  @manticore
end

#closeObject



55
56
57
# File 'lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb', line 55

def close
  @manticore.close
end

#host_unreachable_exceptionsObject



59
60
61
# File 'lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb', line 59

def host_unreachable_exceptions
  [::Manticore::Timeout,::Manticore::SocketException, ::Manticore::ClientProtocolException, ::Manticore::ResolutionFailure, Manticore::SocketTimeout]
end

#perform_request(url, method, path, params = {}, body = nil) ⇒ Response

Performs the request by invoking Transport::Base#perform_request with a block.

Returns:

  • (Response)

See Also:

  • Transport::Base#perform_request


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb', line 31

def perform_request(url, method, path, params={}, body=nil)
  params = (params || {}).merge @request_options
  params[:body] = body if body
  # Convert URI object to string
  url_and_path = path ? (url + path).to_s  : url.to_s

  resp = @manticore.send(method.downcase, url_and_path, params)

  # Manticore returns lazy responses by default
  # We want to block for our usage, this will wait for the repsonse
  # to finish
  resp.call

  # 404s are excluded because they are valid codes in the case of
  # template installation. We might need a better story around this later
  # but for our current purposes this is correct
  if resp.code < 200 || resp.code > 299 && resp.code != 404
    safe_url = ::LogStash::Outputs::ElasticSearch::SafeURL.without_credentials(url)
    raise ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError.new(resp.code, safe_url + path, resp.body)
  end

  resp
end