forked from newrelic/rpm_contrib
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request newrelic#22 from niko/master
Added instrumentation for the Picky search engine
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 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
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,41 @@ | ||
if defined?(::Picky) | ||
|
||
class Picky::NewRelic | ||
def self.obfuscate_tokens tokens | ||
tokens.map { |t| | ||
o = 'xxx' | ||
o += '~' if t.similar? | ||
o += '*' if t.partial? | ||
o = t.qualifiers.sort.join(',') + ':' + o if t.qualifiers && t.qualifiers.respond_to?(:join) | ||
o | ||
}.sort.join(' ') | ||
end | ||
end | ||
|
||
end | ||
|
||
DependencyDetection.defer do | ||
@name = :picky | ||
|
||
depends_on do | ||
defined?(::Picky) && !NewRelic::Control.instance['disable_picky'] | ||
end | ||
|
||
executes do | ||
NewRelic::Agent.logger.debug 'Installing Picky instrumentation' | ||
end | ||
|
||
executes do | ||
::Picky::Search.class_eval do | ||
include NewRelic::Agent::MethodTracer | ||
|
||
def execute_with_newrelic_trace *args | ||
metrics = "Custom/Picky/search: #{Picky::NewRelic.obfuscate_tokens args[0]}" | ||
self.class.trace_execution_scoped(metrics){ execute_without_newrelic_trace(*args) } | ||
end | ||
|
||
alias_method :execute_without_newrelic_trace, :execute | ||
alias_method :execute, :execute_with_newrelic_trace | ||
end | ||
end | ||
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
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,55 @@ | ||
require 'picky' | ||
|
||
require "#{File.dirname(__FILE__)}/helper" | ||
|
||
class NewRelic::Agent::PickyIntrumentationTest < Test::Unit::TestCase | ||
|
||
def tokens_for *tokens | ||
tokens.map{|t| | ||
token = 'whatever' | ||
|
||
token.extend Module.new{ | ||
define_method(:'partial?'){ t[:partial] } | ||
define_method(:'similar?'){ t[:similar] } | ||
define_method(:'qualifiers'){ t[:qualifiers] } | ||
} | ||
|
||
token | ||
} | ||
end | ||
|
||
def test_obfuscate_tokens | ||
tokens = tokens_for({}) | ||
assert_equal 'xxx', Picky::NewRelic.obfuscate_tokens(tokens) | ||
|
||
tokens = tokens_for({:similar => true}) | ||
assert_equal 'xxx~', Picky::NewRelic.obfuscate_tokens(tokens) | ||
|
||
tokens = tokens_for({:partial => true}) | ||
assert_equal 'xxx*', Picky::NewRelic.obfuscate_tokens(tokens) | ||
|
||
tokens = tokens_for({:qualifiers => [:haha]}) | ||
assert_equal 'haha:xxx', Picky::NewRelic.obfuscate_tokens(tokens) | ||
|
||
tokens = tokens_for( {:partial => true}, {:similar => true} ) | ||
assert_equal 'xxx* xxx~', Picky::NewRelic.obfuscate_tokens(tokens) | ||
|
||
tokens = tokens_for( {:similar => true}, {:partial => true} ) | ||
assert_equal 'xxx* xxx~', Picky::NewRelic.obfuscate_tokens(tokens) | ||
|
||
tokens = tokens_for( {:partial => true}, {:partial => true} ) | ||
assert_equal 'xxx* xxx*', Picky::NewRelic.obfuscate_tokens(tokens) | ||
|
||
tokens = tokens_for( | ||
{:similar => true, :qualifiers => [:bla]}, | ||
{:partial => true, :qualifiers => [:bla, :blub]} | ||
) | ||
assert_equal 'bla,blub:xxx* bla:xxx~', Picky::NewRelic.obfuscate_tokens(tokens) | ||
|
||
tokens = tokens_for( | ||
{:similar => true, :qualifiers => [:bla]}, | ||
{:partial => true, :qualifiers => [:blub, :bla]} | ||
) | ||
assert_equal 'bla,blub:xxx* bla:xxx~', Picky::NewRelic.obfuscate_tokens(tokens) | ||
end | ||
end |