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 +4 -4
- data/CHANGELOG.md +6 -0
- data/LICENSE.txt +1 -1
- data/README.md +20 -15
- data/lib/generators/notable/jobs_generator.rb +1 -3
- data/lib/generators/notable/requests_generator.rb +1 -3
- data/lib/generators/notable/templates/{create_jobs.rb → create_jobs.rb.tt} +2 -2
- data/lib/generators/notable/templates/{create_requests.rb → create_requests.rb.tt} +1 -1
- data/lib/notable.rb +25 -18
- data/lib/notable/engine.rb +3 -2
- data/lib/notable/job_extensions.rb +1 -1
- data/lib/notable/middleware.rb +2 -2
- data/lib/notable/throttle.rb +5 -3
- data/lib/notable/unpermitted_parameters.rb +1 -1
- data/lib/notable/unverified_request.rb +0 -2
- data/lib/notable/validation_errors.rb +0 -2
- data/lib/notable/version.rb +1 -1
- metadata +19 -25
- data/.gitignore +0 -14
- data/Gemfile +0 -4
- data/Rakefile +0 -1
- data/notable.gemspec +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a1ecb0013fc63daaa3bec5b0b451fca47d39617ca73c18f72f6dfcefb368bbc
|
4
|
+
data.tar.gz: f156679280ff767f0c99c6dc768f1b25cfc761759935b86cc5d64092d1a6d19a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc5ae406db635275367d0f609b2e28311e1e467ee99c13b7acc1184a22dc998a2a5e645a9a4f3b529403ded4e7aa2f52a818bbd0da7bd40a021163be207fd742
|
7
|
+
data.tar.gz: 84a13882970bec183ae857ad5641531a4267c1cea855842e3a77606923271cbd92246ae4d43df5a997a63fb569b8fa6fb012ffb214eccbce9bc8c7c63c7842a2
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
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
|
-
|
39
|
+
rails db:migrate
|
40
40
|
```
|
41
41
|
|
42
|
-
|
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
|
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 =
|
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 =
|
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
|
132
|
+
Notable.slow_job_threshold = 60.seconds
|
133
133
|
```
|
134
134
|
|
135
|
-
|
135
|
+
To set a threshold for a specific job, use:
|
136
136
|
|
137
137
|
```ruby
|
138
|
-
|
139
|
-
|
140
|
-
|
138
|
+
class CustomJob < ApplicationJob
|
139
|
+
def notable_slow_job_threshold
|
140
|
+
5.minutes
|
141
|
+
end
|
142
|
+
end
|
141
143
|
```
|
142
144
|
|
143
|
-
|
145
|
+
Custom track method
|
144
146
|
|
145
|
-
|
146
|
-
|
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
|
-
|
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
|
-
|
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.
|
10
|
-
t.
|
9
|
+
t.float :runtime
|
10
|
+
t.float :queued_time
|
11
11
|
t.timestamp :created_at
|
12
12
|
end
|
13
13
|
end
|
data/lib/notable.rb
CHANGED
@@ -1,19 +1,15 @@
|
|
1
|
-
|
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
|
-
#
|
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,
|
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
|
-
|
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
|
-
|
61
|
+
Thread.current[:notable_notes] ||= []
|
66
62
|
end
|
67
63
|
|
68
64
|
def self.clear_notes
|
69
|
-
|
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 >
|
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"
|
data/lib/notable/engine.rb
CHANGED
@@ -4,8 +4,9 @@ module Notable
|
|
4
4
|
|
5
5
|
initializer "notable" do |app|
|
6
6
|
if Notable.requests_enabled?
|
7
|
-
|
8
|
-
ActionDispatch::
|
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
|
data/lib/notable/middleware.rb
CHANGED
data/lib/notable/throttle.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
ActiveSupport::Notifications.subscribe "rack.attack" do |
|
2
|
-
|
3
|
-
|
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 |
|
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
|
data/lib/notable/version.rb
CHANGED
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.
|
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:
|
11
|
+
date: 2019-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
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: '
|
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: '
|
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: '
|
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: '
|
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: '
|
69
|
-
description:
|
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: '
|
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
|
-
|
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
data/Gemfile
DELETED
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
|