determinator 2.4.0 → 2.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63baaf3ee379eef31694ec105e48407970d0e53e6906af8e9a1746cfac5ca5e4
4
- data.tar.gz: 88b70dc55dedc32c98dc1eb3619fd420471127c812a7cdda7086c13349d3bdca
3
+ metadata.gz: 02425b2fa13369e05f3f9013a7b42c24f50b4a0b21e96368dd28624b7172486d
4
+ data.tar.gz: b1076e122637aa6f0cdf02d06b0ecc61d5783cd383ae39312c514b0826f23391
5
5
  SHA512:
6
- metadata.gz: 1ea1835cd7e0953c5d6747bbcbddfc43804cd33ffc3ed136c72ede003c2a24c9357c7746081370404b9851788a0b64b9d45a633657365524ed77cf6a5a69bf67
7
- data.tar.gz: 2db13fd8793c724554c2ba4766e3e769eb5d9e4042481b153a205337c5b0cfaad1bd6a691b552ee9a25109f9b8bb7b6dc6837570e909bf5d60fab1f4fe056e86
6
+ metadata.gz: 737f32c5b7d5d1fa849d6433d90e8abaf9bef29b9774fcc174835dcd2f265d7668c6d53c9a2ac90f20cc166c95affba58cd95cc8df591d32e07321ca624e509e
7
+ data.tar.gz: 5f285ca73316e74fb13649bcef594e39f94a68579b38417a1be55f7aaa4e5e0770e8a2ed243b1e306d88f4d3b5a4f40e425af294f4c4bc3c8938af8917b9f668
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # 2.4.2
2
+
3
+ Feature:
4
+ - Add endpoint information to tracking request
5
+
6
+ Bug fix:
7
+ - Make tracking request "start" attribute an actual time
8
+
9
+ # 2.4.1
10
+
11
+ Bug fix:
12
+ - Update "fake" retrievers to match behaviour introduced in `v2.3.1` when a feature is missing
13
+
1
14
  # 2.4.0
2
15
 
3
16
  Feature:
data/README.md CHANGED
@@ -289,12 +289,17 @@ end
289
289
  require 'determinator/tracking'
290
290
 
291
291
  Determinator::Tracking.on_request do |r|
292
- Rails.logger.info("tag=determinator_request type=#{r.type} request_time=#{r.time} error=#{r.error?} response_status=#{r.attributes[:status]} sidekiq_queue=#{r.attributes[:queue]}")
292
+ Rails.logger.info("tag=determinator_request endpoint=#{r.endpoint} type=#{r.type} request_time=#{r.time} error=#{r.error?} response_status=#{r.attributes[:status]} sidekiq_queue=#{r.attributes[:queue]}")
293
293
  r.determinations.each do |d|
294
294
  Rails.logger.info("tag=determination id=#{d.id} guid=#{d.guid} flag=#{d.feature_id} result=#{d.determination}")
295
295
  end
296
296
  end
297
297
 
298
+ # The library sets the "endpoint" with information about the request or sidekiq job. If you
299
+ # have environment variables that further identify the service, e.g. ENV['APP_NAME'],
300
+ # you can configure the tracker to prepend it to the endpoint:
301
+ Determinator::Tracking.endpoint_env_vars = ['APP_NAME']
302
+
298
303
  # If using an APM, you can provide trace information on the request by providing a get_context hook: e.g.
299
304
 
300
305
  Determinator::Tracking.get_context do
@@ -310,9 +315,7 @@ Determinator::Tracking.get_context do
310
315
  end
311
316
  ```
312
317
 
313
- NOTE: this is implemented by keeping the list of requests in a per-request thread-local variable, which means that determinations will only be tracked on the main thread.
314
-
315
- If your application is spinning out worker threads, you should make the determinations in the main thread if possible; or collect them from your worker threads and track them in the main thread with
318
+ NOTE: determinations will only be recorded on the threads where Determinator::Tracking is initialised via the middleware. If offloading work away from these thread (for example, by spinning up new threads within a Rack request or a Sidekiq worker), make the determinations before, and pass them through to the new threads; or, if it's not possible, collect them manually and track them in the request's thread with
316
319
  ```
317
320
  Determinator::Tracking.track(id, guid, feature, determination)
