Sha256: 2bd99a574dbb4129a077343934d19fba4e7225e62bc59c6325a3116ed8598901

Contents?: true

Size: 1.23 KB

Versions: 15

Compression:

Stored size: 1.23 KB

Contents

module Elasticity
  class InstrumentedClient
    INDICES_METHODS = %w(exists create delete get_settings get_mapping flush refresh get_alias get_aliases put_alias delete_alias exists_alias update_aliases)
    INDEX_METHODS   = %w(index delete get mget search count msearch scroll delete_by_query bulk)

    def initialize(client)
      @client = client
    end

    def versions
      (@client.cluster.stats["nodes"] && @client.cluster.stats["nodes"]["versions"]) || []
    end

    # Generate wrapper methods for @client.indices
    INDICES_METHODS.each do |method_name|
      full_name = "index_#{method_name}"

      define_method(full_name) do |*args, &block|
        instrument(full_name, args) do
          @client.indices.public_send(method_name, *args, &block)
        end
      end
    end

    # Generate wrapper methods for @client
    INDEX_METHODS.each do |method_name|
      define_method(method_name) do |*args, &block|
        instrument(method_name, args) do
          @client.public_send(method_name, *args, &block)
        end
      end
    end

    private

    def instrument(name, args)
      ActiveSupport::Notifications.instrument("#{name}.elasticity", args: args, backtrace: caller(1)) do
        yield
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
es-elasticity-1.2.1 lib/elasticity/instrumented_client.rb
es-elasticity-1.1.0 lib/elasticity/instrumented_client.rb
es-elasticity-1.0.1 lib/elasticity/instrumented_client.rb
es-elasticity-0.14.1 lib/elasticity/instrumented_client.rb
es-elasticity-0.14.0 lib/elasticity/instrumented_client.rb
es-elasticity-0.14.0.jhumphreys lib/elasticity/instrumented_client.rb
es-elasticity-0.13.5 lib/elasticity/instrumented_client.rb
es-elasticity-0.13.5.dblackmon.1 lib/elasticity/instrumented_client.rb
es-elasticity-0.13.4 lib/elasticity/instrumented_client.rb
es-elasticity-0.13.4.zpesic lib/elasticity/instrumented_client.rb
es-elasticity-0.13.4.dblackmon.1 lib/elasticity/instrumented_client.rb
es-elasticity-0.13.4.dblackmon.0 lib/elasticity/instrumented_client.rb
es-elasticity-0.13.4.dblackmon lib/elasticity/instrumented_client.rb
es-elasticity-0.13.3 lib/elasticity/instrumented_client.rb
es-elasticity-0.13.3.pre1 lib/elasticity/instrumented_client.rb