logical-insight 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,6 +11,7 @@ require "insight/redirect_interceptor"
11
11
  require "insight/render"
12
12
  require "insight/toolbar"
13
13
  require "insight/enable-button"
14
+ require "insight/path-filter"
14
15
  require 'insight/logger'
15
16
  require 'insight/request-recorder'
16
17
  require 'insight/instrumentation/setup'
@@ -46,17 +47,17 @@ module Insight
46
47
  attr_accessor :panels
47
48
 
48
49
  def call(env)
49
- env.replace @default_options.merge(env)
50
- @env = env
51
- @original_request = Rack::Request.new(@env)
52
- env['insight.logger'] = @logger
53
- Thread.current['insight.logger'] = @logger
54
-
50
+ @original_request = Rack::Request.new(env)
55
51
  if insight_active?
52
+ @env = env
53
+ self.options = @default_options
54
+
55
+ env['insight.logger'] = @logger
56
+ Thread.current['insight.logger'] = @logger
57
+
56
58
  Insight.enable
57
59
  env["insight.panels"] = []
58
- result = @debug_stack.call(env)
59
- result
60
+ @debug_stack.call(env)
60
61
  else
61
62
  @normal_stack.call(env)
62
63
  end
@@ -64,6 +65,7 @@ module Insight
64
65
 
65
66
 
66
67
  def reset(new_options=nil)
68
+ @env = nil
67
69
  initialize_options(new_options)
68
70
 
69
71
  Insight::Instrumentation::ClassProbe::all_probes.each do |probe|
@@ -94,7 +96,8 @@ module Insight
94
96
  @panels.clear
95
97
  builder = Rack::Builder.new
96
98
  builder.use Toolbar, self
97
- builder.run Rack::Cascade.new([panel_mappings, collection_stack(@base_app)])
99
+ builder.run Rack::Cascade.new([panel_mappings, shortcut_stack(@base_app), collection_stack(@base_app)])
100
+
98
101
  @debug_stack = builder.to_app
99
102
  end
100
103
 
@@ -120,24 +123,30 @@ module Insight
120
123
  return asset_mapped(builder)
121
124
  end
122
125
 
126
+ def shortcut_stack(app)
127
+ Rack::Builder.app do
128
+ use PathFilter
129
+ run app
130
+ end
131
+ end
123
132
 
124
133
  def collection_stack(app)
125
134
  classes = read_option(:panel_classes)
126
135
  insight_id = self.object_id
127
136
  panels = self.panels
128
- Rack::Builder.app do
129
- use RequestRecorder
130
- classes.each do |panel_class|
131
- run(lambda do |app|
132
- panel = panel_class.new(app)
133
- panels << panel
134
- panel
135
- end)
136
- end
137
- use RedirectInterceptor
138
- use Instrumentation::Setup
139
- run app
137
+
138
+ #Builder makes it impossible to access the panels
139
+
140
+ app = Instrumentation::Setup.new(app)
141
+ app = RedirectInterceptor.new(app)
142
+ #Reversed? Does it matter?
143
+ app = classes.inject(app) do |app, panel_class|
144
+ panel = panel_class.new(app)
145
+ panels << panel
146
+ panel
140
147
  end
148
+ app = RequestRecorder.new(app)
149
+ return app
141
150
  end
142
151
 
143
152
  def asset_mapped(builder)
@@ -62,7 +62,7 @@ module Insight
62
62
  @db
63
63
  rescue Object => ex
64
64
  msg = "Issue while loading SQLite DB:" + [ex.class, ex.message, ex.backtrace[0..4]].inspect
65
- logger.debug{ msg }
65
+ logger.error{ msg }
66
66
 
67
67
  return {}
68
68
  end
@@ -90,7 +90,7 @@ module Insight
90
90
  end
91
91
 
92
92
  def execute(*args)
93
- logger.debug{ ins_args = args.inspect; "(#{[ins_args.length,120].min}/#{ins_args.length})" + ins_args[0..120] }
93
+ logger.info{ ins_args = args.inspect; "(#{[ins_args.length,120].min}/#{ins_args.length})" + ins_args[0..120] }
94
94
  db.execute(*args)
