rack-insight 0.5.21 → 0.5.22

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,5 +1,31 @@
1
1
  == HEAD
2
2
 
3
+ == 0.5.22 / 2012-09-14
4
+
5
+ * New Features
6
+
7
+ * Improve handling of decoding and marshalling problems with new config options and implementation: (pboling - Peter Boling)
8
+
9
+ :database => a hash. Keys :raise_encoding_errors, and :raise_decoding_errors are self explanatory
10
+ :raise_encoding_errors
11
+ When set to true, if there is an encoding error (unlikely)
12
+ it will cause a 500 error on your site. !!!WARNING!!!
13
+ :raise_decoding_errors
14
+ The bundled panels should work fine with :raise_decoding_errors set to true or false
15
+ but custom panel implementations may prefer one over the other
16
+ The bundled panels will capture these errors and perform admirably.
17
+ Site won't go down unless a custom panel is not handling the errors well.
18
+
19
+ * Bug Fixes
20
+
21
+ * Fixes for redis panel. (oggy - George Ogata)
22
+
23
+ * Other
24
+
25
+ * Error system improvements and refactoring (pboling - Peter Boling)
26
+
27
+ * Internal config validation system (pboling - Peter Boling)
28
+
3
29
  == 0.5.21 / 2012-09-13 - Peter Boling
4
30
 
5
31
  * Attempting to handle values that get stored in the sqlite db, but which can't be re-marshalled, without failing the entire panel
data/README.md CHANGED
@@ -127,6 +127,15 @@ Options:
127
127
  "Logger" => [:instance, :add]
128
128
  }}
129
129
 
130
+ :database => a hash. Keys :raise_encoding_errors, and :raise_decoding_errors are self explanatory
131
+ :raise_encoding_errors
132
+ When set to true, if there is an encoding error (unlikely)
133
+ it will cause a 500 error on your site. !!!WARNING!!!
134
+ :raise_decoding_errors
135
+ The bundled panels should work fine with :raise_decoding_errors set to true or false
136
+ but custom panel implementations may prefer one over the other
137
+ The bundled panels will capture these errors and perform admirably.
138
+ Site won't go down unless a custom panel is not handling the errors well.
130
139
 
131
140
  Configure Middleware
132
141
  --------------------
@@ -200,7 +209,7 @@ Restrict access using a password:
200
209
  :ip_masks => false # Default is 127.0.0.1
201
210
  :password => "yourpassword"
202
211
 
203
- #### custom file path for the logging database ####
212
+ #### custom file path for the request recording database ####
204
213
 
205
214
  Logical Rack::Insight uses SQLite to store data from requests, and outputs a database
206
215
  file in the root directory. If you need the file to be created at another
@@ -2,7 +2,8 @@ module Rack::Insight
2
2
  class Config
3
3
  class << self
4
4
  attr_reader :config, :verbosity, :log_file, :log_level, :rails_log_copy,
5
- :filtered_backtrace, :panel_configs, :silence_magic_insight_warnings
5
+ :filtered_backtrace, :panel_configs, :silence_magic_insight_warnings,
6
+ :database
6
7
  end
7
8
  @log_file = STDOUT
8
9
  @log_level = ::Logger::DEBUG
@@ -26,6 +27,10 @@ module Rack::Insight
26
27
  :templates => {:probes => {'ActionView::Template' => [:instance, :render]}}
27
28
  }
28
29
  @silence_magic_insight_warnings = false
30
+ @database = {
31
+ :raise_encoding_errors => false, # Either way will be logged
32
+ :raise_decoding_errors => true, # Either way will be logged
33
+ }
29
34
 
30
35
  DEFAULTS = {
31
36
  # You can augment or replace the default set of panel load paths.
@@ -45,7 +50,16 @@ module Rack::Insight
45
50
  :verbosity => @verbosity, # true is equivalent to relying soley on the log level of each logged message
46
51
  :filtered_backtrace => @filtered_backtrace, # Full backtraces, or filtered ones?
47
52
  :panel_configs => @panel_configs, # Allow specific panels to have their own configurations, and make it extensible
48
- :silence_magic_insight_warnings => @silence_magic_insight_warnings # Should Rack::Insight warn when the MagicInsight is used?
53
+ :silence_magic_insight_warnings => @silence_magic_insight_warnings, # Should Rack::Insight warn when the MagicInsight is used?
54
+ :database => @database # a hash. Keys :raise_encoding_errors, and :raise_decoding_errors are self explanatory
55
+ # :raise_encoding_errors
56
+ # When set to true, if there is an encoding error (unlikely)
57
+ # it will cause a 500 error on your site. !!!WARNING!!!
58
+ # :raise_decoding_errors
59
+ # The bundled panels should work fine with :raise_decoding_errors set to true or false
60
+ # but custom panel implementations may prefer one over the other
61
+ # The bundled panels will capture these errors and perform admirably.
62
+ # Site won't go down unless a custom panel is not handling the errors well.
49
63
  }
50
64
 
51
65
  @config ||= DEFAULTS
@@ -53,21 +67,34 @@ module Rack::Insight
53
67
  yield @config
54
68
  logger.debug("Rack::Insight::Config#configure:\n called from: #{caller[0]}\n with: #{@config}") if config[:verbosity] == true || config[:verbosity].respond_to?(:<) && config[:verbosity] <= 1
55
69
  @logger = config[:logger]
56
- @log_level = config[:log_level]
57
- @log_file = config[:log_file]
70
+ if @logger.nil?
71
+ @log_level = config[:log_level]
72
+ @log_file = config[:log_file]
73
+ elsif config[:log_level] || config[:log_file]
74
+ logger.warn("Rack::Insight::Config#configure: when logger is set, log_level and log_file have no effect, and will only confuse you.")
75
+ end
58
76
  @verbosity = config[:verbosity]
