Sha256: 73c5a399c9068da0a9ff3d32e223143f02057175861d9dcee766bebf346c89d7

Contents?: true

Size: 1.03 KB

Versions: 7

Compression:

Stored size: 1.03 KB

Contents

module Elasticity
  class InstrumentedClient
    def initialize(client)
      @client = client
    end

    # Generate wrapper methods for @client.indices
    %w(exists create delete get_settings get_mapping flush get_alias get_aliases put_alias delete_alias exists_alias update_aliases).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
    %w(index delete get mget search count msearch scroll delete_by_query bulk).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

7 entries across 7 versions & 1 rubygems

Version Path
es-elasticity-0.4.2 lib/elasticity/instrumented_client.rb
es-elasticity-0.3.10 lib/elasticity/instrumented_client.rb
es-elasticity-0.4.1 lib/elasticity/instrumented_client.rb
es-elasticity-0.4.0 lib/elasticity/instrumented_client.rb
es-elasticity-0.3.9 lib/elasticity/instrumented_client.rb
es-elasticity-0.3.8 lib/elasticity/instrumented_client.rb
es-elasticity-0.3.7 lib/elasticity/instrumented_client.rb