95
95
  end
96
96
 
@@ -98,9 +98,8 @@ module Insight
98
98
  @table_name = table_name
99
99
  @keys = keys
100
100
  if(execute("select * from sqlite_master where name = ?", table_name).empty?)
101
+ logger.warn{ "Initializing a table called #{table_name}" }
101
102
  execute(create_sql)
102
-
103
- logger.debug{ "Initializing a table called #{table_name}" }
104
103
  end
105
104
  end
106
105
 
@@ -31,7 +31,7 @@ module Insight
31
31
  full_body = response.body.join
32
32
  full_body.sub! /<\/body>/, render + "</body>"
33
33
 
34
- response["Content-Length"] = full_body.size.to_s
34
+ response["Content-Length"] = full_body.bytesize.to_s
35
35
 
36
36
  response.body = [full_body]
37
37
  end
@@ -20,8 +20,6 @@ module Insight
20
20
  result = nil
21
21
  if instrument.nil?
22
22
  backstage do
23
- # Rails.logger.debug{"No instrument in thread - #{context} /
24
- # #{called_at}"}
25
23
  result = yield
26
24
  end
27
25
  else
@@ -68,7 +66,7 @@ module Insight
68
66
  begin
69
67
  h[k] = self.new(const_from_name(k))
70
68
  rescue NameError
71
- logger.info{ "Cannot find constant: #{k}" }
69
+ logger.warn{ "Cannot find constant: #{k}" }
72
70
  end
73
71
  end
74
72
  end
@@ -130,7 +128,6 @@ module Insight
130
128
  include Logging
131
129
  def log &block
132
130
  logger.debug &block
133
- #$stderr.puts block.call.inspect
134
131
  end
135
132
 
136
133
  def fulfill_probe_orders
@@ -19,9 +19,7 @@ module Insight
19
19
  message = message.inspect unless String === message
20
20
  return unless severity >= @level
21
21
 
22
- if defined? Rails and
23
- Rails.respond_to? :logger
24
- not Rails.logger.nil?
22
+ if defined? Rails and Rails.respond_to?(:logger) and not Rails.logger.nil?
25
23
  Rails.logger.add(severity, "[Insight]: " + message)
26
24
  end
27
25
 
@@ -49,11 +49,19 @@ module Insight
49
49
  private
50
50
 
51
51
  def read_option(key)
52
- options[option_name(key)]
52
+ key = option_name(key)
53
+ if @env and @env.has_key?(key)
54
+ @env[key]
55
+ else
56
+ @default_options[key]
57
+ end
53
58
  end
54
59
 
55
60
  def write_option(key, value)
56
- options[option_name(key)] = value
61
+ @default_options[option_name(key)] = value
62
+ if @env.respond_to? :[]
63
+ @env[option_name(key)] = value
64
+ end
57
65
  end
58
66
 
59
67
  def option_name(key)
@@ -84,6 +92,7 @@ module Insight
84
92
  'insight.secret_key' => nil,
85
93
  'insight.intercept_redirects' => false,
86
94
  'insight.panels' => [],
95
+ 'insight.path_filters' => %w{/assets/},
87
96
  'insight.log_level' => Logger::INFO,
88
97
  'insight.log_path' => "log/insight.log",
89
98
  'insight.database_path' => "insight.sqlite",
@@ -73,9 +73,11 @@ module Insight
73
73
 
74
74
  def call(env)
75
75
  @env = env
76
+ logger.debug{ "Before call: #{self.name}" }
76
77
  before(env)
77
78
  status, headers, body = @app.call(env)
78
79
  @request = Rack::Request.new(env)
80
+ logger.debug{ "After call: #{self.name}" }
79
81
  after(env, status, headers, body)
80
82
  env["insight.panels"] << self
81
83
  return [status, headers, body]
@@ -94,7 +96,7 @@ module Insight
94
96
  end
