notable 0.4.0 → 0.4.1

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: 714094d0059bb07c9e66ab382626795bc81b1e8cdd695f7354198531bab9caa9
4
+ data.tar.gz: bc36e2654ebd17188b2fb913d3f745ebf40487a57f1e0e82b3ca6a041d4d9975
5
5
  SHA512:
6
- metadata.gz: 9f7cb09c2f95526ebd6862199fcbe8889a50919c93e63293a5142efd5346998b7d9c803c358c0e283db43967e7f7303e22409b3afbc5206ea78939de7846ab84
7
- data.tar.gz: c7612312bafaefbe1cee0f3b70f1bb0dff3bc0963e8116f1c110452d2b6634a8f3df1c7455dce10a058c934a2da71edb5569396d020292c15a075bdfa63e48f7
6
+ metadata.gz: 1590cf5d58fcb9d9bf8021081392b089390218ae3fc525a44f4404dad41302c12c54117aeee658386855321458e17360f12b5ef98bb263e401ee106a95820341
7
+ data.tar.gz: d128c411ed50df17b835d6dcddad2d9dcf3bc0c7094756586709316f604ba0a63cbb5ca00d79f192285895d854f9f8a3c2d4ec3adcf14699cc016b097fa44923
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.4.1 (2022-09-26)
2
+
3
+ - Switched to monotonic time
4
+
1
5
  ## 0.4.0 (2022-01-10)
2
6
 
3
7
  - Dropped support for Ruby < 2.6 and Rails < 5.2
@@ -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.4.1"
3
3
  end
data/lib/notable.rb CHANGED
@@ -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.4.1
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: 2022-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  requirements: []
85
- rubygems_version: 3.3.3
85
+ rubygems_version: 3.3.7
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Track notable requests and background jobs