oboe 2.2.6 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/.gitignore +6 -1
  2. data/Appraisals +20 -0
  3. data/Gemfile +16 -20
  4. data/README.md +280 -10
  5. data/Rakefile +63 -7
  6. data/ext/oboe_metal/extconf.rb +2 -1
  7. data/ext/oboe_metal/tests/test.rb +4 -0
  8. data/gemfiles/rails2.3.gemfile +18 -0
  9. data/gemfiles/rails2.3.gemfile.lock +95 -0
  10. data/gemfiles/rails3.0.gemfile +18 -0
  11. data/gemfiles/rails3.0.gemfile.lock +142 -0
  12. data/gemfiles/rails3.1.gemfile +18 -0
  13. data/gemfiles/rails3.1.gemfile.lock +152 -0
  14. data/gemfiles/rails3.2.gemfile +18 -0
  15. data/gemfiles/rails3.2.gemfile.lock +150 -0
  16. data/init.rb +1 -1
  17. data/lib/joboe_metal.rb +52 -34
  18. data/lib/method_profiling.rb +1 -1
  19. data/lib/oboe.rb +6 -5
  20. data/lib/oboe/api.rb +1 -1
  21. data/lib/oboe/api/layerinit.rb +3 -0
  22. data/lib/oboe/api/logging.rb +1 -1
  23. data/lib/oboe/api/memcache.rb +2 -2
  24. data/lib/oboe/api/profiling.rb +6 -4
  25. data/lib/oboe/api/tracing.rb +1 -1
  26. data/lib/oboe/api/util.rb +1 -1
  27. data/lib/oboe/config.rb +29 -10
  28. data/lib/oboe/frameworks/rails.rb +6 -7
  29. data/lib/oboe/frameworks/rails/inst/action_controller.rb +1 -1
  30. data/lib/oboe/frameworks/rails/inst/action_view.rb +3 -3
  31. data/lib/oboe/frameworks/rails/inst/action_view_2x.rb +3 -3
  32. data/lib/oboe/frameworks/rails/inst/action_view_30.rb +3 -3
  33. data/lib/oboe/frameworks/rails/inst/active_record.rb +1 -1
  34. data/lib/oboe/frameworks/rails/inst/connection_adapters/mysql.rb +1 -1
  35. data/lib/oboe/frameworks/rails/inst/connection_adapters/mysql2.rb +1 -1
  36. data/lib/oboe/frameworks/rails/inst/connection_adapters/oracle.rb +1 -1
  37. data/lib/oboe/frameworks/rails/inst/connection_adapters/postgresql.rb +1 -1
  38. data/lib/oboe/frameworks/rails/inst/connection_adapters/utils.rb +2 -2
  39. data/lib/oboe/inst/cassandra.rb +2 -2
  40. data/lib/oboe/inst/dalli.rb +8 -4
  41. data/lib/oboe/inst/http.rb +38 -34
  42. data/lib/oboe/inst/memcache.rb +12 -3
  43. data/lib/oboe/inst/memcached.rb +10 -5
  44. data/lib/oboe/inst/mongo.rb +19 -15
  45. data/lib/oboe/inst/moped.rb +120 -51
  46. data/lib/oboe/inst/rack.rb +14 -7
  47. data/lib/oboe/inst/resque.rb +2 -2
  48. data/lib/oboe/instrumentation.rb +3 -0
  49. data/lib/oboe/loading.rb +2 -6
  50. data/lib/oboe/logger.rb +3 -1
  51. data/lib/oboe/ruby.rb +3 -0
  52. data/lib/oboe/util.rb +2 -0
  53. data/lib/oboe/version.rb +5 -2
  54. data/lib/oboe_fu.rb +2 -0
  55. data/lib/oboe_metal.rb +23 -10
  56. data/lib/rails/generators/oboe/install_generator.rb +5 -3
  57. data/lib/rails/generators/oboe/templates/oboe_initializer.rb +24 -2
  58. data/oboe.gemspec +20 -14
  59. data/test/instrumentation/cassandra_test.rb +331 -0
  60. data/test/instrumentation/dalli_test.rb +157 -0
  61. data/test/instrumentation/http_test.rb +74 -0
  62. data/test/instrumentation/memcache_test.rb +251 -0
  63. data/test/instrumentation/memcached_test.rb +218 -0
  64. data/test/instrumentation/mongo_test.rb +406 -0
  65. data/test/instrumentation/moped_test.rb +468 -0
  66. data/test/instrumentation/rack_test.rb +55 -0
  67. data/test/instrumentation/resque_test.rb +62 -0
  68. data/test/minitest_helper.rb +113 -0
  69. data/test/support/config_test.rb +41 -0
  70. metadata +56 -35
  71. data/Gemfile.lock +0 -103
  72. data/Guardfile +0 -24
  73. data/install.rb +0 -1
  74. data/spec/instrumentation/cassandra_spec.rb +0 -18
  75. data/spec/instrumentation/dalli_spec.rb +0 -14
  76. data/spec/instrumentation/http_spec.rb +0 -14
  77. data/spec/instrumentation/memcache_spec.rb +0 -19
  78. data/spec/instrumentation/memcached_spec.rb +0 -22
  79. data/spec/instrumentation/mongo_spec.rb +0 -29
  80. data/spec/instrumentation/moped_spec.rb +0 -41
  81. data/spec/instrumentation/resque_spec.rb +0 -18
  82. data/spec/spec_helper.rb +0 -15
  83. data/spec/support/config_spec.rb +0 -27
  84. data/spec/support/oboe_spec.rb +0 -4
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 by Tracelytics, Inc.
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
2
  # All rights reserved.
