Commit 769668bbe51374ff5a44b2c5011c7a24c6a4facf
1 parent
6ae46e9e
Exists in
master
and in
21 other branches
Fixed error with instrumentation for searching multiple models
Showing
4 changed files
with
11 additions
and
4 deletions
Show diff stats
CHANGELOG.md
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | - Added `multi_search` method |
4 | 4 | - Added support for routing for Elasticsearch 2 |
5 | 5 | - Added support for `search_document_id` and `search_document_type` in models |
6 | +- Fixed error with instrumentation for searching multiple models | |
6 | 7 | - Fixed instrumentation for bulk updates |
7 | 8 | |
8 | 9 | ## 1.2.0 | ... | ... |
lib/searchkick.rb
... | ... | @@ -9,7 +9,7 @@ require "searchkick/reindex_job" |
9 | 9 | require "searchkick/model" |
10 | 10 | require "searchkick/tasks" |
11 | 11 | require "searchkick/middleware" |
12 | -require "searchkick/logging" if defined?(Rails) | |
12 | +require "searchkick/logging" if defined?(ActiveSupport::Notifications) | |
13 | 13 | |
14 | 14 | # background jobs |
15 | 15 | begin | ... | ... |
lib/searchkick/logging.rb
1 | 1 | # based on https://gist.github.com/mnutt/566725 |
2 | +require "active_support/core_ext/module/attr_internal" | |
2 | 3 | |
3 | 4 | module Searchkick |
4 | 5 | module QueryWithInstrumentation |
5 | 6 | def execute_search |
7 | + name = searchkick_klass ? "#{searchkick_klass.name} Search" : "Search" | |
6 | 8 | event = { |
7 | - name: "#{searchkick_klass.name} Search", | |
9 | + name: name, | |
8 | 10 | query: params |
9 | 11 | } |
10 | 12 | ActiveSupport::Notifications.instrument("search.searchkick", event) do |
... | ... | @@ -29,8 +31,9 @@ module Searchkick |
29 | 31 | end |
30 | 32 | |
31 | 33 | def remove(record) |
34 | + name = record && record.searchkick_klass ? "#{record.searchkick_klass.name} Remove" : "Remove" | |
32 | 35 | event = { |
33 | - name: "#{record.searchkick_klass.name} Remove", | |
36 | + name: name, | |
34 | 37 | id: search_id(record) |
35 | 38 | } |
36 | 39 | if Searchkick.callbacks_value == :bulk | ... | ... |
test/test_helper.rb
... | ... | @@ -4,13 +4,15 @@ require "minitest/autorun" |
4 | 4 | require "minitest/pride" |
5 | 5 | require "logger" |
6 | 6 | require "active_support/core_ext" if defined?(NoBrainer) |
7 | +require "active_support/logger" | |
8 | +require "active_support/notifications" | |
7 | 9 | |
8 | 10 | ENV["RACK_ENV"] = "test" |
9 | 11 | |
10 | 12 | Minitest::Test = Minitest::Unit::TestCase unless defined?(Minitest::Test) |
11 | 13 | |
12 | 14 | File.delete("elasticsearch.log") if File.exist?("elasticsearch.log") |
13 | -Searchkick.client.transport.logger = Logger.new("elasticsearch.log") | |
15 | +Searchkick.client.transport.logger = ActiveSupport::Logger.new("elasticsearch.log") | |
14 | 16 | Searchkick.search_timeout = 5 |
15 | 17 | |
16 | 18 | puts "Running against Elasticsearch #{Searchkick.server_version}" |
... | ... | @@ -18,6 +20,7 @@ puts "Running against Elasticsearch #{Searchkick.server_version}" |
18 | 20 | I18n.config.enforce_available_locales = true |
19 | 21 | |
20 | 22 | ActiveJob::Base.logger = nil if defined?(ActiveJob) |
23 | +# ActiveSupport::LogSubscriber.logger = ActiveSupport::Logger.new(STDOUT) | |
21 | 24 | |
22 | 25 | def elasticsearch2? |
23 | 26 | Searchkick.server_version.starts_with?("2.") | ... | ... |