lhc 10.5.4 → 11.0.0
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/.ruby-version +1 -1
- data/lib/lhc/interceptors/prometheus.rb +18 -14
- data/lib/lhc/version.rb +1 -1
- data/spec/interceptors/prometheus_spec.rb +9 -6
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b98d689381652202d5204b16f76d5171c7650362ed047d733447f04de02dbac5
|
4
|
+
data.tar.gz: cb43cb26d090cb3e387e9e1b17ece3c96a7aab2b07fb54592f1a594af0dd3d6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02d1689b6669a88dee07d03916d8d3972a5733abb577af695509bbe8c867c6357daefc94bb9008205378a0ccfc65f6de7006fcf66f3425e651ebc92b76e1d1bf
|
7
|
+
data.tar.gz: 4149bfbcb67cd51d4c3743353357d663548a20812035b1d9e051ed9990ca4de73936dff7075db59193113009f8866ccce94a09816bd29942345e2e146cf6f2c9
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.6.5
|
@@ -5,37 +5,41 @@ class LHC::Prometheus < LHC::Interceptor
|
|
5
5
|
|
6
6
|
config_accessor :client, :namespace
|
7
7
|
|
8
|
+
REQUEST_COUNTER_KEY = :lhc_requests
|
9
|
+
REQUEST_HISTOGRAM_KEY = :lhc_request_seconds
|
10
|
+
|
8
11
|
class << self
|
9
12
|
attr_accessor :registered
|
10
13
|
end
|
11
14
|
|
12
|
-
def self.request_key
|
13
|
-
[LHC::Prometheus.namespace, 'lhc_requests'].join('_').to_sym
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.times_key
|
17
|
-
[LHC::Prometheus.namespace, 'lhc_times'].join('_').to_sym
|
18
|
-
end
|
19
|
-
|
20
15
|
def initialize(request)
|
21
16
|
super(request)
|
22
17
|
return if LHC::Prometheus.registered || LHC::Prometheus.client.blank?
|
23
|
-
LHC::Prometheus.client.registry.counter(LHC::Prometheus
|
24
|
-
LHC::Prometheus.client.registry.histogram(LHC::Prometheus
|
18
|
+
LHC::Prometheus.client.registry.counter(LHC::Prometheus::REQUEST_COUNTER_KEY, 'Counter of all LHC requests.')
|
19
|
+
LHC::Prometheus.client.registry.histogram(LHC::Prometheus::REQUEST_HISTOGRAM_KEY, 'Request timings for all LHC requests in seconds.')
|
25
20
|
LHC::Prometheus.registered = true
|
26
21
|
end
|
27
22
|
|
28
23
|
def after_response
|
29
24
|
return if !LHC::Prometheus.registered || LHC::Prometheus.client.blank?
|
25
|
+
|
26
|
+
host = URI.parse(request.url).host
|
27
|
+
|
30
28
|
LHC::Prometheus.client.registry
|
31
|
-
.get(LHC::Prometheus
|
29
|
+
.get(LHC::Prometheus::REQUEST_COUNTER_KEY)
|
32
30
|
.increment(
|
33
31
|
code: response.code,
|
34
32
|
success: response.success?,
|
35
|
-
timeout: response.timeout
|
33
|
+
timeout: response.timeout?,
|
34
|
+
host: host,
|
35
|
+
app: LHC::Prometheus.namespace
|
36
36
|
)
|
37
|
+
|
37
38
|
LHC::Prometheus.client.registry
|
38
|
-
.get(LHC::Prometheus
|
39
|
-
.observe({
|
39
|
+
.get(LHC::Prometheus::REQUEST_HISTOGRAM_KEY)
|
40
|
+
.observe({
|
41
|
+
host: host,
|
42
|
+
app: LHC::Prometheus.namespace
|
43
|
+
}, response.time)
|
40
44
|
end
|
41
45
|
end
|
data/lib/lhc/version.rb
CHANGED
@@ -17,9 +17,9 @@ describe LHC::Prometheus do
|
|
17
17
|
context 'registering' do
|
18
18
|
it 'creates a counter and histogram registry in the prometheus client' do
|
19
19
|
expect(Prometheus::Client.registry).to receive(:counter).and_call_original.once
|
20
|
-
.with(:
|
20
|
+
.with(:lhc_requests, 'Counter of all LHC requests.')
|
21
21
|
expect(Prometheus::Client.registry).to receive(:histogram).and_call_original.once
|
22
|
-
.with(:
|
22
|
+
.with(:lhc_request_seconds, 'Request timings for all LHC requests in seconds.')
|
23
23
|
|
24
24
|
LHC.get('http://local.ch')
|
25
25
|
LHC.get('http://local.ch') # second request, registration should happen only once
|
@@ -32,18 +32,21 @@ describe LHC::Prometheus do
|
|
32
32
|
|
33
33
|
it 'logs monitoring information to the created registries' do
|
34
34
|
expect(Prometheus::Client.registry).to receive(:get).and_return(requests_registry_double).once
|
35
|
-
.with(:
|
35
|
+
.with(:lhc_requests)
|
36
36
|
expect(Prometheus::Client.registry).to receive(:get).and_return(times_registry_double).once
|
37
|
-
.with(:
|
37
|
+
.with(:lhc_request_seconds)
|
38
38
|
|
39
39
|
expect(requests_registry_double).to receive(:increment).once
|
40
40
|
.with(
|
41
41
|
code: 200,
|
42
42
|
success: true,
|
43
|
-
timeout: false
|
43
|
+
timeout: false,
|
44
|
+
app: 'test_app',
|
45
|
+
host: 'local.ch'
|
44
46
|
)
|
47
|
+
|
45
48
|
expect(times_registry_double).to receive(:observe).once
|
46
|
-
.with({}, 0)
|
49
|
+
.with({ host: 'local.ch', app: 'test_app' }, 0)
|
47
50
|
|
48
51
|
LHC.get('http://local.ch')
|
49
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 11.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhc/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -400,8 +400,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
400
400
|
version: '0'
|
401
401
|
requirements:
|
402
402
|
- Ruby >= 2.0.0
|
403
|
-
|
404
|
-
rubygems_version: 2.7.9
|
403
|
+
rubygems_version: 3.0.6
|
405
404
|
signing_key:
|
406
405
|
specification_version: 4
|
407
406
|
summary: Advanced HTTP Client for Ruby, fueled with interceptors
|