3
3
 
4
4
  module Oboe
@@ -9,20 +9,17 @@ module Oboe
9
9
  @app = app
10
10
  end
11
11
 
12
- def call(env)
12
+ def collect(env)
13
13
  report_kvs = {}
14
- xtrace = nil
15
14
 
16
15
  begin
17
- xtrace = env['HTTP_X_TRACE'] if env.is_a?(Hash)
18
-
19
16
  req = ::Rack::Request.new(env)
20
17
  report_kvs[:SampleRate] = Oboe::Config[:sample_rate]
21
18
  report_kvs[:SampleSource] = Oboe::Config[:sample_source]
22
19
  report_kvs['HTTP-Host'] = req.host
23
20
  report_kvs['Port'] = req.port
24
21
  report_kvs['Proto'] = req.scheme
25
- report_kvs['Query-String'] = req.query_string unless req.query_string.blank?
22
+ report_kvs['Query-String'] = req.query_string unless req.query_string.empty?
26
23
  report_kvs[:URL] = req.path
27
24
  report_kvs[:Method] = req.request_method
28
25
  report_kvs['AJAX'] = true if req.xhr?
@@ -43,11 +40,21 @@ module Oboe
43
40
  # Discard any potential exceptions. Debug log and report whatever we can.
44
41
  Oboe.logger.debug "[oboe/debug] Rack KV collection error: #{e.inspect}"
45
42
  end
43
+ report_kvs
44
+ end
45
+
46
+ def call(env)
47
+ report_kvs = {}
48
+ xtrace = env.is_a?(Hash) ? env['HTTP_X_TRACE'] : nil
46
49
 
47
50
  result, xtrace = Oboe::API.start_trace('rack', xtrace, report_kvs) do
48
51
 
49
52
  status, headers, response = @app.call(env)
50
- Oboe::API.log(nil, 'info', { :Status => status })
53
+
54
+ if Oboe.tracing?
55
+ report_kvs = collect(env)
56
+ Oboe::API.log(nil, 'info', report_kvs.merge!({ :Status => status }))
57
+ end
51
58
 
52
59
  [status, headers, response]
53
60
  end
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2013 by Tracelytics, Inc.
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
2
  # All rights reserved.
3
3
 
4
4
  require 'socket'
@@ -29,7 +29,7 @@ module Oboe
29
29
  end
30
30
  end
31
31
 
32
- report_kvs[:Backtrace] = Oboe::API.backtrace
32
+ report_kvs[:Backtrace] = Oboe::API.backtrace if Oboe::Config[:resque][:collect_backtraces]
33
33
  rescue
