lhc 10.5.4 → 11.0.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: d6a58802c72c372ef590e6ce3b026f6ab4714edb46264cee52226d18072dec11
4
- data.tar.gz: 4ac49035c4ea3ab95e3860e3821c1dadeeb1620311cf59644ae419d9cb5f902e
3
+ metadata.gz: b98d689381652202d5204b16f76d5171c7650362ed047d733447f04de02dbac5
4
+ data.tar.gz: cb43cb26d090cb3e387e9e1b17ece3c96a7aab2b07fb54592f1a594af0dd3d6a
5
5
  SHA512:
6
- metadata.gz: c41d503ece87ae60f8569cf6dfe2b92a6c0b97c0c59ec268ad7e1df627d2b2db7a1a0f485fe1b03e954b8d1fec7b8f5b7d391b16b89804244441fabf1caee881
7
- data.tar.gz: 632a6f16c9b8c59a1fae1a0a46810c67b22f9950e67edbf4512599ee993c926a524db4fd6baa69d81df9a583ffaca07e7940516c420903274617bf6dc0a55f88
6
+ metadata.gz: 02d1689b6669a88dee07d03916d8d3972a5733abb577af695509bbe8c867c6357daefc94bb9008205378a0ccfc65f6de7006fcf66f3425e651ebc92b76e1d1bf
7
+ data.tar.gz: 4149bfbcb67cd51d4c3743353357d663548a20812035b1d9e051ed9990ca4de73936dff7075db59193113009f8866ccce94a09816bd29942345e2e146cf6f2c9
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.4.3
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.request_key, 'Counter of all LHC requests.')
24
- LHC::Prometheus.client.registry.histogram(LHC::Prometheus.times_key, 'Times for all LHC requests.')
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.request_key)
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.times_key)
39
- .observe({}, response.time_ms)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LHC
4
- VERSION ||= '10.5.4'
4
+ VERSION ||= '11.0.0'
5
5
  end
@@ -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(:test_app_lhc_requests, 'Counter of all LHC requests.')
20
+ .with(:lhc_requests, 'Counter of all LHC requests.')
21
21
  expect(Prometheus::Client.registry).to receive(:histogram).and_call_original.once
22
- .with(:test_app_lhc_times, 'Times for all LHC requests.')
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(:test_app_lhc_requests)
35
+ .with(:lhc_requests)
36
36
  expect(Prometheus::Client.registry).to receive(:get).and_return(times_registry_double).once
37
- .with(:test_app_lhc_times)
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: 10.5.4
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-10-25 00:00:00.000000000 Z
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
- rubyforge_project:
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