59
77
  @filtered_backtrace = config[:filtered_backtrace]
60
78
  @silence_magic_insight_warnings = config[:silence_magic_insight_warnings]
79
+ @database = config[:database]
61
80
 
62
81
  config[:panel_configs].each do |panel_name_sym, config|
63
82
  set_panel_config(panel_name_sym, config)
64
83
  end
65
84
 
66
- unless config[:panel_load_paths].kind_of?(Array)
67
- raise "Rack::Insight::Config.config[:panel_load_paths] is invalid: Expected kind of Array but got #{config[:panel_load_paths].class}"
68
- end
69
- unless config[:panel_configs].kind_of?(Hash)
70
- raise "Rack::Insight::Config.config[:panel_configs] is invalid: Expected kind of Hash but got #{config[:panel_configs].class}"
85
+ validate_config(:panel_configs, Hash)
86
+ validate_config(:panel_load_paths, Array)
87
+ validate_config(:database, Hash)
88
+ end
89
+
90
+ def self.validate_config(key, klass)
91
+ raise ConfigurationError.new(key, klass.to_s) unless config[key].kind_of?(klass)
92
+ end
93
+
94
+ class ConfigurationError < StandardError;
95
+ def self.new(key, expected)
96
+ actual = Rack::Insight::Config.config[key].class
97
+ super("Rack::Insight::Config.config[:#{key}] is invalid: Expected kind of #{expected} but got #{actual}")
71
98
  end
72
99
  end
73
100
 
@@ -14,6 +14,7 @@ module Rack::Insight
14
14
  # # Setting as below is only required when not using a table (Why are you including this module then?)
15
15
  # # self.has_table = false
16
16
  # end
17
+ # TODO: Move the has_table definition into this module's included hook.
17
18
  module RequestDataClient
18
19
  def key_sql_template(sql)
19
20
  @key_sql_template = sql
@@ -185,12 +186,39 @@ module Rack::Insight
185
186
  insert(sql)
186
187
  end
187
188
 
189
+ # We sometimes get errors in the encoding and decoding, and they could be from any number of root causes.
190
+ # This will allow those root causes to be exposed at the top layer by wrapping all errors in a Rack::Insight
191
+ # namespaced error class, which will be rescued higher up the stack.
192
+ module ErrorWrapper
193
+ def new(parent, message = '')
194
+ ex = super("#{message}#{parent.class}: #{parent.message}")
195
+ ex.set_backtrace parent.backtrace
196
+ ex
197
+ end
198
+ end
199
+
200
+ class EncodingError < StandardError
201
+ extend ErrorWrapper
202
+ end
203
+
204
+ class DecodingError < StandardError
205
+ extend ErrorWrapper
206
+ end
207
+
188
208
  def encode_value(value)
189
209
  Base64.encode64(YAML.dump(value))
210
+ rescue Exception => ex
211
+ wrapped = EncodingError.new(ex, "Rack::Insight::Database#encode_value failed with error: ")
212
+ logger.error(wrapped)
213
+ raise wrapped if Rack::Insight::Config.database[:raise_encoding_errors]
190
214
  end
191
215
 
192
216
  def decode_value(value)
193
- YAML.load(Base64.decode64(value)) rescue "Unable to decode"
217
+ YAML.load(Base64.decode64(value))
218
+ rescue Exception => ex
219
+ wrapped = DecodingError.new(ex, "Rack::Insight::Database#decode_value failed with error: ")
220
+ logger.error(wrapped)
221
+ raise wrapped if Rack::Insight::Config.database[:raise_decoding_errors]
194
222
  end
195
223
 
196
224
  def retrieve(key_sql)
@@ -12,9 +12,9 @@ if defined?(Redis)
12
12
  elsif defined?(Redis::Client) # newer versions of redis-rb
13
13
 
14
14
  Redis::Client.class_eval do
15
- def call_with_insight(*argv)
16
- Rack::Insight::RedisPanel.record(argv, Kernel.caller) do
17
- call_without_insight(*argv)
15
+ def call_with_insight(command, &block)
16
+ Rack::Insight::RedisPanel.record(command, Kernel.caller) do
17
+ call_without_insight(command, &block)
18
18
  end
19
19
  end
20
20
  end
@@ -1,7 +1,7 @@
1
1
  module Rack
2
2
  module Insight
3
3
 
4
- VERSION = '0.5.21'
4
+ VERSION = '0.5.22'
5
5
 
6
6
  end
7
7
  end
@@ -0,0 +1,14 @@
1
+ <h3><%= name %></h3>
2
+ <p>Unable to Decoding or Marshalling Objects from rack-insight data storage.</p>
3
+ <h4>Error</h4>
4
+ <p><%= @error.message %></p>
5
+ <h4>Backtrace</h4>
6
+ <p>
7
+ <pre>
8
+ <code>
9
+ <%- @error.backtrace.each do |line| %>
10
+ <%= line %>
11
+ <%- end %>
12
+ </code>
13
+ </pre>
14
+ </p>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-insight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.21
4
+ version: 0.5.22
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-09-13 00:00:00.000000000 Z
15
+ date: 2012-09-14 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rack
@@ -283,6 +283,7 @@ files:
283
283
  - lib/rack/insight/rspec_matchers.rb
284
284
  - lib/rack/insight/toolbar.rb
285
285
  - lib/rack/insight/version.rb
286
+ - lib/rack/insight/views/decoding_error.html.erb
286
287
  - lib/rack/insight/views/enable-button.html.erb
287
288
  - lib/rack/insight/views/error.html.erb
288
289
  - lib/rack/insight/views/headers_fragment.html.erb