notable 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 388cbc24d5dae49059d56fdc1eb0151b88413642696510648be056498258e5b0
4
- data.tar.gz: f0dab808379c2b143ca41b443ce5b07930e8f87e6d83caf4a369f81ea644590b
3
+ metadata.gz: 0a1ecb0013fc63daaa3bec5b0b451fca47d39617ca73c18f72f6dfcefb368bbc
4
+ data.tar.gz: f156679280ff767f0c99c6dc768f1b25cfc761759935b86cc5d64092d1a6d19a
5
5
  SHA512:
6
- metadata.gz: 1f7774c7eec961cbda78bd0652dc640e283f32907375fb344ad5098bafba794f7539562d8fc6808cf2b101f340b706a6b55a2be83c7c25ca90fdc7372b6a7b2b
7
- data.tar.gz: 54fbe03343496f1d8b87b115458bae361db725f66b2996ce32f4fd00f5b43a4784bbd631bb346523abf8caa6d1b7b4d5a4762b24ef8bdb3451b978a5a5e422a6
6
+ metadata.gz: bc5ae406db635275367d0f609b2e28311e1e467ee99c13b7acc1184a22dc998a2a5e645a9a4f3b529403ded4e7aa2f52a818bbd0da7bd40a021163be207fd742
7
+ data.tar.gz: 84a13882970bec183ae857ad5641531a4267c1cea855842e3a77606923271cbd92246ae4d43df5a997a63fb569b8fa6fb012ffb214eccbce9bc8c7c63c7842a2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.3.0
2
+
3
+ - Added support for Rack::Attack 6
4
+ - Added job-specific slow job threshold
5
+ - Dropped support for Rails 4.2
6
+
1
7
  ## 0.2.2
2
8
 
3
9
  - Added `mask_ips` option
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Andrew Kane
1
+ Copyright (c) 2014-2019 Andrew Kane
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -36,10 +36,10 @@ And run:
36
36
  ```sh
37
37
  rails generate notable:requests
38
38
  rails generate notable:jobs
39
- rake db:migrate
39
+ rails db:migrate
40
40
  ```
41
41
 
