Sha256: b340a4789bf3b1bc1080866bb04a8a7df65b5ea7c8fd6a4602cf7385b692597d

Contents?: true

Size: 1.65 KB

Versions: 52

Compression:

Stored size: 1.65 KB

Contents

module Elasticsearch
  module Transport
    module Transport

      # Handles node discovery ("sniffing")
      #
      class Sniffer
        PROTOCOL = 'http'

        attr_reader   :transport
        attr_accessor :timeout

        # @param transport [Object] A transport instance
        #
        def initialize(transport)
          @transport = transport
          @timeout   = transport.options[:sniffer_timeout] || 1
        end

        # Retrieves the node list from the Elasticsearch's
        # [_Nodes Info API_](http://www.elasticsearch.org/guide/reference/api/admin-cluster-nodes-info/)
        # and returns a normalized Array of information suitable for passing to transport.
        #
        # Shuffles the collection before returning it when the `randomize_hosts` option is set for transport.
        #
        # @return [Array<Hash>]
        # @raise  [SnifferTimeoutError]
        #
        def hosts
          Timeout::timeout(timeout, SnifferTimeoutError) do
            nodes = transport.perform_request('GET', '_nodes/http').body

            hosts = nodes['nodes'].map do |id,info|
              if info[PROTOCOL]
                host, port = info[PROTOCOL]['publish_address'].split(':')

                { :id =>      id,
                  :name =>    info['name'],
                  :version => info['version'],
                  :host =>    host,
                  :port =>    port,
                  :roles =>   info['roles'],
                  :attributes => info['attributes'] }
              end
            end.compact

            hosts.shuffle! if transport.options[:randomize_hosts]
            hosts
          end
        end
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 6 rubygems

Version Path
logstash-output-scalyr-0.1.9 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/sniffer.rb
logstash-output-scalyr-0.1.8 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/sniffer.rb
logstash-output-scalyr-0.1.7 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/sniffer.rb
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/sniffer.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/sniffer.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/sniffer.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/sniffer.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/sniffer.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/sniffer.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/sniffer.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/sniffer.rb
elasticsearch-transport-6.8.1 lib/elasticsearch/transport/transport/sniffer.rb
elasticsearch-transport-6.8.0 lib/elasticsearch/transport/transport/sniffer.rb
elasticsearch-transport-6.3.1 lib/elasticsearch/transport/transport/sniffer.rb
elasticsearch-transport-6.3.0 lib/elasticsearch/transport/transport/sniffer.rb
elasticsearch-transport-6.2.0 lib/elasticsearch/transport/transport/sniffer.rb
logstash-filter-device_detection-1.0.7-java vendor/bundle/jruby/1.9/gems/elasticsearch-transport-5.0.5/lib/elasticsearch/transport/transport/sniffer.rb
elasticsearch-transport-6.1.0 lib/elasticsearch/transport/transport/sniffer.rb
elasticsearch-transport-6.0.3 lib/elasticsearch/transport/transport/sniffer.rb
elasticsearch-transport-5.0.5 lib/elasticsearch/transport/transport/sniffer.rb