34
34
  end
35
35
 
@@ -1,3 +1,6 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
3
+
1
4
  module Oboe
2
5
  module Inst
3
6
  def self.load_instrumentation
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 by Tracelytics, Inc.
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
2
  # All rights reserved.
3
3
 
4
4
  require 'digest/sha1'
@@ -78,8 +78,6 @@ module Oboe
78
78
  # Load the oboe tracing API
79
79
  #
80
80
  def self.require_api
81
- require 'oboe/version'
82
-
83
81
  pattern = File.join(File.dirname(__FILE__), 'api', '*.rb')
84
82
  Dir.glob(pattern) do |f|
85
83
  require f
@@ -91,8 +89,6 @@ module Oboe
91
89
  rescue LoadError => e
92
90
  Oboe.logger.fatal "[oboe/error] Couldn't load oboe api."
93
91
  end
94
-
95
- require 'oboe/config'
96
92
  end
97
93
 
98
94
  ##
@@ -114,5 +110,5 @@ end
114
110
 
115
111
  Oboe::Loading.require_api
116
112
  Oboe::Loading.load_framework_instrumentation
117
- Oboe::API.report_init('ruby')
113
+ Oboe::Reporter.start
118
114
 
@@ -1,6 +1,8 @@
1
- # Copyright (c) 2013 by AppNeta
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
2
  # All rights reserved.
3
3
 
4
+ require 'logger'
5
+
4
6
  module Oboe
5
7
  class << self
6
8
  attr_accessor :logger
@@ -1,3 +1,6 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
3
+
1
4
  module Oboe
2
5
  module Ruby
3
6
  def self.initialize
@@ -1,3 +1,5 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
1
3
 
2
4
  module Oboe
3
5
  module Util
@@ -1,8 +1,11 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
3
+
1
4
  module Oboe
2
5
  module Version
3
6
  MAJOR = 2
4
- MINOR = 2
5
- PATCH = 6
7
+ MINOR = 3
8
+ PATCH = 2
6
9
  BUILD = nil
7
10
 
8
11
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
@@ -1,3 +1,5 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
1
3
 
2
4
  puts "[oboe_fu] This gem has been deprecated. Please use the 'oboe' gem instead."
3
5
  require 'oboe'
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2012 by Tracelytics, Inc.
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
2
  # All rights reserved.
3
3
 
4
4
  module Oboe_metal
@@ -12,7 +12,7 @@ module Oboe_metal
12
12
  class << self
13
13
  attr_accessor :layer_op
14
14
 
15
- def log(layer, label, options = {}, with_backtrace = true)
15
+ def log(layer, label, options = {}, with_backtrace = false)
16
16
  evt = Oboe::Context.createEvent()
17
17
  evt.addInfo("Layer", layer.to_s)
18
18
  evt.addInfo("Label", label.to_s)
@@ -37,6 +37,27 @@ module Oboe_metal
37
37
  end
38
38
 
39
39
  module Reporter
40
+ ##
41
+ # Initialize the Oboe Context, reporter and report the initialization
42
+ #
43
+ def self.start
44
+ begin
45
+ Oboe_metal::Context.init()
46
+
47
+ if ENV['RACK_ENV'] == "test"
48
+ Oboe.reporter = Oboe::FileReporter.new("./tmp/trace_output.bson")
49
+ else
50
+ Oboe.reporter = Oboe::UdpReporter.new(Oboe::Config[:reporter_host])
51
+ end
52
+
53
+ Oboe::API.report_init('ruby') unless ["development", "test"].include? ENV['RACK_ENV']
54
+
55
+ rescue Exception => e
56
+ $stderr.puts e.message
57
+ raise
58
+ end
59
+ end
60
+
40
61
  def self.sendReport(evt)
41
62
  Oboe.reporter.sendReport(evt)
42
63
  end
@@ -83,12 +104,4 @@ module Oboe
83
104
  end
84
105
  end
85
106
 
86
- begin
87
- Oboe_metal::Context.init()
88
- Oboe.reporter = Oboe::UdpReporter.new("127.0.0.1")
89
-
90
- rescue Exception => e
91
- $stderr.puts e.message
92
- raise
93
- end
94
107
 
