This repository has been archived by the owner on Oct 5, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
instrument elastic searchable queries
- Loading branch information
Ryan Sonnek
committed
Feb 29, 2012
1 parent
0b338b3
commit 2b3376c
Showing
2 changed files
with
47 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module ElasticSearchable | ||
class LogSubscriber < ActiveSupport::LogSubscriber | ||
def query(event) | ||
return unless logger.debug? | ||
|
||
name = '%s (%.1fms)' % ["ElasticSearchable Query", event.duration] | ||
|
||
params = event.payload[:query].merge event.payload[:options] | ||
# produces: 'query: "foo" OR "bar", rows: 3, ...' | ||
options = params.map{ |k, v| "#{k}: #{color(v, BOLD, true)}" }.join(', ') | ||
|
||
debug " #{color(name, YELLOW, true)} [ #{query} ]" | ||
end | ||
end | ||
|
||
module ControllerRuntime | ||
extend ActiveSupport::Concern | ||
|
||
protected | ||
def append_info_to_payload(payload) | ||
super | ||
payload[:elastic_searchable_runtime] = ElasticSearchable::LogSubscriber.runtime | ||
end | ||
|
||
module ClassMethods | ||
def log_process_action(payload) | ||
messages, elastic_searchable_runtime = super, payload[:elastic_searchable_runtime] | ||
messages << ("ElasticSearchable: %.1fms" % elastic_searchable_runtime.to_f) if elastic_searchable_runtime | ||
messages | ||
end | ||
end | ||
end | ||
end | ||
ElasticSearchable::LogSubscriber.attach_to :elastic_searchable | ||
ActiveSupport.on_load(:action_controller) do | ||
include ElasticSearchable::ControllerRuntime | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters