umbra-rb 0.1.3.pre → 0.1.4.pre

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: f02fb8bd32e28add55e66431d5d04b94586e66245c31a75a6e6d391781680d11
4
- data.tar.gz: 65b2eeed6b27b8e72966102e534e7d29cb46bc639acacff46f63b79e7a112564
3
+ metadata.gz: 679e800927f9e68d4db11021a503382982a875ffe2603225733e41fcbecea043
4
+ data.tar.gz: 917c3503760f10e01849b3c57b6d9e61410f2b1d523407b128f96387fdcf212a
5
5
  SHA512:
6
- metadata.gz: 592160621a75b39df6055bce8e7356167df48ab6eedcbf65432f17e1b42622ac2ed7dfeacb36d252d78398789406630c55af3bb741d0152562d8e39e24ff45f2
7
- data.tar.gz: 7fc6eec4562a0cd1174cd7b60f4dc820b4dd350ea02ac5866cb2b2341af5fd47704ccfcfba10cd443f2d802211244efb57ffb19a046ec2bbdbf1aa7f4cd4e686
6
+ metadata.gz: 705b476de7c8caf4fc74b20b5bcd4852f6794785ed07f0778aabcd846cbf520aac6060c7e715bc79e59f02468da828f371344393aa0f45ba5dbc208180eba666
7
+ data.tar.gz: 0c06e66a03e07d85f73f1b66de8b31efa8fcd18c81f267279140e970ada23f0455df5d789719775242699c5f4bd53b544d7aea7e356c7ed66f1cde4c86cf5ac8
data/.circleci/config.yml CHANGED
@@ -1,6 +1,9 @@
1
1
  ruby: &ruby
2
2
  image: carwow/ruby-ci:2.6
3
3
 
4
+ redis: &redis
5
+ image: redis
6
+
4
7
  version: 2
5
8
 
6
9
  jobs:
@@ -37,6 +40,7 @@ jobs:
37
40
  working_directory: ~/umbra
38
41
  docker:
39
42
  - *ruby
43
+ - *redis
40
44
  steps:
41
45
  - attach_workspace:
42
46
  at: '~'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- umbra-rb (0.1.3.pre)
4
+ umbra-rb (0.1.4.pre)
5
5
  multi_json (~> 1.13)
6
6
  oj (~> 3.9)
7
7
  redis (~> 4.1)
data/README.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # umbra :waning_crescent_moon:
2
- ### A shadow requesting tool for rack-based apps
3
2
 
4
- `umbra` is a rack middleware that allows you to create shadow requests via a redis pub/sub channel.
3
+ > **umbra** /ˈʌmbrə/
4
+ >
5
+ > noun
6
+ > 1. the fully shaded inner region of a shadow cast by an opaque object, especially the area on the earth or moon experiencing the total phase of an eclipse.
7
+ > 2. shadow or darkness.
8
+ > "an impenetrable umbra seemed to fill every inch of the museum"
5
9
 
6
- This can help you to build confidence in your infrasture by simulating elevated traffic in a controlled manner. Thereby allowing you to observe and monitor the limits of your systems.
10
+ `umbra` is a rack middleware that allows you to create shadow requests via a redis pub/sub channel.
7
11
 
8
12
  # Installation
9
13
 
data/lib/umbra/encoder.rb CHANGED
@@ -11,32 +11,37 @@ module Umbra
11
11
  @status, @headers, @body = response
12
12
  end
13
13
 