@@ -1,3 +1,5 @@
1
+ # Copyright (c) 2013 AppNeta, Inc.
2
+ # All rights reserved.
1
3
 
2
4
  module Oboe
3
5
  class InstallGenerator < ::Rails::Generators::Base
@@ -7,18 +9,18 @@ module Oboe
7
9
  def copy_initializer
8
10
  # Set defaults
9
11
  @tracing_mode = 'through'
10
- @sampling_rate = '300000'
12
+ @sample_rate = '300000'
11
13
  @verbose = 'false'
12
14
 
13
15
  say ""
14
16
  say shell.set_color "Welcome to the TraceView Ruby instrumentation setup.", :green, :bold
15
17
  say ""
16
- say "To instrument your Rails application, you have the option to setup sampling strategies here."
18
+ say "To instrument your Rails application, you can setup your tracing strategy here."
17
19
  say ""
18
20
  say shell.set_color "Documentation Links", :magenta
19
21
  say "-------------------"
20
22
  say ""
21
- say "Details on configuring your sampling rate:"
23
+ say "Details on configuring your sample rate:"
22
24
  say "http://support.tv.appneta.com/support/solutions/articles/86336-configuring-sampling"
23
25
  say ""
24
26
  say "More information on instrumenting Ruby applications can be found here:"
@@ -1,7 +1,7 @@
1
1
  # AppNeta TraceView Initializer (the oboe gem)
2
2
  # http://www.appneta.com/products/traceview/
3
3
  #
4
- # Details on configuring your sampling rate:
4
+ # Details on configuring your sample rate:
5
5
  # http://support.tv.appneta.com/support/solutions/articles/86336
6
6
  #
7
7
  # More information on instrumenting Ruby applications can be found here:
@@ -16,7 +16,7 @@ if defined?(Oboe::Config)
16
16
  Oboe::Config[:tracing_mode] = '<%= @tracing_mode %>'
17
17
 
18
18
  # sample_rate is a value from 0 - 1m indicating the fraction of requests per million to trace
19
- # Oboe::Config[:sample_rate] = <%= @sampling_rate %>
19
+ # Oboe::Config[:sample_rate] = <%= @sample_rate %>
20
20
 
21
21
  # Verbose output of instrumentation initialization
22
22
  # Oboe::Config[:verbose] = <%= @verbose %>
@@ -56,5 +56,27 @@ if defined?(Oboe::Config)
56
56
  # Oboe::Config[:memcached][:enabled] = true
57
57
  # Oboe::Config[:mongo][:enabled] = true
58
58
  # Oboe::Config[:moped][:enabled] = true
59
+ # Oboe::Config[:nethttp][:enabled] = true
59
60
  # Oboe::Config[:resque][:enabled] = true
61
+
62
+ #
63
+ # Enabling/Disabling Backtrace Collection
64
+ #
65
+ # Instrumentation can optionally collect backtraces as they collect
66
+ # performance metrics. Note that this has a negative impact on
67
+ # performance but can be useful when trying to locate the source of
68
+ # a certain call or operation.
69
+ #
70
+ # Oboe::Config[:action_controller][:collect_backtraces] = true
71
+ # Oboe::Config[:active_record][:collect_backtraces] = true
72
+ # Oboe::Config[:action_view][:collect_backtraces] = true
73
+ # Oboe::Config[:cassandra][:collect_backtraces] = true
74
+ # Oboe::Config[:dalli][:collect_backtraces] = false
75
+ # Oboe::Config[:memcache][:collect_backtraces] = false
76
+ # Oboe::Config[:memcached][:collect_backtraces] = false
77
+ # Oboe::Config[:mongo][:collect_backtraces] = true
78
+ # Oboe::Config[:moped][:collect_backtraces] = true
79
+ # Oboe::Config[:nethttp][:collect_backtraces] = true
80
+ # Oboe::Config[:resque][:collect_backtraces] = true
81
+ #
60
82
  end
