yabeda-latency 0.1.1 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/yabeda/latency/collector.rb +19 -11
- data/lib/yabeda/latency/version.rb +1 -1
- metadata +2 -3
- data/Gemfile.lock +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17004f75788a8617c66c902ac6960642f6602c6b86c1669bc5d60977144fefaf
|
4
|
+
data.tar.gz: 86d188ae431880ef8c669513c24ae4ca2b468901fa5ea8af349b66c1b5bbba76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9effa468a27201895c214a411e9ce27e9886d7b7381784cf695a9a1d429d1dbb1d70e8a287dce39c218acfb7c35a81a253bcb7b2f0bcd8642160948603edc7b3
|
7
|
+
data.tar.gz: 874332278744061281ec5206f710eec5884998c1fa4e262b929f938fab47255296db0fa6944f41010335fc735dccab741d2db79ef1d498abd75a488e6f5e3aac
|
data/.gitignore
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Yabeda
|
4
4
|
module Latency
|
5
|
-
LATENCY_BUCKETS = [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5
|
5
|
+
LATENCY_BUCKETS = [0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5].freeze
|
6
6
|
EMPTY_HASH = {}.freeze
|
7
7
|
REQUEST_START_HEADER = 'HTTP_X_REQUEST_START'
|
8
8
|
|
@@ -14,23 +14,29 @@ module Yabeda
|
|
14
14
|
class Collector
|
15
15
|
attr_reader :app, :registry
|
16
16
|
|
17
|
-
def initialize(app, metrics_prefix: :http_server)
|
17
|
+
def initialize(app, metrics_prefix: :http_server, debug: false)
|
18
18
|
@app = app
|
19
19
|
@metrics_prefix = metrics_prefix
|
20
|
+
@debug = debug
|
20
21
|
|
21
22
|
init_request_metrics
|
22
23
|
end
|
23
24
|
|
24
25
|
def call(env) # :nodoc:
|
25
26
|
now = Time.now
|
26
|
-
|
27
|
-
measure(latency_seconds) unless latency_seconds.nil?
|
28
|
-
ensure
|
27
|
+
observe(env, now)
|
29
28
|
@app.call(env)
|
30
29
|
end
|
31
30
|
|
32
31
|
protected
|
33
32
|
|
33
|
+
def observe(env, now)
|
34
|
+
latency_seconds = calculate_latency_seconds(env, now)
|
35
|
+
measure(latency_seconds) unless latency_seconds.nil?
|
36
|
+
rescue StandardError => e
|
37
|
+
warn "Could not observe latency (#{e.message})" if @debug
|
38
|
+
end
|
39
|
+
|
34
40
|
# rubocop:disable Metrics/MethodLength
|
35
41
|
def init_request_metrics
|
36
42
|
prefix = @metrics_prefix
|
@@ -38,7 +44,7 @@ module Yabeda
|
|
38
44
|
Yabeda.configure do
|
39
45
|
group prefix do
|
40
46
|
histogram(
|
41
|
-
:
|
47
|
+
:request_latency,
|
42
48
|
comment: 'The time for the HTTP request to reach Rack application',
|
43
49
|
unit: :seconds,
|
44
50
|
per: :field,
|
@@ -51,7 +57,7 @@ module Yabeda
|
|
51
57
|
# rubocop:enable Metrics/MethodLength
|
52
58
|
|
53
59
|
def metric
|
54
|
-
@metric ||= Yabeda.__send__(@metrics_prefix).
|
60
|
+
@metric ||= Yabeda.__send__(@metrics_prefix).request_latency
|
55
61
|
end
|
56
62
|
|
57
63
|
def measure(latency_seconds)
|
@@ -62,11 +68,13 @@ module Yabeda
|
|
62
68
|
|
63
69
|
def calculate_latency_seconds(env, now)
|
64
70
|
raw_header_value = env[REQUEST_START_HEADER]
|
65
|
-
|
71
|
+
request_start_timestamp_s = extract_timestamp_from_header_value(raw_header_value)
|
72
|
+
|
73
|
+
puts "X-Request-Start: #{raw_header_value}, Now: #{now.to_f}" if @debug
|
66
74
|
|
67
|
-
return unless
|
75
|
+
return unless request_start_timestamp_s
|
68
76
|
|
69
|
-
now.to_f -
|
77
|
+
now.to_f - request_start_timestamp_s
|
70
78
|
end
|
71
79
|
|
72
80
|
def extract_timestamp_from_header_value(value)
|
@@ -81,7 +89,7 @@ module Yabeda
|
|
81
89
|
|
82
90
|
return unless str
|
83
91
|
|
84
|
-
str.
|
92
|
+
str.to_f
|
85
93
|
end
|
86
94
|
end
|
87
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yabeda-latency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Ker-Seymer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yabeda
|
@@ -38,7 +38,6 @@ files:
|
|
38
38
|
- ".travis.yml"
|
39
39
|
- CODE_OF_CONDUCT.md
|
40
40
|
- Gemfile
|
41
|
-
- Gemfile.lock
|
42
41
|
- LICENSE.txt
|
43
42
|
- README.md
|
44
43
|
- Rakefile
|
data/Gemfile.lock
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
yabeda-latency (0.1.1)
|
5
|
-
yabeda (~> 0.2)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
ast (2.4.2)
|
11
|
-
coderay (1.1.3)
|
12
|
-
concurrent-ruby (1.1.8)
|
13
|
-
diff-lcs (1.4.4)
|
14
|
-
dry-initializer (3.0.3)
|
15
|
-
method_source (1.0.0)
|
16
|
-
parallel (1.20.1)
|
17
|
-
parser (3.0.0.0)
|
18
|
-
ast (~> 2.4.1)
|
19
|
-
pry (0.13.1)
|
20
|
-
coderay (~> 1.1)
|
21
|
-
method_source (~> 1.0)
|
22
|
-
rainbow (3.0.0)
|
23
|
-
rake (12.3.3)
|
24
|
-
regexp_parser (2.0.3)
|
25
|
-
rexml (3.2.4)
|
26
|
-
rspec (3.10.0)
|
27
|
-
rspec-core (~> 3.10.0)
|
28
|
-
rspec-expectations (~> 3.10.0)
|
29
|
-
rspec-mocks (~> 3.10.0)
|
30
|
-
rspec-core (3.10.1)
|
31
|
-
rspec-support (~> 3.10.0)
|
32
|
-
rspec-expectations (3.10.1)
|
33
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
-
rspec-support (~> 3.10.0)
|
35
|
-
rspec-mocks (3.10.1)
|
36
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
-
rspec-support (~> 3.10.0)
|
38
|
-
rspec-support (3.10.1)
|
39
|
-
rubocop (1.9.1)
|
40
|
-
parallel (~> 1.10)
|
41
|
-
parser (>= 3.0.0.0)
|
42
|
-
rainbow (>= 2.2.2, < 4.0)
|
43
|
-
regexp_parser (>= 1.8, < 3.0)
|
44
|
-
rexml
|
45
|
-
rubocop-ast (>= 1.2.0, < 2.0)
|
46
|
-
ruby-progressbar (~> 1.7)
|
47
|
-
unicode-display_width (>= 1.4.0, < 3.0)
|
48
|
-
rubocop-ast (1.4.1)
|
49
|
-
parser (>= 2.7.1.5)
|
50
|
-
ruby-progressbar (1.11.0)
|
51
|
-
unicode-display_width (2.0.0)
|
52
|
-
yabeda (0.7.0)
|
53
|
-
concurrent-ruby
|
54
|
-
dry-initializer
|
55
|
-
|
56
|
-
PLATFORMS
|
57
|
-
ruby
|
58
|
-
|
59
|
-
DEPENDENCIES
|
60
|
-
pry
|
61
|
-
rake (~> 12.0)
|
62
|
-
rspec (~> 3.0)
|
63
|
-
rubocop
|
64
|
-
yabeda
|
65
|
-
yabeda-latency!
|
66
|
-
|
67
|
-
BUNDLED WITH
|
68
|
-
2.1.1
|