95
97
 
96
98
  def name
97
- "Unnamed panel: #{__FILE__}" #for shame
99
+ "Unnamed panel: #{self.class.name}" #for shame
98
100
  end
99
101
 
100
102
  def heading_for_request(number)
@@ -15,7 +15,6 @@ module Insight
15
15
  end
16
16
  end
17
17
 
18
-
19
18
  def after_detect(method_call, timing, args, message)
20
19
  message = args[1] || args[2] unless message.is_a?(String)
21
20
  log_level = args[0]
@@ -27,6 +27,10 @@ module Insight
27
27
  false
28
28
  end
29
29
 
30
+ def name
31
+ "Memory"
32
+ end
33
+
30
34
  end
31
35
 
32
36
  end
@@ -0,0 +1,23 @@
1
+ require 'insight/logger'
2
+
3
+ module Insight
4
+ class PathFilter
5
+ include Logging
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ filters = env['insight.path_filters'].map do |string|
12
+ %r{^#{string}}
13
+ end
14
+
15
+ unless filter = filters.find{|regex| regex =~ env['PATH_INFO']}
16
+ return [404, {}, []]
17
+ end
18
+
19
+ logger.debug{ "Shortcutting collection stack: #{filter} =~ #{env['PATH_INFO']}"}
20
+ return @app.call(env)
21
+ end
22
+ end
23
+ end
@@ -1,6 +1,7 @@
1
1
  module Insight
2
2
  class Toolbar
3
3
  include Render
4
+ include Logging
4
5
 
5
6
  MIME_TYPES = ["text/html", "application/xhtml+xml"]
6
7
 
@@ -16,7 +17,9 @@ module Insight
16
17
 
17
18
  response = Rack::Response.new(body, status, headers)
18
19
 
19
- inject_toolbar(response) if okay_to_modify?(env, response)
20
+ if okay_to_modify?(env, response)
21
+ inject_toolbar(response)
22
+ end
20
23
 
21
24
  return response.to_a
22
25
  end
@@ -46,6 +49,9 @@ module Insight
46
49
  requests = @request_table.to_a.map do |row|
47
50
  { :id => row[0], :method => row[1], :path => row[2] }
48
51
  end
52
+
53
+ logger.info{ "Injecting toolbar: active panels: #{@insight.panels.map{|pnl| pnl.class.name}.inspect}" }
54
+
49
55
  headers_fragment = render_template("headers_fragment",
50
56
  :panels => @insight.panels,
51
57
  :request_id => req_id)
@@ -1 +1,21 @@
1
- <a id='logical-insight-enabler' href="javascript: (function(){var script=document.createElement('script'); script.src='/__insight__/bookmarklet.js'; document.getElementsByTagName('head')[0].appendChild(script); document.insightEnable()})()">Insight</a>
1
+ <script type="text/javascript" src='/__insight__/bookmarklet.js'></script>
2
+ <style>
3
+ #logical-insight-enabler {
4
+ position: absolute;
5
+ z-index: 100000;
6
+ overflow: hidden;
7
+ width: 4px;
8
+ height: 4px;
9
+ top: 0;
10
+ left: 0;
11
+ background: #326342;
12
+ color: #92EF3F;
13
+ }
14
+
15
+ #logical-insight-enabler:hover {
16
+ width: 50px;
17
+ height: 24px;
18
+ }
19
+ </style>
20
+
21
+ <a id='logical-insight-enabler' href="#" onclick="document.insightEnable()" style="">Insight</a>
@@ -1,7 +1,5 @@
1
-
2
- <li id="insight_disable_button">[X]</li>
3
- <li id="insight_debug_button">Insight (req# <span id="request_id"><%= request_id %></span>)</li>
4
-
1
+ <li id="insight_disable_button">[X]</li>
2
+ <li id="insight_debug_button">Insight (req# <span id="request_id"><%= request_id %></span>)</li>
5
3
  <% panels.each do |panel| %>
6
4
  <li>
7
5
  <% begin %>
@@ -3,7 +3,7 @@ module Insight
3
3
  describe "ActiveRecordPanel" do
4
4
  before do
5
5
  mock_constant("ActiveRecord::Base")
6
- reset_insight :panel_classes => [ActiveRecordPanel]
6
+ reset_insight :panel_files => %w{active_record_panel}
7
7
  end
8
8
 
9
9
  def mock_model(name)
@@ -112,7 +112,7 @@ module Insight
112
112
 
113
113
  describe "cache operations" do
114
114
  before do
115
- rack_env "insight.secret_key", 'abc'
115
+ app.insight_app.secret_key = 'abc'
116
116
  response = get_via_rack "/"
117
117
  end
118
118
 
@@ -3,7 +3,7 @@ if defined? Mongo
3
3
  describe "MongoPanel" do
4
4
  before do
5
5
  MongoPanel.reset
6
- rack_env "insight.panel_classes", [MongoPanel]
6
+ reset_insight :panel_files => %w{mongo_panel}
7
7
  end
8
8
 
9
9
  describe "heading" do
@@ -61,7 +61,7 @@ module Insight
61
61
 
62
62
  describe "sql/execute" do
63
63
  it "displays the query results" do
64
- rack_env "insight.secret_key", "abc"
64
+ app.insight_app.secret_key = "abc"
65
65
  expect_query "SELECT username FROM users",
66
66
  [["username"],
67
67
  ["bryan"]]
@@ -73,7 +73,7 @@ module Insight
73
73
  end
74
74
 
75
75
  it "is forbidden when the hash is missing or wrong" do
76
- rack_env "insight.secret_key", 'abc'
76
+ app.insight_app.secret_key='abc'
77
77
 
78
78
  lambda {
79
79
  get_via_rack "/__insight__/sql/execute", {:query => "SELECT username FROM users",
@@ -82,7 +82,7 @@ module Insight
82
82
  end
83
83
 
84
84
  it "is not available when the insight.secret_key is nil" do
85
- rack_env "insight.secret_key", nil
85
+ app.insight_app.secret_key = nil
86
86
 
87
87
  lambda {
88
88
  get_via_rack "/__insight__/sql/execute", {:query => "SELECT username FROM users",
@@ -91,7 +91,7 @@ module Insight
91
91
  end
92
92
 
93
93
  it "is not available when the insight.secret_key is an empty string" do
94
- rack_env "insight.secret_key", ""
94
+ app.insight_app.secret_key = ""
95
95
 
96
96
  lambda {
97
97
  get_via_rack "/__insight__/sql/execute", {:query => "SELECT username FROM users",
@@ -102,7 +102,7 @@ module Insight
102
102
 
103
103
  describe "sql/explain" do
104
104
  it "displays the query explain plan" do
105
- rack_env "insight.secret_key", "abc"
105
+ app.insight_app.secret_key = "abc"
106
106
  expect_query "EXPLAIN SELECT username FROM users",
107
107
  [["table"],
108
108
  ["users"]]
@@ -115,7 +115,7 @@ module Insight
115
115
  end
116
116
 
117
117
  it "is forbidden when the hash is missing or wrong" do
118
- rack_env "insight.secret_key", 'abc'
118
+ app.insight_app.secret_key='abc'
119
119
 
120
120
  lambda {
121
121
  get_via_rack "/__insight__/sql/explain", :query => "SELECT username FROM users",
@@ -124,7 +124,7 @@ module Insight
124
124
  end
125
125
 
126
126
  it "is not available when the insight.secret_key is nil" do
127
- rack_env "insight.secret_key", nil
127
+ app.insight_app.secret_key=nil
128
128
 
129
129
  lambda {
130
130
  get_via_rack "/__insight__/sql/explain", :query => "SELECT username FROM users",
@@ -133,7 +133,7 @@ module Insight
133
133
  end
134
134
 
135
135
  it "is not available when the insight.secret_key is an empty string" do
136
- rack_env "insight.secret_key", ""
136
+ app.insight_app.secret_key=""
137
137
 
138
138
  lambda {
139
139
  get_via_rack "/__insight__/sql/explain", :query => "SELECT username FROM users",
@@ -72,31 +72,35 @@ describe Insight do
72
72
  end
73
73
 
74
74
  context "redirected when configured to intercept redirects" do
75
+ before :each do
76
+ app.insight_app.intercept_redirects = true
77
+ end
78
+
75
79
  it "shows the interception page" do
76
- response = get "/redirect", {}, "insight.intercept_redirects" => true
80
+ response = get "/redirect"
77
81
  response.should have_selector("div#insight")
78
82
  end
79
83
 
80
84
  it "should provide a link to the target URL" do
81
- response = get "/redirect", {}, "insight.intercept_redirects" => true
85
+ response = get "/redirect"
82
86
  response.should have_selector("a[href='http://example.org/']")
83
87
  end
84
88
 
85
89
  it "inserts the toolbar if requested" do
86
- response = get "/redirect", {}, "insight.intercept_redirects" => true
90
+ response = get "/redirect"
87
91
  response.should have_selector("div#insight")
88
92
  end
89
93
 
90
94
  it "does not inserts the toolbar if not requested" do
91
95
  header 'cookie', ""
92
- response = get "/redirect", {}, "insight.intercept_redirects" => true
96
+ response = get "/redirect"
93
97
  response.should_not have_selector("div#insight")
94
98
  end
95
99
  end
96
100
 
97
101
  context "configured with an IP address restriction" do
98
102
  before do
99
- rack_env "insight.ip_masks", [IPAddr.new("127.0.0.1/255.255.255.0")]
103
+ app.insight_app.ip_masks = [IPAddr.new("127.0.0.1/255.255.255.0")]
100
104
  end
101
105
 
102
106
  it "inserts the Insight toolbar when the IP matches" do
@@ -111,14 +115,14 @@ describe Insight do
111
115
 
112
116
  it "doesn't use any panels" do
113
117
  DummyPanel.should_not_receive(:new)
114
- rack_env "insight.panel_classes", [DummyPanel]
118
+ app.insight_app.panel_classes = [DummyPanel]
115
119
  get_via_rack "/", {}, "REMOTE_ADDR" => "128.0.0.1"
116
120
  end
117
121
  end
118
122
 
119
123
  context "configured with a password" do
120
124
  before do
121
- rack_env "insight.password", "secret"
125
+ app.insight_app.password = "secret"
122
126
  end
123
127
 
124
128
  it "should insert the Insight toolbar when the password matches" do
@@ -134,7 +138,7 @@ describe Insight do
134
138
  end
135
139
  it "doesn't use any panels" do
136
140
  DummyPanel.should_not_receive(:new)
137
- rack_env "insight.panel_classes", [DummyPanel]
141
+ app.insight_app.panel_classes = [DummyPanel]
138
142
  get_via_rack "/"
139
143
  end
140
144
  end
metadata CHANGED
@@ -1,70 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: logical-insight
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.5
4
5
  prerelease:
5
- version: 0.4.4
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Bryan Helmkamp
9
9
  - Evan Dorn
10
10
  - Judson Lester
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
-
15
- date: 2011-12-13 00:00:00 Z
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
14
+ date: 2011-12-13 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
18
17
  name: corundum
19
- requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirement: &71737750 !ruby/object:Gem::Requirement
20
19
  none: false
21
- requirements:
20
+ requirements:
22
21
  - - ~>
23
- - !ruby/object:Gem::Version
22
+ - !ruby/object:Gem::Version
24
23
  version: 0.0.13
25
24
  type: :development
26
25
  prerelease: false
27
- version_requirements: *id001
28
- - !ruby/object:Gem::Dependency
26
+ version_requirements: *71737750
27
+ - !ruby/object:Gem::Dependency
29
28
  name: uuid
30
- requirement: &id002 !ruby/object:Gem::Requirement
29
+ requirement: &71736830 !ruby/object:Gem::Requirement
31
30
  none: false
32
- requirements:
31
+ requirements:
33
32
  - - ~>
34
- - !ruby/object:Gem::Version
35
- segments:
33
+ - !ruby/object:Gem::Version
34
+ version: 2.3.1
35
+ segments:
36
36
  - 2
37
37
  - 3
38
38
  - 1
39
- version: 2.3.1
40
39
  type: :runtime
41
40
  prerelease: false
42
- version_requirements: *id002
43
- - !ruby/object:Gem::Dependency
41
+ version_requirements: *71736830
42
+ - !ruby/object:Gem::Dependency
44
43
  name: sqlite3
45
- requirement: &id003 !ruby/object:Gem::Requirement
44
+ requirement: &70113490 !ruby/object:Gem::Requirement
46
45
  none: false
47
- requirements:
46
+ requirements:
48
47
  - - ~>
49
- - !ruby/object:Gem::Version
50
- segments:
48
+ - !ruby/object:Gem::Version
49
+ version: 1.3.3
50
+ segments:
51
51
  - 1
52
52
  - 3
53
53
  - 3
54
- version: 1.3.3
55
54
  type: :runtime
56
55
  prerelease: false
57
- version_requirements: *id003
58
- description: "Debugging toolbar for Rack applications implemented as\n middleware. Rails 3 compatible version maintained by Logical Reality\n Design. "
56
+ version_requirements: *70113490
57
+ description: ! "Debugging toolbar for Rack applications implemented as\n middleware.
58
+ \ Rails 3 compatible version maintained by Logical Reality\n Design. "
59
59
  email: evan@lrdesign.com judson@lrdesign.com
60
60
  executables: []
61
-
62
61
  extensions: []
63
-
64
- extra_rdoc_files:
62
+ extra_rdoc_files:
65
63
  - README.md
66
64
  - MIT-LICENSE.txt
67
- files:
65
+ files:
68
66
  - lib/logical-insight.rb
69
67
  - lib/insight.rb
70
68
  - lib/insight/rack_static_bug_avoider.rb
@@ -101,6 +99,7 @@ files:
101
99
  - lib/insight/enable-button.rb
102
100
  - lib/insight/instrumentation.rb
103
101
  - lib/insight/app.rb
102
+ - lib/insight/path-filter.rb
104
103
  - lib/insight/panels/request_variables_panel.rb
105
104
  - lib/insight/panels/redis_panel.rb
106
105
  - lib/insight/panels/rails_info_panel.rb
@@ -166,33 +165,30 @@ files:
166
165
  - Thorfile
167
166
  homepage: https://github.com/LRDesign/logical-insight
168
167
  licenses: []
169
-
170
168
  post_install_message:
171
169
  rdoc_options: []
172
-
173
- require_paths:
170
+ require_paths:
174
171
  - lib
175
- required_ruby_version: !ruby/object:Gem::Requirement
172
+ required_ruby_version: !ruby/object:Gem::Requirement
176
173
  none: false
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- hash: 910188977
181
- segments:
174
+ requirements:
175
+ - - ! '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ segments:
182
179
  - 0
183
- version: "0"
184
- required_rubygems_version: !ruby/object:Gem::Requirement
180
+ hash: -406706161
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
182
  none: false
186
- requirements:
187
- - - ">="
188
- - !ruby/object:Gem::Version
189
- version: "0"
183
+ requirements:
184
+ - - ! '>='
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
190
187
  requirements: []
191
-
192
188
  rubyforge_project:
193
- rubygems_version: 1.8.11
189
+ rubygems_version: 1.8.15
194
190
  signing_key:
195
191
  specification_version: 3
196
- summary: Debugging toolbar for Rack applications implemented as middleware. Rails 3 compatible version maintained by Logical Reality Design.
192
+ summary: Debugging toolbar for Rack applications implemented as middleware. Rails
193
+ 3 compatible version maintained by Logical Reality Design.
197
194
  test_files: []
198
-