chimera_http_client 1.1.2 → 1.2.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: c0909ba0cb053a18ffbbe0c81e866f61692b7eadb86cf790e97e5ab8178dbb69
4
- data.tar.gz: 2583f9ea44ef1d2868cb8b421e680795cb474bccc4ef3e0a006c3c02135d3f17
3
+ metadata.gz: 5a1e1ddc7ca2263c940a81d57b6fbd4a94cb013ba040cf47a10e9428b4ad2fee
4
+ data.tar.gz: 2314f9fac4ec7b9514d19fe50d96051f47e9a9fce4cc588c3c2f5381bf53b8d2
5
5
  SHA512:
6
- metadata.gz: b193b7ed042727cc5a9c8b937cd7542b743a0f6530f47be8e842484be19cfc2edd9c9756564d3eb683d3875a65c84aefb482abb9df6d54a8c4d634c106337227
7
- data.tar.gz: ad18499c13ad4bc2ca9a02a1ae52f99ca559c2dff880e19553968d06e2bd7da5ab65b258f07d58767759e08974438c050fd7f4c17b17bdc1e89a71f47208b484
6
+ metadata.gz: 3074c920d64e9b4ce923590c320e1db14ede59d63527bbf29070b8625edfc3738a9354fa00ca21dcf61635882f97d6a755be10fa0c0776e567c13264a5f7358c
7
+ data.tar.gz: 2530bee55981a60ce9beaf1959b8af1b7ca333f1d16655de7782bd994bf75d6aff094beced3a8ebe31ea8dc3c2109e1bc9159058bf45932cb006e305925f8567
data/README.markdown CHANGED
@@ -83,12 +83,13 @@ Setting the `base_url` is meant to be a comfort feature, as you can then pass sh
83
83
 
84
84
  The optional parameters are:
85
85
 
86
+ * `cache` - an instance of your cache solution, can be overwritten in any request
87
+ * `deserializers` - custom methods to deserialize the response body, below more details
86
88
  * `logger` - an instance of a logger class that implements `#info` and `#warn` methods
89
+ * `monitor` - to collect metrics about requests, the basis for your instrumentation needs
87
90
  * `timeout` - the timeout for all requests, can be overwritten in any request, the default are 3 seconds
88
91
  * `user_agent` - if you would like your calls to identify with a specific user agent
89
92
  * `verbose` - the default is `false`, set it to true while debugging issues
90
- * `cache` - an instance of your cache solution, can be overwritten in any request
91
- * `deserializers` - custom methods to deserialize the response body, below more details
92
93
 
93
94
  ##### Custom deserializers
94
95
 
@@ -102,6 +103,23 @@ A Deserializer has to be an object on which the method `call` with the parameter
102
103
 
103
104
  where `body` is the response body (in the default case a JSON object). The class `Deserializer` contains the default objects that are used. They might help you creating your own. Don't forget to make requests with another header than the default `"Content-Type" => "application/json"`, when the API you connect to does not support JSON.
104
105
 
106
+ ##### Monitoring, metrics, instrumentation
107
+
108
+ Pass an object as `:monitor` to a connection that defines the method `call` and accepts a hash as parameter.
109
+
110
+ monitor.call({...})
111
+
112
+ It will receive information about every request as soon as it finished. What you do with this information is up for you to implement.
113
+
114
+ | Field | Description |
115
+ |:---------------|:----------------------------------------------------------------------|
116
+ | `url` | URL of the endpoint that was called |
117
+ | `method` | HTTP method: get, post, ... |
118
+ | `status` | HTTP status code: 200, ... |
119
+ | `runtime` | the time in seconds it took the request to finish |
120
+ | `completed_at` | Time.now.utc.iso8601(3) |
121
+ | `context` | Whatever you pass as `monitoring_context` to the options of a request |
122
+
105
123
  ### Request methods
106
124
 
107
125
  The available methods are:
@@ -142,6 +160,7 @@ All request methods expect a mandatory `endpoint` and an optional hash as parame
142
160
  * `password` - used for a BasicAuth login
143
161
  * `timeout` - set a custom timeout per request (the default is 3 seconds)
144
162
  * `cache` - optionally overwrite the cache store set in `Connection` in any request
163
+ * `monitoring_context` - pass additional information you want to collect with your instrumentation `monitor`
145
164
 
146
165
  Example:
147
166
 
data/TODO.markdown CHANGED
@@ -14,8 +14,9 @@ _none known_
14
14
  * [x] ~~include the total_time of the requests in the log~~
15
15
  * [x] ~~add (example) to README~~
16
16
  * [ ] add logger.warn / .error for error cases (?)
17
+ * [ ] streamline log message
17
18
 