14
- def call
15
- MultiJson.dump(
16
- 'request' => {
17
- 'scheme' => @env.fetch('rack.url_scheme'),
18
- 'host' => @env['HTTP_HOST'] || @env.fetch('SERVER_NAME'),
19
- 'uri' => @env.fetch('REQUEST_URI'),
20
- 'port' => @env.fetch('SERVER_PORT'),
21
- 'method' => @env.fetch('REQUEST_METHOD'),
22
- 'query' => @env.fetch('QUERY_STRING'),
23
- 'script_name' => @env.fetch('SCRIPT_NAME'),
24
- 'path_info' => @env.fetch('PATH_INFO'),
25
- 'headers' => request_headers,
26
- 'body' => request_body
27
- },
28
- 'response' => {
29
- 'status' => @status,
30
- 'headers' => @headers,
31
- 'body' => body_string
14
+ def to_h
15
+ @to_h ||=
16
+ {
17
+ 'request' => {
18
+ 'scheme' => @env.fetch('rack.url_scheme'),
19
+ 'host' => @env['HTTP_HOST'] || @env.fetch('SERVER_NAME'),
20
+ 'uri' => @env.fetch('REQUEST_URI'),
21
+ 'port' => @env.fetch('SERVER_PORT'),
22
+ 'method' => @env.fetch('REQUEST_METHOD'),
23
+ 'query' => @env.fetch('QUERY_STRING'),
24
+ 'script_name' => @env.fetch('SCRIPT_NAME'),
25
+ 'path_info' => @env.fetch('PATH_INFO'),
26
+ 'headers' => request_headers,
27
+ 'body' => request_body
28
+ },
29
+ 'response' => {
30
+ 'status' => @status,
31
+ 'headers' => @headers,
32
+ 'body' => body_string
33
+ }
32
34
  }
33
- )
35
+ end
36
+
37
+ def call
38
+ @call ||= MultiJson.dump(to_h)
34
39
  end
35
40
 
36
41
  private
37
42
 
38
43
  def request_headers
39
- @env.select { |k, _| k.start_with?('HTTP_') }
44
+ @request_headers ||= @env.select { |k, _| k.start_with?('HTTP_') }
40
45
  end
41
46
 
42
47
  def request_body
@@ -44,11 +49,14 @@ module Umbra
44
49
  end
45
50
 
46
51
  def body_string
47
- str = []
52
+ @body_string ||=
53
+ begin
54
+ str = []
48
55
 
49
- @body.each { |x| str << x.to_s }
56
+ @body.each { |x| str << x.to_s }
50
57
 
51
- str.join('')
58
+ str.join('')
59
+ end
52
60
  end
53
61
  end
54
62
  end
@@ -16,6 +16,7 @@ module Umbra
16
16
 
17
17
  private
18
18
 
19
+ # rubocop:disable Metrics/MethodLength
19
20
  def start_once!
20
21
  LOCK.synchronize do
21
22
  return if @started == Process.pid
@@ -44,6 +45,7 @@ module Umbra
44
45
  end
45
46
  end
46
47
  end
48
+ # rubocop:enable Metrics/MethodLength
47
49
  end
48
50
 
49
51
  STOP = Object.new
@@ -2,6 +2,11 @@
2
2
 
3
3
  module Umbra
4
4
  class RequestBuilder
5
+ UMBRA_HEADERS = {
6
+ Umbra::HEADER_KEY => Umbra::HEADER_VALUE,
7
+ 'HTTP_CACHE_CONTROL' => 'no-cache, no-store, private, max-age=0'
8
+ }.freeze
9
+
5
10
  class << self
6
11
  def call(env)
7
12
  Typhoeus::Request.new(
@@ -17,7 +22,7 @@ module Umbra
17
22
  def headers(env)
18
23
  request(env)
19
24
  .fetch('headers')
20
- .merge(Umbra::HEADER_KEY => Umbra::HEADER_VALUE)
25
+ .merge(UMBRA_HEADERS)
21
26
  .transform_keys { |key| key.split('_').drop(1).map(&:capitalize).join('-') }
22
27
  end
23
28
 
@@ -24,6 +24,7 @@ module Umbra
24
24
 
25
25
  private
26
26
 
27
+ # rubocop:disable Metrics/MethodLength
27
28
  def start_worker!
28
29
  @lock.synchronize do
29
30
  return if @started
@@ -31,7 +32,7 @@ module Umbra
31
32
  @started = true
32
33
  Umbra.logger.info '[umbra] Starting shadowing threads...'
33
34
 
34
- workers = (1..@pool).map do |thread_num|
35
+ workers = (0...@pool).map do |thread_num|
35
36
  Thread.new do
36
37
  Umbra.logger.info "[umbra] shadow thread #{thread_num} waiting"
37
38
 
@@ -54,5 +55,6 @@ module Umbra
54
55
  end
55
56
  end
56
57
  end
58
+ # rubocop:enable Metrics/MethodLength
57
59
  end
58
60
  end
data/lib/umbra/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Umbra
4
- VERSION = '0.1.3.pre'
4
+ VERSION = '0.1.4.pre'
5
5
  end
data/lib/umbra.rb CHANGED
@@ -36,7 +36,7 @@ module Umbra
36
36
  return unless @config
37
37
  return unless @config.request_selector.call(env, response)
38
38
 
39
- env.merge!('umbra.request_body' => request_body(env))
39
+ env['umbra.request_body'] = request_body(env)
40
40
 
41
41
  @config.publisher.call(env, response)
42
42
  rescue StandardError => e
@@ -76,7 +76,7 @@ module Umbra
76
76
  redis.ping
77
77
  logger.info '[umbra] redis is alive!'
78
78
  rescue Redis::BaseError => e
79
- logger.warn "[umbra] redis while connecting to redis: #{e.message}"
79
+ logger.warn "[umbra] error while connecting to redis: #{e.message}"
80
80
  reset!
81
81
  rescue StandardError => e
82
82
  logger.warn "[umbra] redis is misconfigured: #{e.message}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: umbra-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3.pre
4
+ version: 0.1.4.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - carwow Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-25 00:00:00.000000000 Z
11
+ date: 2019-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler