time_bandits 0.10.10 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +17 -5
  3. data/Appraisals +2 -9
  4. data/README.md +33 -6
  5. data/Rakefile +1 -0
  6. data/docker-compose.yml +4 -4
  7. data/gemfiles/activesupport_5.2.4.3.gemfile +8 -0
  8. data/gemfiles/activesupport_5.2.4.3.gemfile.lock +81 -0
  9. data/gemfiles/activesupport_6.0.3.2.gemfile +8 -0
  10. data/gemfiles/activesupport_6.0.3.2.gemfile.lock +81 -0
  11. data/lib/time_bandits.rb +2 -6
  12. data/lib/time_bandits/monkey_patches/action_controller.rb +2 -67
  13. data/lib/time_bandits/monkey_patches/active_record.rb +18 -98
  14. data/lib/time_bandits/rack/logger.rb +46 -19
  15. data/lib/time_bandits/railtie.rb +6 -8
  16. data/lib/time_bandits/time_consumers/dalli.rb +0 -12
  17. data/lib/time_bandits/time_consumers/garbage_collection.rb +5 -29
  18. data/lib/time_bandits/version.rb +1 -1
  19. data/test/test_helper.rb +5 -10
  20. data/test/unit/database_test.rb +6 -2
  21. data/test/unit/gc_consumer_test.rb +2 -3
  22. data/test/unit/sequel_test.rb +5 -1
  23. data/time_bandits.gemspec +6 -3
  24. metadata +20 -35
  25. data/gemfiles/activesupport_4.1.16.gemfile +0 -8
  26. data/gemfiles/activesupport_4.1.16.gemfile.lock +0 -91
  27. data/gemfiles/activesupport_4.2.8.gemfile +0 -8
  28. data/gemfiles/activesupport_4.2.8.gemfile.lock +0 -89
  29. data/gemfiles/activesupport_4.2.9.gemfile +0 -8
  30. data/gemfiles/activesupport_4.2.9.gemfile.lock +0 -89
  31. data/gemfiles/activesupport_5.0.3.gemfile +0 -8
  32. data/gemfiles/activesupport_5.0.3.gemfile.lock +0 -88
  33. data/gemfiles/activesupport_5.0.4.gemfile +0 -8
  34. data/gemfiles/activesupport_5.0.4.gemfile.lock +0 -88
  35. data/gemfiles/activesupport_5.1.1.gemfile +0 -8
  36. data/gemfiles/activesupport_5.1.1.gemfile.lock +0 -88
  37. data/gemfiles/activesupport_5.1.2.gemfile +0 -8
  38. data/gemfiles/activesupport_5.1.2.gemfile.lock +0 -88
  39. data/gemfiles/activesupport_5.1.5.gemfile +0 -8
  40. data/gemfiles/activesupport_5.1.5.gemfile.lock +0 -85
  41. data/lib/time_bandits/monkey_patches/active_support_cache_store.rb +0 -18
  42. data/lib/time_bandits/rack/logger40.rb +0 -94
  43. data/rails/init.rb +0 -1
@@ -1,18 +0,0 @@
1
- require "active_support/cache"
2
-
3
- # Rails 4 builtin mem_cache_store broke hit reporting for fetch.
4
- # This has been fixed in Rails 5.
5
- # The dalli time consumer makes sure to require this file only for Rails 4.
6
-
7
- class ActiveSupport::Cache::Store
8
- private
9
- # only called by fetch
10
- def find_cached_entry(key, name, options)
11
- instrument(:read, name, options) do |payload|
12
- payload[:super_operation] = :fetch if payload
13
- res = read_entry(key, options)
14
- payload[:hit] = !!res if payload
15
- res
16
- end
17
- end
18
- end
@@ -1,94 +0,0 @@
1
- require 'active_support/core_ext/time/conversions'
2
- require 'active_support/core_ext/object/blank'
3
- require 'active_support/log_subscriber'
4
- require 'action_dispatch/http/request'
5
- require 'rack/body_proxy'
6
-
7
- module TimeBandits
8
- module Rack
9
- # Sets log tags, logs the request, calls the app, and flushes the logs.
10
- class Logger < ActiveSupport::LogSubscriber
11
- def initialize(app, taggers = nil)
12
- @app = app
13
- @taggers = taggers || Rails.application.config.log_tags || []
14
- @instrumenter = ActiveSupport::Notifications.instrumenter
15
- end
16
-
17
- def call(env)
18
- request = ActionDispatch::Request.new(env)
19
-
20
- if logger.respond_to?(:tagged) && !@taggers.empty?
21
- logger.tagged(compute_tags(request)) { call_app(request, env) }
22
- else
23
- call_app(request, env)
24
- end
25
- end
26
-
27
- protected
28
-
29
- def call_app(request, env)
30
- start_time = Time.now
31
- start(request, start_time)
32
- resp = @app.call(env)
33
- resp[2] = ::Rack::BodyProxy.new(resp[2]) { finish(request) }
34
- resp
35
- rescue
36
- finish(request)
37
- raise
38
- ensure
39
- completed(request, (Time.now - start_time) * 1000, resp)
40
- ActiveSupport::LogSubscriber.flush_all!
41
- end
42
-
43
- # Started GET "/session/new" for 127.0.0.1 at 2012-09-26 14:51:42 -0700
44
- def started_request_message(request, start_time=Time.now)
45
- 'Started %s "%s" for %s at %s' % [
46
- request.request_method,
47
- request.filtered_path,
48
- request.ip,
49
- start_time.to_default_s ]
50
- end
51
-
52
- def compute_tags(request)
53
- @taggers.collect do |tag|
54
- case tag
55
- when Proc
56
- tag.call(request)
57
- when Symbol
58
- request.send(tag)
59
- else
60
- tag
61
- end
62
- end
63
- end
64
-
65
- private
66
-
67
- def start(request, start_time)
68
- TimeBandits.reset
69
- Thread.current.thread_variable_set(:time_bandits_completed_info, nil)
70
- @instrumenter.start 'action_dispatch.request', request: request
71
-
72
- logger.debug ""
73
- logger.info started_request_message(request, start_time)
74
- end
75
-
76
- def completed(request, run_time, resp)
77
- status = resp ? resp.first.to_i : 500
78
- completed_info = Thread.current.thread_variable_get(:time_bandits_completed_info)
79
- additions = completed_info[1] if completed_info
80
- message = "Completed #{status} #{::Rack::Utils::HTTP_STATUS_CODES[status]} in %.1fms" % run_time
81
- message << " (#{additions.join(' | ')})" unless additions.blank?
82
- logger.info message
83
- end
84
-
85
- def finish(request)
86
- @instrumenter.finish 'action_dispatch.request', request: request
87
- end
88
-
89
- def logger
90
- @logger ||= Rails.logger
91
- end
92
- end
93
- end
94
- end
@@ -1 +0,0 @@
1
- require File.expand_path('../../init.rb', __FILE__)