notable 0.4.0 → 0.5.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: f7ba556539ddc3c2c67a5fc37623c138c15432f32e962ff60118863ecd5ff3b7
4
- data.tar.gz: a301a3c1a1f84c0bce4dd83e1a965210d6ccb08586c9b2bb6f51fb10676d3f8c
3
+ metadata.gz: 6901159f15d1920eaf07ff40c239d4b05d75bb469c55ddebc67874703e362efe
4
+ data.tar.gz: 5092cf2e632b615faaae6a1027104597ab4a434102374f9fc7a0eff7c5246b46
5
5
  SHA512:
6
- metadata.gz: 9f7cb09c2f95526ebd6862199fcbe8889a50919c93e63293a5142efd5346998b7d9c803c358c0e283db43967e7f7303e22409b3afbc5206ea78939de7846ab84
7
- data.tar.gz: c7612312bafaefbe1cee0f3b70f1bb0dff3bc0963e8116f1c110452d2b6634a8f3df1c7455dce10a058c934a2da71edb5569396d020292c15a075bdfa63e48f7
6
+ metadata.gz: fc4b419c11fc0dae0cac44c8ba581cff4df203cb4be3b462876e46b315139b3f2e71737ef69e2c28c07ed05ce3840aab6602ada5739bb51a0e5b2d5dc5abfbd4
7
+ data.tar.gz: c0ce85fa70b1930db449a3570f29c2e41adf13db86c5a2ade506978294de6daf82e4231ea7ce1fbe226b82cbcac63c87db4aaeb9748b114796b34610650913f5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.5.0 (2023-07-02)
2
+
3
+ - Dropped support for Ruby < 3 and Rails < 6.1
4
+
5
+ ## 0.4.1 (2022-09-26)
6
+
7
+ - Switched to monotonic time
8
+
1
9
  ## 0.4.0 (2022-01-10)
2
10
 
3
11
  - Dropped support for Ruby < 2.6 and Rails < 5.2
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2022 Andrew Kane
1
+ Copyright (c) 2014-2023 Andrew Kane
2
2
 
3
3
  MIT License
4
4
 
@@ -5,9 +5,9 @@ module Notable
5
5
  end
6
6
 
7
7
  def call(env)
8
- start_time = Time.now
8
+ start_time = Notable.monotonic_time
9
9
  status, headers, body = @app.call(env)
10
- request_time = Time.now - start_time
10
+ request_time = Notable.monotonic_time - start_time
11
11
 
12
12
  Safely.safely do
13
13
  if env["action_dispatch.exception"]
@@ -22,11 +22,11 @@ module Notable
22
22
  "Error"
23
23
  end
24
24
  Notable.track message, "#{e.class.name}: #{e.message}"
25
- elsif (!status or status.to_i >= 400) and !Notable.notes.any?
25
+ elsif (!status || status.to_i >= 400) && !Notable.notes.any?
26
26
  Notable.track Rack::Utils::HTTP_STATUS_CODES[status.to_i]
27
27
  end
28
28
 
29
- if request_time > Notable.slow_request_threshold and status.to_i != 503
29
+ if request_time > Notable.slow_request_threshold && status.to_i != 503
30
30
  Notable.track "Slow Request"
31
31
  end
32
32
 
@@ -1,3 +1,3 @@
1
1
  module Notable
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/notable.rb CHANGED
@@ -3,13 +3,13 @@ require "active_support"
3
3
  require "safely/core"
4
4
 
5
5
  # modules
6
- require "notable/debug_exceptions"
7
- require "notable/middleware"
8
- require "notable/throttle"
9
- require "notable/unpermitted_parameters"
10
- require "notable/version"
6
+ require_relative "notable/debug_exceptions"
7
+ require_relative "notable/middleware"
8
+ require_relative "notable/throttle"
9
+ require_relative "notable/unpermitted_parameters"
10
+ require_relative "notable/version"
11
11
 
12
- require "notable/engine" if defined?(Rails)
12
+ require_relative "notable/engine" if defined?(Rails)
13
13
 
14
14
  module Notable
15
15
  class << self
@@ -69,9 +69,8 @@ module Notable
69
69
  slow_job_threshold ||= Notable.slow_job_threshold
70
70
  exception = nil
71
71
  notes = nil
72
- start_time = Time.now
73
- created_at = Time.parse(created_at) if created_at.is_a?(String)
74
- queued_time = created_at ? start_time - created_at : nil
72
+ started_at = Time.now # wall time
73
+ start_time = monotonic_time
75
74
  begin
76
75
  yield
77
76
  rescue Exception => e
@@ -81,11 +80,16 @@ module Notable
81
80
  notes = Notable.notes
82
81
  Notable.clear_notes
83
82
  end
84
- runtime = Time.now - start_time
83
+ runtime = monotonic_time - start_time
85
84
 
86
85
  Safely.safely do
87
86
  notes << {note_type: "Slow Job"} if runtime > slow_job_threshold
88
87
 
88
+ if notes.any?
89
+ created_at = Time.parse(created_at) if created_at.is_a?(String)
90
+ queued_time = created_at ? [started_at - created_at, 0].max : nil
91
+ end
92
+
89
93
  notes.each do |note|
90
94
  data = {
91
95
  note_type: note[:note_type],
@@ -114,6 +118,10 @@ module Notable
114
118
  addr.mask(48).to_s
115
119
  end
116
120
  end
121
+
122
+ def self.monotonic_time
123
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
124
+ end
117
125
  end
118
126
 
119
127
  ActiveSupport.on_load(:action_controller) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.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: 2022-01-11 00:00:00.000000000 Z
11
+ date: 2023-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: '6.1'
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: '5.2'
26
+ version: '6.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: safely_block
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.1
33
+ version: '0.4'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.1.1
40
+ version: '0.4'
41
41
  description:
42
42
  email: andrew@ankane.org
43
43
  executables: []
@@ -75,14 +75,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
75
  requirements:
76
76
  - - ">="
77
77
  - !ruby/object:Gem::Version
78
- version: '2.6'
78
+ version: '3'
79
79
  required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  requirements: []
85
- rubygems_version: 3.3.3
85
+ rubygems_version: 3.4.10
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Track notable requests and background jobs