lhc 9.1.2 → 9.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -9
- data/docs/interceptors.md +2 -1
- data/docs/interceptors/logging.md +29 -0
- data/docs/interceptors/monitoring.md +18 -12
- data/lib/lhc.rb +5 -2
- data/lib/lhc/interceptors/logging.rb +19 -0
- data/lib/lhc/version.rb +1 -1
- data/spec/interceptors/logging/main_spec.rb +21 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e82411889a538078642c154032b132cec72cf53b
|
4
|
+
data.tar.gz: 12f685a1fb5cb8e9452ecd3c2f8ffaf2621a7122
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efa93d6795be75faa9151a9b4fb273338e6fe7ff4d9772302b3f6a04b08364c3111b71e7b0d3529d2af8a8f965d9e23c5d71df5141a83677dfa21bafd2a26738
|
7
|
+
data.tar.gz: 8d88b401cfe5122a19cb6ac5c2f5b2478a0bf231858e7430edd133f4f6c592e165f9ca2c6bf1cbf8e433a93027f7892bbcc890bd638c1cec4d8419b158331b8e
|
data/README.md
CHANGED
@@ -259,17 +259,11 @@ To monitor and manipulate the http communication done with LHC, you can define i
|
|
259
259
|
|
260
260
|
→ [Read more about interceptors](docs/interceptors.md)
|
261
261
|
|
262
|
-
|
263
|
-
like
|
264
|
-
[Caching](/docs/interceptors/caching.md),
|
265
|
-
[Monitoring](/docs/interceptors/monitoring.md),
|
266
|
-
[Authentication](/docs/interceptors/authentication.md),
|
267
|
-
[Retry](/docs/interceptors/retry.md),
|
268
|
-
[Rollbar](/docs/interceptors/rollbar.md),
|
269
|
-
[Prometheus](/docs/interceptors/prometheus.md).
|
262
|
+
### Core Interceptors
|
270
263
|
|
271
|
-
|
264
|
+
There are some interceptors that are part of LHC already, that cover some basic usecases:
|
272
265
|
|
266
|
+
[Available Core Interceptors](/docs/interceptors)
|
273
267
|
|
274
268
|
## License
|
275
269
|
|
data/docs/interceptors.md
CHANGED
@@ -23,7 +23,8 @@ Interceptors
|
|
23
23
|
## Core Interceptors
|
24
24
|
|
25
25
|
There are some interceptors that are part of LHC already, that cover some basic usecases:
|
26
|
-
|
26
|
+
|
27
|
+
[Available Core Interceptors](/docs/interceptors)
|
27
28
|
|
28
29
|
## Callbacks
|
29
30
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Logging Interceptor
|
2
|
+
|
3
|
+
The logging interceptor logs all requests done with LHC to the Rails logs.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
LHC.config.interceptors = [LHC::Logging]
|
9
|
+
|
10
|
+
LHC::Logging.logger = Rails.logger
|
11
|
+
```
|
12
|
+
|
13
|
+
## What and how it logs
|
14
|
+
|
15
|
+
The logging Interceptor logs basic information about the request and the response:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
LHC.get('http://local.ch')
|
19
|
+
# Before LHC request<70128730317500> GET http://local.ch at 2018-05-23T07:53:19+02:00 Params={} Headers={\"User-Agent\"=>\"Typhoeus - https://github.com/typhoeus/typhoeus\", \"Expect\"=>\"\"}
|
20
|
+
# After LHC response for request<70128730317500>: GET http://local.ch at 2018-05-23T07:53:28+02:00 Time=0ms URL=http://local.ch:80/
|
21
|
+
```
|
22
|
+
|
23
|
+
## Configure
|
24
|
+
|
25
|
+
You can configure the logger beeing used by the logging interceptor:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
LHC::Logging.logger = Another::Logger
|
29
|
+
```
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# Monitoring Interceptor
|
2
2
|
|
3
|
-
|
3
|
+
The monitoring interceptor reports all requests done with LHC to a given StatsD instance.
|
4
|
+
|
5
|
+
## Installation
|
4
6
|
|
5
7
|
```ruby
|
6
8
|
LHC.config.interceptors = [LHC::Monitoring]
|
@@ -12,8 +14,17 @@ You also have to configure statsd in order to have the monitoring interceptor re
|
|
12
14
|
LHC::Monitoring.statsd = <your-instance-of-statsd>
|
13
15
|
```
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
## What it tracks
|
18
|
+
|
19
|
+
It tracks request attempts with `before_request` and `after_request` (counts).
|
20
|
+
|
21
|
+
In case your workers/processes are getting killed due limited time constraints,
|
22
|
+
you are able to detect deltas with relying on "before_request", and "after_request" counts:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
"lhc.<app_name>.<env>.<host>.<http_method>.before_request", 1
|
26
|
+
"lhc.<app_name>.<env>.<host>.<http_method>.after_request", 1
|
27
|
+
```
|
17
28
|
|
18
29
|
In case of a successful response it reports the response code with a count and the response time with a gauge value.
|
19
30
|
|
@@ -25,14 +36,6 @@ In case of a successful response it reports the response code with a count and t
|
|
25
36
|
"lhc.<app_name>.<env>.<host>.<http_method>.time", 43
|
26
37
|
```
|
27
38
|
|
28
|
-
In case your workers/processes are getting killed due limited time constraints,
|
29
|
-
you are able to detect deltas with relying on "before_request", and "after_request" counts:
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
"lhc.<app_name>.<env>.<host>.<http_method>.before_request", 1
|
33
|
-
"lhc.<app_name>.<env>.<host>.<http_method>.after_request", 1
|
34
|
-
```
|
35
|
-
|
36
39
|
Timeouts are also reported:
|
37
40
|
|
38
41
|
```ruby
|
@@ -41,7 +44,10 @@ Timeouts are also reported:
|
|
41
44
|
|
42
45
|
All the dots in the host are getting replaced with underscore (_), because dot is the default separator in graphite.
|
43
46
|
|
44
|
-
|
47
|
+
|
48
|
+
## Configure
|
49
|
+
|
50
|
+
It is possible to set the key for Monitoring Interceptor on per request basis:
|
45
51
|
|
46
52
|
```ruby
|
47
53
|
LHC.get('http://local.ch', monitoring_key: 'local_website')
|
data/lib/lhc.rb
CHANGED
@@ -18,12 +18,15 @@ module LHC
|
|
18
18
|
'lhc/interceptors/auth'
|
19
19
|
autoload :Caching,
|
20
20
|
'lhc/interceptors/caching'
|
21
|
+
autoload :DefaultTimeout,
|
22
|
+
'lhc/interceptors/default_timeout'
|
23
|
+
autoload :Logging,
|
24
|
+
'lhc/interceptors/logging'
|
21
25
|
autoload :Prometheus,
|
22
26
|
'lhc/interceptors/prometheus'
|
23
27
|
autoload :Retry,
|
24
28
|
'lhc/interceptors/retry'
|
25
|
-
|
26
|
-
'lhc/interceptors/default_timeout'
|
29
|
+
|
27
30
|
autoload :Config,
|
28
31
|
'lhc/config'
|
29
32
|
autoload :Endpoint,
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class LHC::Logging < LHC::Interceptor
|
2
|
+
|
3
|
+
include ActiveSupport::Configurable
|
4
|
+
config_accessor :logger
|
5
|
+
|
6
|
+
def before_request
|
7
|
+
return unless logger
|
8
|
+
logger.info(
|
9
|
+
"Before LHC request<#{request.object_id}> #{request.method.upcase} #{request.url} at #{DateTime.now} Params=#{request.params} Headers=#{request.headers}"
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def after_response
|
14
|
+
return unless logger
|
15
|
+
logger.info(
|
16
|
+
"After LHC response for request<#{request.object_id}> #{request.method.upcase} #{request.url} at #{DateTime.now} Time=#{response.time_ms}ms URL=#{response.effective_url}"
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
data/lib/lhc/version.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHC::Logging do
|
4
|
+
let(:logger) { spy('logger') }
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
LHC.config.interceptors = [LHC::Logging]
|
8
|
+
LHC::Logging.logger = logger
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'does log information before and after every request made with LHC' do
|
12
|
+
stub_request(:get, 'http://local.ch').to_return(status: 200)
|
13
|
+
LHC.get('http://local.ch')
|
14
|
+
expect(logger).to have_received(:info).once.with(
|
15
|
+
%r{Before LHC request<\d+> GET http://local.ch at \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2} Params={} Headers={.*?}}
|
16
|
+
)
|
17
|
+
expect(logger).to have_received(:info).once.with(
|
18
|
+
%r{After LHC response for request<\d+> GET http://local.ch at \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}:\d{2} Time=0ms URL=http://local.ch:80/}
|
19
|
+
)
|
20
|
+
end
|
21
|
+
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: 9.
|
4
|
+
version: 9.2.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: 2018-
|
11
|
+
date: 2018-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -195,6 +195,7 @@ files:
|
|
195
195
|
- docs/interceptors/authentication.md
|
196
196
|
- docs/interceptors/caching.md
|
197
197
|
- docs/interceptors/default_timeout.md
|
198
|
+
- docs/interceptors/logging.md
|
198
199
|
- docs/interceptors/monitoring.md
|
199
200
|
- docs/interceptors/prometheus.md
|
200
201
|
- docs/interceptors/retry.md
|
@@ -222,6 +223,7 @@ files:
|
|
222
223
|
- lib/lhc/interceptors/auth.rb
|
223
224
|
- lib/lhc/interceptors/caching.rb
|
224
225
|
- lib/lhc/interceptors/default_timeout.rb
|
226
|
+
- lib/lhc/interceptors/logging.rb
|
225
227
|
- lib/lhc/interceptors/monitoring.rb
|
226
228
|
- lib/lhc/interceptors/prometheus.rb
|
227
229
|
- lib/lhc/interceptors/retry.rb
|
@@ -313,6 +315,7 @@ files:
|
|
313
315
|
- spec/interceptors/default_timeout/main_spec.rb
|
314
316
|
- spec/interceptors/define_spec.rb
|
315
317
|
- spec/interceptors/dup_spec.rb
|
318
|
+
- spec/interceptors/logging/main_spec.rb
|
316
319
|
- spec/interceptors/monitoring/main_spec.rb
|
317
320
|
- spec/interceptors/prometheus_spec.rb
|
318
321
|
- spec/interceptors/response_competition_spec.rb
|
@@ -369,7 +372,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
369
372
|
requirements:
|
370
373
|
- Ruby >= 2.0.0
|
371
374
|
rubyforge_project:
|
372
|
-
rubygems_version: 2.6.
|
375
|
+
rubygems_version: 2.6.12
|
373
376
|
signing_key:
|
374
377
|
specification_version: 4
|
375
378
|
summary: LocalHttpClient
|
@@ -450,6 +453,7 @@ test_files:
|
|
450
453
|
- spec/interceptors/default_timeout/main_spec.rb
|
451
454
|
- spec/interceptors/define_spec.rb
|
452
455
|
- spec/interceptors/dup_spec.rb
|
456
|
+
- spec/interceptors/logging/main_spec.rb
|
453
457
|
- spec/interceptors/monitoring/main_spec.rb
|
454
458
|
- spec/interceptors/prometheus_spec.rb
|
455
459
|
- spec/interceptors/response_competition_spec.rb
|