42
- For a web interface, check out [Notable Web](https://github.com/ankane/notable_web).
42
+ To explore the data, check out [Blazer](https://github.com/ankane/blazer).
43
43
 
44
44
  ## Requests
45
45
 
@@ -93,23 +93,23 @@ Notable.enabled = Rails.env.production?
93
93
  Set slow threshold
94
94
 
95
95
  ```ruby
96
- Notable.slow_request_threshold = 5 # seconds (default)
96
+ Notable.slow_request_threshold = 5.seconds
97
97
  ```
98
98
 
99
99
  Custom user method
100
100
 
101
101
  ```ruby
102
- Notable.user_method = -> (env) {
102
+ Notable.user_method = lambda do |env|
103
103
  env["warden"].try(:user) || env["action_controller.instance"].try(:current_visit)
104
- }
104
+ end
105
105
  ```
106
106
 
107
107
  Custom track method
108
108
 
109
109
  ```ruby
110
- Notable.track_request_method = -> (data, env) {
110
+ Notable.track_request_method = lambda do |data, env|
111
111
  Notable::Request.create!(data)
112
- }
112
+ end
113
113
  ```
114
114
 
115
115
  Skip tracking CSRF failures
@@ -129,21 +129,26 @@ Notable.mask_ips = true
129
129
  Set slow threshold
130
130
 
131
131
  ```ruby
132
- Notable.slow_job_threshold = 60 # seconds (default)
132
+ Notable.slow_job_threshold = 60.seconds
133
133
  ```
134
134
 
135
- Custom track method
135
+ To set a threshold for a specific job, use:
136
136
 
137
137
  ```ruby
138
- Notable.track_job_method = -> (data) {
139
- Notable::Job.create!(data)
140
- }
138
+ class CustomJob < ApplicationJob
139
+ def notable_slow_job_threshold
140
+ 5.minutes
141
+ end
142
+ end
141
143
  ```
142
144
 
143
- ## TODO
145
+ Custom track method
144
146
 
145
- - ability to disable features
146
- - add indexes
147
+ ```ruby
148
+ Notable.track_job_method = lambda do |data|
149
+ Notable::Job.create!(data)
150
+ end
151
+ ```
147
152
 
148
153
  ## Contributing
149
154
 
@@ -26,9 +26,7 @@ module Notable
26
26
  end
27
27
 
28
28
  def migration_version
29
- if ActiveRecord::VERSION::MAJOR >= 5
30
- "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
31
- end
29
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
32
30
  end
33
31
  end
34
32
  end
@@ -26,9 +26,7 @@ module Notable
26
26
  end
27
27
 
28
28
  def migration_version
29
- if ActiveRecord::VERSION::MAJOR >= 5
30
- "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
31
- end
29
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
32
30
  end
33
31
  end
34
32
  end
@@ -6,8 +6,8 @@ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version
6
6
  t.text :job
7
7
  t.string :job_id
8
8
  t.string :queue
9
- t.decimal :runtime
10
- t.decimal :queued_time
9
+ t.float :runtime
10
+ t.float :queued_time
11
11
  t.timestamp :created_at
12
12
  end
13
13
  end
@@ -13,7 +13,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version
13
13
  t.text :user_agent
14
14
  t.text :referrer
15
15
  t.text :params
16
- t.decimal :request_time
16
+ t.float :request_time
17
17
  t.timestamp :created_at
18
18
  end
19
19
 
data/lib/notable.rb CHANGED
@@ -1,19 +1,15 @@
1
- require "notable/version"
2
-
3
- require "request_store"
1
+ # dependencies
2
+ require "active_support"
4
3
  require "safely/core"
5
- require "action_dispatch/middleware/debug_exceptions"
6
-
7
- # middleware
8
- require "notable/middleware"
9
- require "notable/engine" if defined?(Rails)
10
4
 
11
- # requests
12
- require "notable/unpermitted_parameters"
13
- require "notable/unverified_request"
14
- require "notable/validation_errors"
5
+ # modules
15
6
  require "notable/debug_exceptions"
7
+ require "notable/middleware"
16
8
  require "notable/throttle"
9
+ require "notable/unpermitted_parameters"
10
+ require "notable/version"
11
+
12
+ require "notable/engine" if defined?(Rails)
17
13
 
18
14
  module Notable
19
15
  class << self
@@ -45,7 +41,7 @@ module Notable
45
41
  end
46
42
 
47
43
  # requests
48
- self.track_request_method = -> (data, env) { Notable::Request.create!(data) }
44
+ self.track_request_method = -> (data, _) { Notable::Request.create!(data) }
49
45
  self.user_method = -> (env) { env["warden"].user if env["warden"] }
50
46
  self.slow_request_threshold = 5
51
47
 
@@ -54,7 +50,7 @@ module Notable
54
50
  self.slow_job_threshold = 60
55
51
 
56
52
  def self.track(note_type, note = nil)
57
- (RequestStore.store[:notable_notes] ||= []) << {note_type: note_type, note: note}
53
+ notes << {note_type: note_type, note: note}
58
54
  end
59
55
 
60
56
  def self.track_error(e)
@@ -62,14 +58,15 @@ module Notable
62
58
  end
63
59
 
64
60
  def self.notes
65
- RequestStore.store[:notable_notes].to_a
61
+ Thread.current[:notable_notes] ||= []
66
62
  end
67
63
 
68
64
  def self.clear_notes
69
- RequestStore.store.delete(:notable_notes)
65
+ Thread.current[:notable_notes] = nil
70
66
  end
71
67
 
72
- def self.track_job(job, job_id, queue, created_at)
68
+ def self.track_job(job, job_id, queue, created_at, slow_job_threshold = nil)
69
+ slow_job_threshold ||= Notable.slow_job_threshold
73
70
  exception = nil
74
71
  notes = nil
75
72
  start_time = Time.now
@@ -86,7 +83,7 @@ module Notable
86
83
  runtime = Time.now - start_time
87
84
 
88
85
  Safely.safely do
89
- notes << {note_type: "Slow Job"} if runtime > Notable.slow_job_threshold
86
+ notes << {note_type: "Slow Job"} if runtime > slow_job_threshold
90
87
 
91
88
  notes.each do |note|
92
89
  data = {
@@ -118,6 +115,16 @@ module Notable
118
115
  end
119
116
  end
120
117
 
118
+ ActiveSupport.on_load(:action_controller) do
119
+ require "notable/unverified_request"
120
+ include Notable::UnverifiedRequest
121
+ end
122
+
123
+ ActiveSupport.on_load(:active_record) do
124
+ require "notable/validation_errors"
125
+ include Notable::ValidationErrors
126
+ end
127
+
121
128
  ActiveSupport.on_load(:active_job) do
122
129
  if Notable.jobs_enabled?
123
130
  require "notable/job_extensions"
@@ -4,8 +4,9 @@ module Notable
4
4
 
5
5
  initializer "notable" do |app|
6
6
  if Notable.requests_enabled?
7
- app.config.middleware.insert_after RequestStore::Middleware, Notable::Middleware
8
- ActionDispatch::DebugExceptions.send(:prepend, Notable::DebugExceptions)
7
+ # insert in same place as request_store
8
+ app.config.middleware.insert_after ActionDispatch::RequestId, Notable::Middleware
9
+ ActionDispatch::DebugExceptions.prepend Notable::DebugExceptions
9
10
  end
10
11
  end
11
12
  end
@@ -5,7 +5,7 @@ module Notable
5
5
  included do
6
6
  around_perform do |job, block|
7
7
  # no way to get queued_at time :(
8
- Notable.track_job(job.class.name, job.job_id, job.queue_name, nil) do
8
+ Notable.track_job(job.class.name, job.job_id, job.queue_name, nil, try(:notable_slow_job_threshold)) do
9
9
  block.call
10
10
  end
11
11
  end
@@ -1,6 +1,5 @@
1
1
  module Notable
2
2
  class Middleware
3
-
4
3
  def initialize(app)
5
4
  @app = app
6
5
  end
@@ -69,7 +68,8 @@ module Notable
69
68
  end
70
69
 
71
70
  [status, headers, body]
71
+ ensure
72
+ Notable.clear_notes
72
73
  end
73
-
74
74
  end
75
75
  end
@@ -1,5 +1,7 @@
1
- ActiveSupport::Notifications.subscribe "rack.attack" do |name, start, finish, request_id, req|
2
- if [:blacklist, :throttle].include?(req.env["rack.attack.match_type"])
3
- Notable.track "Throttle", req.env["rack.attack.matched"]
1
+ ActiveSupport::Notifications.subscribe "rack.attack" do |_name, _start, _finish, _request_id, req|
2
+ request = req.is_a?(Hash) ? req[:request] : req
3
+
4
+ if [:blacklist, :throttle].include?(request.env["rack.attack.match_type"])
5
+ Notable.track "Throttle", request.env["rack.attack.matched"]
4
6
  end
5
7
  end
@@ -1,3 +1,3 @@
1
- ActiveSupport::Notifications.subscribe "unpermitted_parameters.action_controller" do |name, start, finish, id, payload|
1
+ ActiveSupport::Notifications.subscribe "unpermitted_parameters.action_controller" do |_name, _start, _finish, _id, payload|
2
2
  Notable.track "Unpermitted Parameters", payload[:keys].join(", ")
3
3
  end
@@ -15,5 +15,3 @@ module Notable
15
15
  end
16
16
  end
17
17
  end
18
-
19
- ActionController::Base.send(:include, Notable::UnverifiedRequest)
@@ -13,5 +13,3 @@ module Notable
13
13
  end
14
14
  end
15
15
  end
16
-
17
- ActiveRecord::Base.send(:include, Notable::ValidationErrors)
@@ -1,3 +1,3 @@
1
1
  module Notable
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-18 00:00:00.000000000 Z
11
+ date: 2019-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: request_store
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: safely_block
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,49 +42,45 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.7'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.7'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
69
- description: Track notable requests and background jobs
70
- email:
71
- - andrew@chartkick.com
68
+ version: '0'
69
+ description:
70
+ email: andrew@chartkick.com
72
71
  executables: []
73
72
  extensions: []
74
73
  extra_rdoc_files: []
75
74
  files:
76
- - ".gitignore"
77
75
  - CHANGELOG.md
78
- - Gemfile
79
76
  - LICENSE.txt
80
77
  - README.md
81
- - Rakefile
82
78
  - app/models/notable/job.rb
83
79
  - app/models/notable/request.rb
84
80
  - lib/generators/notable/jobs_generator.rb
85
81
  - lib/generators/notable/requests_generator.rb
86
- - lib/generators/notable/templates/create_jobs.rb
87
- - lib/generators/notable/templates/create_requests.rb
82
+ - lib/generators/notable/templates/create_jobs.rb.tt
83
+ - lib/generators/notable/templates/create_requests.rb.tt
88
84
  - lib/notable.rb
89
85
  - lib/notable/debug_exceptions.rb
90
86
  - lib/notable/engine.rb
@@ -95,7 +91,6 @@ files:
95
91
  - lib/notable/unverified_request.rb
96
92
  - lib/notable/validation_errors.rb
97
93
  - lib/notable/version.rb
98
- - notable.gemspec
99
94
  homepage: https://github.com/ankane/notable
100
95
  licenses:
101
96
  - MIT
@@ -108,15 +103,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
103
  requirements:
109
104
  - - ">="
110
105
  - !ruby/object:Gem::Version
111
- version: '0'
106
+ version: '2.4'
112
107
  required_rubygems_version: !ruby/object:Gem::Requirement
113
108
  requirements:
114
109
  - - ">="
115
110
  - !ruby/object:Gem::Version
116
111
  version: '0'
117
112
  requirements: []
118
- rubyforge_project:
119
- rubygems_version: 2.7.6
113
+ rubygems_version: 3.0.3
120
114
  signing_key:
121
115
  specification_version: 4
122
116
  summary: Track notable requests and background jobs
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in notable.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"
data/notable.gemspec DELETED
@@ -1,26 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "notable/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "notable"
8
- spec.version = Notable::VERSION
9
- spec.authors = ["Andrew Kane"]
10
- spec.email = ["andrew@chartkick.com"]
11
- spec.summary = "Track notable requests and background jobs"
12
- spec.description = "Track notable requests and background jobs"
13
- spec.homepage = "https://github.com/ankane/notable"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_dependency "request_store"
22
- spec.add_dependency "safely_block", ">= 0.1.1"
23
-
24
- spec.add_development_dependency "bundler", "~> 1.7"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- end