18
- ### Custom De-serializer
19
+ ### ~~Custom De-serializer~~
19
20
 
20
21
  * [x] ~~allow to pass custom deserializer~~
21
22
  * [x] ~~use custom deserializer in #parsed_body instead of default JSON parsing~~
@@ -40,15 +41,18 @@ _none known_
40
41
 
41
42
  - [ ] Determine by parameter if 3xx Redirects should be handled as an Error or not
42
43
  - [x] ~~Add a longer description to the gemspec file~~
44
+ - [ ] Refactor README to explain simple use case vs. all the powerful options?
43
45
 
44
- ### Instrumentation
46
+ ### ~~Instrumentation~~
45
47
 
46
- - [ ] allow to pass object to collect metrics for monitoring
47
- - [ ] request URL
48
- - [ ] request resonse code
49
- - [ ] request datetime
50
- - [ ] request runtime
51
- - [ ] add example to README
48
+ - [x] ~~allow to pass object to collect metrics for monitoring~~
49
+ - [x] ~~request URL~~
50
+ - [x] ~~request HTTP method~~
51
+ - [x] ~~request response code~~
52
+ - [x] ~~request datetime~~
53
+ - [x] ~~request runtime~~
54
+ - [x] ~~custom context information per request~~
55
+ - [x] ~~add example to README~~
52
56
 
53
57
  ### Enable more Typhoeus functionality
54
58
 
@@ -93,7 +97,7 @@ _none known_
93
97
  * [x] ~~allow to set custom timeout per call~~
94
98
  * [x] ~~add (example) to README~~
95
99
 
96
- ### Release
100
+ ### ~~Release~~
97
101
 
98
102
  * [x] ~~rename module to have unique namespace~~
99
103
  * [x] ~~release to rubygems to add to the plethora of similar gems~~
@@ -8,6 +8,7 @@ module ChimeraHttpClient
8
8
  @base_url = options.fetch(:base_url)
9
9
  @deserializer = default_deserializer.merge(options.fetch(:deserializer, {}))
10
10
  @logger = options[:logger]
11
+ @monitor = options[:monitor]
11
12
  @timeout = options[:timeout]
12
13
 
13
14
  Typhoeus::Config.cache = options[:cache]
@@ -12,8 +12,9 @@ module ChimeraHttpClient
12
12
 
13
13
  def request
14
14
  options = {
15
- logger: @logger,
16
15
  deserializer: @deserializer,
16
+ logger: @logger,
17
+ monitor: @monitor,
17
18
  }
18
19
 
19
20
  @request ||= Request.new(options)
@@ -38,12 +38,13 @@ module ChimeraHttpClient
38
38
  private
39
39
 
40
40
  def create_request(method:, url:, body:, headers:, options:)
41
- class_options = {
42
- logger: @logger,
41
+ instance_options = {
43
42
  deserializer: @deserializer,
43
+ logger: @logger,
44
+ monitor: @monitor,
44
45
  }
45
46
 
46
- Request.new(class_options).create(
47
+ Request.new(instance_options).create(
47
48
  method: method,
48
49
  url: url,
49
50
  body: body,
@@ -5,7 +5,6 @@ module ChimeraHttpClient
5
5
  attr_reader :request, :result
6
6
 
7
7
  def initialize(options = {})
8
- @logger = options[:logger]
9
8
  @options = options
10
9
  end
11
10
 
@@ -37,13 +36,21 @@ module ChimeraHttpClient
37
36
 
38
37
  @result = nil
39
38
  @request.on_complete do |response|
40
- @logger&.info("Completed HTTP request: #{method.upcase} #{url} " \
41
- "in #{response.total_time&.round(3)}sec with status code #{response.code}")
39
+ runtime = response.total_time&.round(3)
40
+
41
+ @options[:monitor]&.call(
42
+ {
43
+ url: url, method: method, status: response.code, runtime: runtime,
44
+ completed_at: Time.now.utc.iso8601(3), context: options[:monitoring_context]
45
+ }
46
+ )
47
+ @options[:logger]&.info("Completed HTTP request: #{method.upcase} #{url} " \
48
+ "in #{runtime}sec with status code #{response.code}")
42
49
 
43
50
  @result = on_complete_handler(response)
44
51
  end
45
52
 
46
- @logger&.info("Starting HTTP request: #{method.upcase} #{url}")
53
+ @options[:logger]&.info("Starting HTTP request: #{method.upcase} #{url}")
47
54
 
48
55
  self
49
56
  end
@@ -1,3 +1,3 @@
1
1
  module ChimeraHttpClient
2
- VERSION = "1.1.2".freeze
2
+ VERSION = "1.2.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chimera_http_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Finger