Sha256: 4ea0abcc1f314cd485aabd26fb7b43dfc3b61ce5a9beee26ac30caec0caaec38

Contents?: true

Size: 1.1 KB

Versions: 22

Compression:

Stored size: 1.1 KB

Contents

module Elasticity
  class InstrumentedClient
    INDICES_METHODS = %w(exists create delete get_settings get_mapping flush 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

    # 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

22 entries across 22 versions & 1 rubygems

Version Path
es-elasticity-0.11.5 lib/elasticity/instrumented_client.rb
es-elasticity-0.11.1 lib/elasticity/instrumented_client.rb
es-elasticity-0.9.0 lib/elasticity/instrumented_client.rb
es-elasticity-0.8.4 lib/elasticity/instrumented_client.rb
es-elasticity-0.8.3 lib/elasticity/instrumented_client.rb
es-elasticity-0.8.2 lib/elasticity/instrumented_client.rb
es-elasticity-0.8.1 lib/elasticity/instrumented_client.rb
es-elasticity-0.8.0 lib/elasticity/instrumented_client.rb
es-elasticity-0.7.1 lib/elasticity/instrumented_client.rb
es-elasticity-0.7.0 lib/elasticity/instrumented_client.rb
es-elasticity-0.6.5 lib/elasticity/instrumented_client.rb
es-elasticity-0.6.4 lib/elasticity/instrumented_client.rb
es-elasticity-0.6.3 lib/elasticity/instrumented_client.rb
es-elasticity-0.6.2 lib/elasticity/instrumented_client.rb
es-elasticity-0.6.1 lib/elasticity/instrumented_client.rb
es-elasticity-0.6.0 lib/elasticity/instrumented_client.rb
es-elasticity-0.5.2 lib/elasticity/instrumented_client.rb
es-elasticity-0.5.1 lib/elasticity/instrumented_client.rb
es-elasticity-0.5.0 lib/elasticity/instrumented_client.rb
es-elasticity-0.4.5 lib/elasticity/instrumented_client.rb