@@ -2,18 +2,24 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
  require "oboe/version"
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.name = %q{oboe}
6
- s.version = Oboe::Version::STRING
7
- s.date = Time.now.strftime('%Y-%m-%d')
8
- s.authors = ["Tracelytics, Inc."]
9
- s.email = %q{contact@tracelytics.com}
10
- s.summary = %q{Tracelytics instrumentation gem}
11
- s.homepage = %q{http://tracelytics.com}
12
- s.description = %q{The oboe gem provides AppNeta instrumentation for Ruby and Ruby frameworks.}
13
- s.extra_rdoc_files = ["LICENSE"]
14
- s.files = `git ls-files`.split("\n")
15
- s.extensions = ['ext/oboe_metal/extconf.rb']
16
- s.test_files = Dir.glob("{spec}/**/*.rb")
17
- s.add_development_dependency 'rake'
18
- s.add_development_dependency 'rspec'
5
+ s.name = %q{oboe}
6
+ s.version = Oboe::Version::STRING
7
+ s.date = Time.now.strftime('%Y-%m-%d')
8
+
9
+ s.authors = ["Peter Giacomo Lombardo", "Spiros Eliopoulos"]
10
+ s.email = %q{traceviewsupport@appneta.com}
11
+ s.homepage = %q{http://www.appneta.com/application-performance-management}
12
+ s.summary = %q{AppNeta TraceView performance instrumentation gem for Ruby}
13
+ s.description = %q{The oboe gem provides TraceView instrumentation for Ruby and Ruby frameworks.}
14
+
15
+ s.extra_rdoc_files = ["LICENSE"]
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = Dir.glob("{test}/**/*.rb")
18
+
19
+ s.extensions = ['ext/oboe_metal/extconf.rb']
20
+
21
+ s.add_development_dependency 'rake'
22
+ s.add_development_dependency 'minitest'
23
+ s.add_development_dependency 'bson'
19
24
  end
25
+
@@ -0,0 +1,331 @@
1
+ require 'minitest_helper'
2
+
3
+ describe Oboe::Inst::Cassandra do
4
+ before do
5
+ clear_all_traces
6
+
7
+ @client = Cassandra.new('TRCassInstr', '127.0.0.1:9160',
8
+ :retries => 2, :connect_timeout => 1,
9
+ :timeout => 5)
10
+ @client.disable_node_auto_discovery!
11
+
12
+ # These are standard entry/exit KVs that are passed up with all mongo operations
13
+ @entry_kvs = {
14
+ 'Layer' => 'cassandra',
15
+ 'Label' => 'entry',
16
+ 'RemoteHost' => '127.0.0.1',
17
+ 'RemotePort' => '9160' }
18
+
19
+ @exit_kvs = { 'Layer' => 'cassandra', 'Label' => 'exit' }
20
+ @collect_backtraces = Oboe::Config[:cassandra][:collect_backtraces]
21
+ end
22
+
23
+ after do
24
+ Oboe::Config[:cassandra][:collect_backtraces] = @collect_backtraces
25
+ @client.disconnect!
26
+ end
27
+
28
+ it 'Stock Cassandra should be loaded, defined and ready' do
29
+ defined?(::Cassandra).wont_match nil
30
+ end
31
+
32
+ it 'Cassandra should have oboe methods defined' do
33
+ [ :insert, :remove, :count_columns, :get_columns, :multi_get_columns, :get,
34
+ :multi_get, :get_range_single, :get_range_batch, :get_indexed_slices,
35
+ :create_index, :drop_index, :add_column_family, :drop_column_family,
36
+ :add_keyspace, :drop_keyspace ].each do |m|
37
+ ::Cassandra.method_defined?("#{m}_with_oboe").must_equal true
38
+ end
39
+ # Special 'exists?' case
40
+ ::Cassandra.method_defined?("exists_with_oboe?").must_equal true
41
+ end
42
+
43
+ it 'should trace insert' do
44
+ Oboe::API.start_trace('cassandra_test', '', {}) do
45
+ user = {'screen_name' => 'larry', "blah" => "ok"}
46
+ @client.insert(:Users, '5', user, { :ttl => 600, :consistency => 1})
47
+ end
48
+
49
+ traces = get_all_traces
50
+
51
+ traces.count.must_equal 4
52
+ validate_outer_layers(traces, 'cassandra_test')
53
+
54
+ validate_event_keys(traces[1], @entry_kvs)
55
+ traces[1]['Op'].must_equal "insert"
56
+ traces[1]['Cf'].must_equal "Users"
57
+ traces[1]['Key'].must_equal "5"
58
+ traces[1]['Consistency'].must_equal "1"
59
+ traces[1]['Ttl'].must_equal "600"
60
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
61
+ validate_event_keys(traces[2], @exit_kvs)
62
+ end
63
+
64
+ it 'should trace remove' do
65
+ Oboe::API.start_trace('cassandra_test', '', {}) do
66
+ @client.remove(:Users, '5', 'blah')
67
+ end
68
+
69
+ traces = get_all_traces
70
+
71
+ traces.count.must_equal 4
72
+ validate_outer_layers(traces, 'cassandra_test')
73
+
74
+ validate_event_keys(traces[1], @entry_kvs)
75
+ traces[1]['Op'].must_equal "remove"
76
+ traces[1]['Cf'].must_equal "Users"
77
+ traces[1]['Key'].must_equal "5"
78
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
79
+ validate_event_keys(traces[2], @exit_kvs)
80
+ end
81
+
82
+ it 'should trace count_columns' do
83
+ @client.insert(:Statuses, '12', {'body' => 'v1', 'user' => 'v2'})
84
+
85
+ Oboe::API.start_trace('cassandra_test', '', {}) do
86
+ @client.count_columns(:Statuses, '12', :count => 50)
87
+ end
88
+
89
+ traces = get_all_traces
90
+
91
+ traces.count.must_equal 4
92
+ validate_outer_layers(traces, 'cassandra_test')
93
+
94
+ validate_event_keys(traces[1], @entry_kvs)
95
+ traces[1]['Op'].must_equal "count_columns"
96
+ traces[1]['Cf'].must_equal "Statuses"
97
+ traces[1]['Key'].must_equal "12"
98
+ traces[1]['Count'].must_equal "50"
99
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
100
+ validate_event_keys(traces[2], @exit_kvs)
101
+ end
102
+
103
+ it 'should trace get_columns' do
104
+ Oboe::API.start_trace('cassandra_test', '', {}) do
105
+ @client.get_columns(:Statuses, '12', ['body'])
106
+ end
107
+
108
+ traces = get_all_traces
109
+
110
+ traces.count.must_equal 4
111
+ validate_outer_layers(traces, 'cassandra_test')
112
+
113
+ validate_event_keys(traces[1], @entry_kvs)
114
+ traces[1]['Op'].must_equal "get_columns"
115
+ traces[1]['Cf'].must_equal "Statuses"
116
+ traces[1]['Key'].must_equal "12"
117
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
118
+ validate_event_keys(traces[2], @exit_kvs)
119
+ end
120
+
121
+ it 'should trace multi_get_columns' do
122
+ Oboe::API.start_trace('cassandra_test', '', {}) do
123
+ @client.multi_get_columns(:Users, ['12', '5'], ['body'])
124
+ end
125
+
126
+ traces = get_all_traces
127
+
128
+ traces.count.must_equal 4
129
+ validate_outer_layers(traces, 'cassandra_test')
130
+
131
+ validate_event_keys(traces[1], @entry_kvs)
132
+ traces[1]['Op'].must_equal "multi_get_columns"
133
+ traces[1]['Cf'].must_equal "Users"
134
+ traces[1]['Key'].must_equal "[\"12\", \"5\"]"
135
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
136
+ validate_event_keys(traces[2], @exit_kvs)
137
+ end
138
+
139
+ it 'should trace get' do
140
+ Oboe::API.start_trace('cassandra_test', '', {}) do
141
+ @client.get(:Statuses, '12', :reversed => true)
142
+ end
143
+
144
+ traces = get_all_traces
145
+
146
+ traces.count.must_equal 4
147
+ validate_outer_layers(traces, 'cassandra_test')
148
+
149
+ validate_event_keys(traces[1], @entry_kvs)
150
+ traces[1]['Op'].must_equal "get"
151
+ traces[1]['Cf'].must_equal "Statuses"
152
+ traces[1]['Key'].must_equal "12"
153
+ traces[1]['Reversed'].must_equal "true"
154
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
155
+ validate_event_keys(traces[2], @exit_kvs)
156
+ end
157
+
158
+ it 'should trace exists?' do
159
+ Oboe::API.start_trace('cassandra_test', '', {}) do
160
+ @client.exists?(:Statuses, '12')
161
+ @client.exists?(:Statuses, '12', 'body')
162
+ end
163
+
164
+ traces = get_all_traces
165
+
166
+ traces.count.must_equal 6
167
+ validate_outer_layers(traces, 'cassandra_test')
168
+
169
+ validate_event_keys(traces[1], @entry_kvs)
170
+ traces[1]['Op'].must_equal "exists?"
171
+ traces[1]['Cf'].must_equal "Statuses"
172
+ traces[1]['Key'].must_equal "12"
173
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
174
+ validate_event_keys(traces[2], @exit_kvs)
175
+
176
+ traces[3]['Op'].must_equal "exists?"
177
+ traces[3]['Cf'].must_equal "Statuses"
178
+ traces[3]['Key'].must_equal "12"
179
+ traces[3].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
180
+ end
181
+
182
+ it 'should trace get_range_keys' do
183
+ Oboe::API.start_trace('cassandra_test', '', {}) do
184
+ @client.get_range_keys(:Statuses, :key_count => 4)
185
+ end
186
+
187
+ traces = get_all_traces
188
+
189
+ traces.count.must_equal 4
190
+ validate_outer_layers(traces, 'cassandra_test')
191
+
192
+ validate_event_keys(traces[1], @entry_kvs)
193
+ traces[1]['Op'].must_equal "get_range_batch"
194
+ traces[1]['Cf'].must_equal "Statuses"
195
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
196
+ validate_event_keys(traces[2], @exit_kvs)
197
+ end
198
+
199
+ it 'should trace create_index and drop_index' do
200
+ Oboe::API.start_trace('cassandra_test', '', {}) do
201
+ @client.create_index('TRCassInstr', 'Statuses', 'x', 'LongType')
202
+ @client.drop_index('TRCassInstr', 'Statuses', 'x')
203
+ end
204
+
205
+ traces = get_all_traces
206
+
207
+ traces.count.must_equal 6
208
+ validate_outer_layers(traces, 'cassandra_test')
209
+
210
+ validate_event_keys(traces[1], @entry_kvs)
211
+ traces[1]['Op'].must_equal "create_index"
212
+ traces[1]['Cf'].must_equal "Statuses"
213
+ traces[1]['Keyspace'].must_equal "TRCassInstr"
214
+ traces[1]['Column_name'].must_equal "x"
215
+ traces[1]['Validation_class'].must_equal "LongType"
216
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
217
+ validate_event_keys(traces[2], @exit_kvs)
218
+
219
+ validate_event_keys(traces[3], @entry_kvs)
220
+ traces[3]['Op'].must_equal "drop_index"
221
+ traces[3]['Cf'].must_equal "Statuses"
222
+ traces[3]['Keyspace'].must_equal "TRCassInstr"
223
+ traces[3]['Column_name'].must_equal "x"
224
+ traces[3].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
225
+ validate_event_keys(traces[4], @exit_kvs)
226
+ end
227
+
228
+ it 'should trace get_indexed_slices' do
229
+ @client.create_index('TRCassInstr', 'Statuses', 'x', 'LongType')
230
+ Oboe::API.start_trace('cassandra_test', '', {}) do
231
+ expressions = [
232
+ { :column_name => 'x',
233
+ :value => [0,20].pack("NN"),
234
+ :comparison => "=="},
235
+ { :column_name => 'non_indexed',
236
+ :value => [5].pack("N*"),
237
+ :comparison => ">"} ]
238
+ @client.get_indexed_slices(:Statuses, expressions).length
239
+ end
240
+
241
+ traces = get_all_traces
242
+
243
+ traces.count.must_equal 4
244
+ validate_outer_layers(traces, 'cassandra_test')
245
+
246
+ validate_event_keys(traces[1], @entry_kvs)
247
+ traces[1]['Op'].must_equal "get_indexed_slices"
248
+ traces[1]['Cf'].must_equal "Statuses"
249
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
250
+ validate_event_keys(traces[2], @exit_kvs)
251
+ end
252
+
253
+ it 'should trace add and remove of column family' do
254
+ cf_name = (0...10).map{ ('a'..'z').to_a[rand(26)] }.join
255
+ cf_def = CassandraThrift::CfDef.new(:keyspace => "TRCassInstr", :name => cf_name)
256
+
257
+ Oboe::API.start_trace('cassandra_test', '', {}) do
258
+ @client.add_column_family(cf_def)
259
+ @client.drop_column_family(cf_name)
260
+ end
261
+
262
+ traces = get_all_traces
263
+
264
+ traces.count.must_equal 6
265
+ validate_outer_layers(traces, 'cassandra_test')
266
+
267
+ validate_event_keys(traces[1], @entry_kvs)
268
+ traces[1]['Op'].must_equal "add_column_family"
269
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
270
+ validate_event_keys(traces[2], @exit_kvs)
271
+
272
+ traces[3]['Op'].must_equal "drop_column_family"
273
+ traces[3]['Cf'].must_equal cf_name
274
+ traces[3].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
275
+ end
276
+
277
+ it 'should trace add and remove of keyspace' do
278
+ ks_name = (0...10).map{ ('a'..'z').to_a[rand(26)] }.join
279
+ column_families = [{:name =>"a"}, {:name => "b", :type => :super}]
280
+ ks_def = CassandraThrift::KsDef.new(:name => ks_name,
281
+ :strategy_class => "org.apache.cassandra.locator.SimpleStrategy",
282
+ :replication_factor => 1,
283
+ :cf_defs => [])
284
+
285
+ Oboe::API.start_trace('cassandra_test', '', {}) do
286
+ @client.add_keyspace(ks_def)
287
+ @client.keyspace = ks_name
288
+ @client.drop_keyspace(ks_name)
289
+ end
290
+
291
+ traces = get_all_traces
292
+
293
+ traces.count.must_equal 6
294
+ validate_outer_layers(traces, 'cassandra_test')
295
+
296
+ validate_event_keys(traces[1], @entry_kvs)
297
+ traces[1]['Op'].must_equal "add_keyspace"
298
+ traces[1]['Name'].must_equal ks_name
299
+ traces[1].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
300
+ validate_event_keys(traces[2], @exit_kvs)
301
+
302
+ traces[3]['Op'].must_equal "drop_keyspace"
303
+ traces[3]['Name'].must_equal ks_name
304
+ traces[3].has_key?('Backtrace').must_equal Oboe::Config[:cassandra][:collect_backtraces]
305
+ end
306
+
307
+ it "should obey :collect_backtraces setting when true" do
308
+ Oboe::Config[:cassandra][:collect_backtraces] = true
309
+
310
+ Oboe::API.start_trace('cassandra_test', '', {}) do
311
+ user = {'screen_name' => 'larry', "blah" => "ok"}
312
+ @client.insert(:Users, '5', user, { :ttl => 600, :consistency => 1})
313
+ end
314
+
315
+ traces = get_all_traces
316
+ layer_has_key(traces, 'cassandra', 'Backtrace')
317
+ end
318
+
319
+ it "should obey :collect_backtraces setting when false" do
320
+ Oboe::Config[:cassandra][:collect_backtraces] = false
321
+
322
+ Oboe::API.start_trace('cassandra_test', '', {}) do
323
+ user = {'screen_name' => 'larry', "blah" => "ok"}
324
+ @client.insert(:Users, '5', user, { :ttl => 600, :consistency => 1})
325
+ end
326
+
327
+ traces = get_all_traces
328
+ layer_doesnt_have_key(traces, 'cassandra', 'Backtrace')
329
+ end
330
+
331
+ end