318
321
  ```
@@ -10,7 +10,7 @@ module Determinator
10
10
 
11
11
  # @param name [string,symbol] The name of the feature to retrieve
12
12
  def retrieve(name)
13
- @features[name.to_s]
13
+ @features.fetch(name.to_s, MissingResponse.new)
14
14
  end
15
15
 
16
16
  # @param feature [Determinator::Feature] The feature to store
@@ -10,6 +10,7 @@ module Determinator
10
10
  # The Control class will assume a nil return from this method
11
11
  # means the feature doesn't exist, so in turn will return `false`.
12
12
  def retrieve(_)
13
+ MissingResponse.new
13
14
  end
14
15
  end
15
16
  end
@@ -4,6 +4,8 @@ require 'determinator/tracking/context'
4
4
  module Determinator
5
5
  module Tracking
6
6
  class << self
7
+ attr_reader :endpoint_env_vars
8
+
7
9
  def instance
8
10
  Thread.current[:determinator_tracker]
9
11
  end
@@ -12,9 +14,9 @@ module Determinator
12
14
  Thread.current[:determinator_tracker] = Tracker.new(type)
13
15
  end
14
16
 
15
- def finish!(error:, **attributes)
17
+ def finish!(endpoint:, error:, **attributes)
16
18
  return false unless started?
17
- request = instance.finish!(error: error, **attributes)
19
+ request = instance.finish!(endpoint: endpoint, error: error, **attributes)
18
20
  clear!
19
21
  report(request)
20
22
  request
@@ -57,6 +59,16 @@ module Determinator
57
59
  @on_request = nil
58
60
  @get_context = nil
59
61
  end
62
+
63
+ def endpoint_env_vars=(vars)
64
+ @endpoint_env_vars = Array(vars)
65
+ end
66
+
67
+ def collect_endpoint_info(parts)
68
+ endpoint = Array(Determinator::Tracking.endpoint_env_vars).map{ |v| ENV[v] }
69
+ endpoint += Array(parts)
70
+ endpoint.reject{ |p| p.nil? || p == ''}.join(' ')
71
+ end
60
72
  end
61
73
  end
62
74
  end
@@ -16,7 +16,24 @@ module Determinator
16
16
  error = true
17
17
  raise
18
18
  ensure
19
- Determinator::Tracking.finish!(status: status, error: !!error)
19
+ Determinator::Tracking.finish!(
20
+ status: status,
21
+ error: !!error,
22
+ endpoint: extract_endpoint(env)
23
+ )
24
+ end
25
+
26
+ private
27
+
28
+ def extract_endpoint(env)
29
+ parts = if params = env['action_dispatch.request.path_parameters']
30
+ [[params[:controller], params[:action]].join('#')]
31
+ else
32
+ [env['REQUEST_METHOD'], env['PATH_INFO'] || env['REQUEST_URI']]
33
+ end
34
+ Determinator::Tracking.collect_endpoint_info(parts)
35
+ rescue
36
+ env['PATH_INFO']
20
37
  end
21
38
  end
22
39
  end
@@ -1,14 +1,16 @@
1
1
  module Determinator
2
2
  module Tracking
3
3
  class Request
4
- attr_reader :type, :time, :error, :attributes, :determinations, :context
4
+ attr_reader :start, :type, :endpoint, :time, :error, :attributes, :determinations, :context
5
5
 
6
- def initialize(type:, time:, error:, attributes:, determinations:, context: nil)
6
+ def initialize(start:, type:, endpoint:, time:, error:, attributes:, determinations:, context: nil)
7
+ @start = start
7
8
  @type = type
8
9
  @time = time
9
10
  @error = error
10
11
  @attributes = attributes
11
12
  @determinations = determinations
13
+ @endpoint = endpoint
12
14
  @context = context
13
15
  end
14
16
 
@@ -18,7 +18,11 @@ module Determinator
18
18
  error = true
19
19
  raise
20
20
  ensure
21
- Determinator::Tracking.finish!(queue: queue, error: !!error)
21
+ Determinator::Tracking.finish!(
22
+ endpoint: Determinator::Tracking.collect_endpoint_info(worker.class.name),
23
+ queue: queue,
24
+ error: !!error
25
+ )
22
26
  end
23
27
  end
24
28
  end
@@ -9,7 +9,8 @@ module Determinator
9
9
  def initialize(type)
10
10
  @determinations = []
11
11
  @type = type
12
- @start = now
12
+ @monotonic_start = now
13
+ @start = Time.now
13
14
  end
14
15
 
15
16
  def track(id, guid, feature, determination)
@@ -21,11 +22,13 @@ module Determinator
21
22
  )
22
23
  end
23
24
 
24
- def finish!(error:, **attributes)
25
- request_time = now - @start
25
+ def finish!(endpoint:, error:, **attributes)
26
+ request_time = now - @monotonic_start
26
27
  Determinator::Tracking::Request.new(
28
+ start: @start,
27
29
  type: type,
28
30
  time: request_time,
31
+ endpoint: endpoint,
29
32
  error: error,
30
33
  attributes: attributes,
31
34
  determinations: determinations,
@@ -1,3 +1,3 @@
1
1
  module Determinator
2
- VERSION = '2.4.0'
2
+ VERSION = '2.4.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: determinator
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Hastings-Spital
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-05 00:00:00.000000000 Z
11
+ date: 2020-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday