lhc-core-interceptors 2.4.0 → 3.0.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 +2 -173
- data/lhc-core-interceptors.gemspec +3 -3
- data/lib/lhc-core-interceptors/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16bce23e32361c1e5c4a8363136c80654bf8aa8b
|
4
|
+
data.tar.gz: 6b3844d8f2aae9522f760007f83ce93221f75118
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccfc9da67e8473de4975c071552c293894c3d9722d10c1623710eb8926c7e111754ff2050dfd5cbc5b874f247752580e87d104208034496b4087ef133ae5d228
|
7
|
+
data.tar.gz: fac37b477195608abc57dfe6609abfcfcebfd4a2132400a72adee3aec735de6c6ca7afcf8fd941e3943fbc5d76009aaa56324e9e7928fdfd54dca67b41fdb803
|
data/README.md
CHANGED
@@ -1,173 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
The following set of interceptors can be used with [LHC](https://github.com/local-ch/lhc).
|
5
|
-
|
6
|
-
## Cache Interceptor
|
7
|
-
|
8
|
-
Add the cache interceptor to your basic set of LHC interceptors.
|
9
|
-
|
10
|
-
```ruby
|
11
|
-
LHC.config.interceptors = [LHC::Caching]
|
12
|
-
```
|
13
|
-
|
14
|
-
You can configure your own cache (default Rails.cache) and logger (default Rails.logger):
|
15
|
-
|
16
|
-
```ruby
|
17
|
-
LHC::Caching.cache = ActiveSupport::Cache::MemoryStore.new
|
18
|
-
LHC::Caching.logger = Logger.new(STDOUT)
|
19
|
-
```
|
20
|
-
|
21
|
-
|
22
|
-
Caching is not enabled by default, although you added it to your basic set of interceptors.
|
23
|
-
If you want to have requests served/stored and stored in/from cache, you have to enable it by request.
|
24
|
-
|
25
|
-
```ruby
|
26
|
-
LHC.get('http://local.ch', cache: true)
|
27
|
-
```
|
28
|
-
|
29
|
-
You can also enable caching when configuring an endpoint in LHS.
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
class Feedbacks < LHS::Service
|
33
|
-
endpoint ':datastore/v2/feedbacks', cache: true
|
34
|
-
end
|
35
|
-
```
|
36
|
-
|
37
|
-
### Cache Interceptor Options
|
38
|
-
|
39
|
-
```ruby
|
40
|
-
LHC.get('http://local.ch', cache: true, cache_expires_in: 1.day, cache_race_condition_ttl: 15.seconds)
|
41
|
-
```
|
42
|
-
|
43
|
-
`cache_expires_in` lets the cache expires every X seconds.
|
44
|
-
|
45
|
-
Set the key that is used for caching by using the `cache_key` option. Every key is prefixed with `LHC_CACHE: `.
|
46
|
-
|
47
|
-
Setting `cache_race_condition_ttl` is very useful in situations where a cache entry is used very frequently and is under heavy load.
|
48
|
-
If a cache expires and due to heavy load several different processes will try to read data natively and then they all will try to write to cache.
|
49
|
-
To avoid that case the first process to find an expired cache entry will bump the cache expiration time by the value set in `cache_race_condition_ttl`.
|
50
|
-
|
51
|
-
### Testing
|
52
|
-
|
53
|
-
Add to your spec_helper.rb:
|
54
|
-
|
55
|
-
```ruby
|
56
|
-
require 'lhc-core-interceptors/test/cache_helper.rb'
|
57
|
-
```
|
58
|
-
|
59
|
-
This will initialize a MemoryStore cache for LHC::Caching interceptor and resets the cache before every test.
|
60
|
-
|
61
|
-
## Monitoring Interceptor
|
62
|
-
|
63
|
-
Add the monitoring interceptor to your basic set of LHC interceptors.
|
64
|
-
|
65
|
-
```ruby
|
66
|
-
LHC.config.interceptors = [LHC::Monitoring]
|
67
|
-
```
|
68
|
-
|
69
|
-
You also have to configure statsd in order to have the monitoring interceptor report.
|
70
|
-
|
71
|
-
```ruby
|
72
|
-
LHC::Monitoring.statsd = <your-instance-of-statsd>
|
73
|
-
```
|
74
|
-
|
75
|
-
The monitoring interceptor reports all the HTTP communication done with LHS.
|
76
|
-
It reports the trial always.
|
77
|
-
|
78
|
-
In case of a successful response it reports the response code with a count and the response time with a gauge value.
|
79
|
-
|
80
|
-
```ruby
|
81
|
-
LHC.get('http://local.ch')
|
82
|
-
|
83
|
-
"lhc.<app_name>.<env>.<host>.<http_method>.count", 1
|
84
|
-
"lhc.<app_name>.<env>.<host>.<http_method>.200", 1
|
85
|
-
"lhc.<app_name>.<env>.<host>.<http_method>.time", 43
|
86
|
-
```
|
87
|
-
|
88
|
-
In case your workers/processes are getting killed due limited time constraints,
|
89
|
-
you are able to detect deltas with relying on "before_request", and "after_request" counts:
|
90
|
-
|
91
|
-
```ruby
|
92
|
-
"lhc.<app_name>.<env>.<host>.<http_method>.before_request", 1
|
93
|
-
"lhc.<app_name>.<env>.<host>.<http_method>.after_request", 1
|
94
|
-
```
|
95
|
-
|
96
|
-
Timeouts are also reported:
|
97
|
-
|
98
|
-
```ruby
|
99
|
-
"lhc.<app_name>.<env>.<host>.<http_method>.timeout", 1
|
100
|
-
```
|
101
|
-
|
102
|
-
All the dots in the host are getting replaced with underscore (_), because dot is the default separator in graphite.
|
103
|
-
|
104
|
-
It is also possible to set the key for Monitoring Interceptor on per request basis:
|
105
|
-
|
106
|
-
```ruby
|
107
|
-
LHC.get('http://local.ch', monitoring_key: 'local_website')
|
108
|
-
|
109
|
-
"local_website.count", 1
|
110
|
-
"local_website.200", 1
|
111
|
-
"local_website.time", 43
|
112
|
-
```
|
113
|
-
|
114
|
-
If you use this approach you need to add all namespaces (app, environment etc.) to the key on your own.
|
115
|
-
|
116
|
-
|
117
|
-
### Auth Interceptor
|
118
|
-
|
119
|
-
Add the auth interceptor to your basic set of LHC interceptors.
|
120
|
-
|
121
|
-
```ruby
|
122
|
-
LHC.config.interceptors = [LHC::Auth]
|
123
|
-
```
|
124
|
-
|
125
|
-
#### Bearer Authentication
|
126
|
-
|
127
|
-
```ruby
|
128
|
-
LHC.get('http://local.ch', auth: { bearer: -> { access_token } })
|
129
|
-
```
|
130
|
-
|
131
|
-
Adds the following header to the request:
|
132
|
-
```
|
133
|
-
'Authorization': 'Bearer 123456'
|
134
|
-
```
|
135
|
-
|
136
|
-
Assuming the method `access_token` responds on runtime of the request with `123456`.
|
137
|
-
|
138
|
-
#### Basic Authentication
|
139
|
-
|
140
|
-
```ruby
|
141
|
-
LHC.get('http://local.ch', auth: { basic: { username: 'steve', password: 'can' } })
|
142
|
-
```
|
143
|
-
|
144
|
-
Adds the following header to the request:
|
145
|
-
```
|
146
|
-
'Authorization': 'Basic c3RldmU6Y2Fu'
|
147
|
-
```
|
148
|
-
|
149
|
-
Which is the base64 encoded credentials "username:password".
|
150
|
-
|
151
|
-
## Rollbar Interceptor
|
152
|
-
|
153
|
-
Forward errors to rollbar when exceptions occur during http requests.
|
154
|
-
|
155
|
-
```ruby
|
156
|
-
LHC.config.interceptors = [LHC::Rollbar]
|
157
|
-
```
|
158
|
-
|
159
|
-
```ruby
|
160
|
-
LHC.get('http://local.ch')
|
161
|
-
```
|
162
|
-
|
163
|
-
If it raises, it forwards the request and response object to rollbar, which contain all necessary data.
|
164
|
-
|
165
|
-
### Forward additional parameters
|
166
|
-
|
167
|
-
```ruby
|
168
|
-
LHC.get('http://local.ch', rollbar: { tracking_key: 'this particular request' })
|
169
|
-
```
|
170
|
-
|
171
|
-
## License
|
172
|
-
|
173
|
-
[GNU Affero General Public License Version 3.](https://www.gnu.org/licenses/agpl-3.0.en.html)
|
1
|
+
# DEPRECATED
|
2
|
+
Merged into lhc: https://github.com/local-ch/lhc/blob/master/docs/interceptors.md
|
@@ -7,11 +7,11 @@ require "lhc-core-interceptors/version"
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "lhc-core-interceptors"
|
9
9
|
s.version = LHCCoreInterceptors::VERSION
|
10
|
-
s.authors = ['local
|
10
|
+
s.authors = ['https://github.com/local-ch/lhc-core-interceptors/graphs/contributors']
|
11
11
|
s.email = ['ws-operations@local.ch']
|
12
12
|
s.homepage = 'https://github.com/local-ch/lhc-core-interceptors'
|
13
|
-
s.summary = '
|
14
|
-
s.description = '
|
13
|
+
s.summary = '[DEPRECATED] Merged into lhc: https://github.com/local-ch/lhc/blob/master/docs/interceptors.md'
|
14
|
+
s.description = '[DEPRECATED] Merged into lhc: https://github.com/local-ch/lhc/blob/master/docs/interceptors.md'
|
15
15
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
17
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhc-core-interceptors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- local
|
7
|
+
- https://github.com/local-ch/lhc-core-interceptors/graphs/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -108,8 +108,7 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
description:
|
112
|
-
etc.)
|
111
|
+
description: "[DEPRECATED] Merged into lhc: https://github.com/local-ch/lhc/blob/master/docs/interceptors.md"
|
113
112
|
email:
|
114
113
|
- ws-operations@local.ch
|
115
114
|
executables: []
|
@@ -215,7 +214,7 @@ rubyforge_project:
|
|
215
214
|
rubygems_version: 2.6.8
|
216
215
|
signing_key:
|
217
216
|
specification_version: 4
|
218
|
-
summary:
|
217
|
+
summary: "[DEPRECATED] Merged into lhc: https://github.com/local-ch/lhc/blob/master/docs/interceptors.md"
|
219
218
|
test_files:
|
220
219
|
- spec/auth/basic_auth_spec.rb
|
221
220
|
- spec/auth/bearer_spec.rb
|