hoodoo 1.9.2 → 1.10.0

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODE5N2QwMWIyMWIxNDgxYTliZmUyODdjZThkZmFlOTFiYzEzYWEyMg==
4
+ YjU2MjRlMTgwYjU3ZDdhOTBhZjk4M2E5NGEwZjk5Mjg4MDM0YjMyMw==
5
5
  data.tar.gz: !binary |-
6
- OGVmODcxY2UxYzNiNTE0NmFlODhhYjhlZjFlZjhiZDA4OGY0MjNkYg==
6
+ YWFhZjNkZGJkNDMyZDI1NmE4NDk0NGQyMzAxNGFkMDZlMWU0NzRkMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NmZiODc1NjM5MDYxMzI4NWRmYjEyOTNmNGQyN2YxNmU5MGNlMmQ4NjEzMzZl
10
- Y2YzZjAzMjBjZWMxZDgwNTkzN2M1M2M5Y2Y3OWZlYTJhMGM3NTkwY2NmNzgx
11
- OGJmODhhOTQxZmJmNGFiMzUyOTI3NGExYmJiYTNhOTM2NGY3YTE=
9
+ ZDBiYjhmNDc5OTQ2ODAyNjI5NzU3YzY0YjE4MmQzYTRiMjRkY2NmYjdkZDJl
10
+ N2UxYThkMDhiMzBjMmQ4YWQ1YjcyMDhlMjM2ZDVjNjhiNGJhMTg4ZjgzZTg1
11
+ MDA0NWQ1OWZmMWM0MzhlNDkzZmNjODM4ZTdkOTUxMTQzYmFmNGY=
12
12
  data.tar.gz: !binary |-
13
- ODA0YmQ2ZmZjOTgwMGFkZGNhZWVkZTA3MzI5ZjVmZTE2ZTE2ZTVlYWQ1NDJi
14
- MGU0MWJhZmU4MmVkMWFmMzMwOWFhNTQwNDRlMjEwYjQ0YTIzOTBhNjgwODIz
15
- YWNiODZkN2FhMjc1MjRjYmM1MmNmMDhhMGNjNGVjMTI0NDFkYzg=
13
+ Y2UyY2ZhMDM1YTRlOTg5ODlmNzYwZDMyNGQyMTRiNjY1NmY3ZDdhYjAwN2Y1
14
+ NmQxNDQ0NmQ1ZDUxZDA4YzgzZGI1YjdkODY4YTViZjc4MWMwNzVlZmNhM2E4
15
+ MmY3MDlmZTFhZTBhZTAxYWVkODQ4NWFmYTJkOGQwOWMzNDIzMTE=
@@ -27,8 +27,8 @@ module Hoodoo; module Services
27
27
  # AMQP-based queue.
28
28
  #
29
29
  # +routing_key+:: The routing key (as a String) to use. Optional. If
30
- # omitted, reads +ENV[ 'AMQ_LOGGING_ENDPOINT' ]+ or if
31
- # that is unset, defaults to +platform.logging+.
30
+ # omitted, reads <tt>ENV['AMQ_LOGGING_ENDPOINT']</tt> or
31
+ # if that is unset, defaults to +platform.logging+.
32
32
  #
33
33
  # If you're running with Rack on top of Alchemy, then the +call+ method's
34
34
  # +env+ parameter containing the Rack environment _MUST_ have a key of
@@ -37,9 +37,21 @@ module Hoodoo; module Services
37
37
  # parameter. The logger will then use this active Alchemy service to send
38
38
  # messages to its configured routing key.
39
39
  #
40
+ # If <tt>ENV['AMQ_ANALYTICS_LOGGING_ENDPOINT']</tt> is defined then its
41
+ # value is used for a routing key in the case, very specifically, of a
42
+ # message logged with a +code+ of +analytics+. If the variable is not set,
43
+ # the same routing key is used for all messages regardless of code; else
44
+ # that particular code can be streamed off to another Rabbit queue via the
45
+ # given alternative routing key.
46
+ #
40
47
  def initialize( alchemy, routing_key = nil )
41
- @alchemy = alchemy
42
- @routing_key = routing_key || ENV[ 'AMQ_LOGGING_ENDPOINT' ] || 'platform.logging'
48
+ routing_key = routing_key || ENV[ 'AMQ_LOGGING_ENDPOINT' ] || 'platform.logging'
49
+ analytics_routing_key = ENV[ 'AMQ_ANALYTICS_LOGGING_ENDPOINT' ]
50
+
51
+ @alchemy = alchemy
52
+ @routing_keys = Hash.new( routing_key ) # Use "routing_key" as a default value
53
+
54
+ @routing_keys[ :analytics ] = analytics_routing_key || routing_key
43
55
  end
44
56
 
45
57
  # Custom implementation of the Hoodoo::Logger::WriterMixin#report
@@ -83,7 +95,10 @@ module Hoodoo; module Services
83
95
  :identity => ( session[ 'identity' ] || {} ).to_h
84
96
  }.to_json()
85
97
 
86
- @alchemy.send_message_to_service( @routing_key, { "body" => message } )
98
+ @alchemy.send_message_to_service(
99
+ @routing_keys[ code.to_sym ],
100
+ { "body" => message }
101
+ )
87
102
  end
88
103
  end
89
104
 
@@ -12,6 +12,6 @@ module Hoodoo
12
12
  # The Hoodoo gem version. If this changes, ensure that the date in
13
13
  # "hoodoo.gemspec" is correct and run "bundle install" (or "update").
14
14
  #
15
- VERSION = '1.9.2'
15
+ VERSION = '1.10.0'
16
16
 
17
17
  end
@@ -53,16 +53,16 @@ describe Hoodoo::Services::Middleware::AMQPLogWriter do
53
53
 
54
54
  @session.caller_identity_name = @identity_id_4
55
55
 
56
- @alchemy = OpenStruct.new
57
- @queue = 'foo.bar'
58
- @logger = described_class.new( @alchemy, @queue )
56
+ @alchemy = OpenStruct.new
57
+ @default_routing_key = 'foo.bar'
58
+ @custom_routing_key = 'baz.foo'
59
+ @logger = described_class.new( @alchemy, @default_routing_key )
59
60
  end
60
61
 
61
- it 'sends expected data' do
62
+ def test_with_code( code, expected_routing_key )
62
63
  Timecop.freeze do
63
64
  level = 'warn'
64
65
  component = 'test_component'
65
- code = 'test_code'
66
66
  reported_at = Time.now.iso8601( 12 )
67
67
  id = Hoodoo::UUID.generate
68
68
  interaction_id = Hoodoo::UUID.generate
@@ -92,9 +92,51 @@ describe Hoodoo::Services::Middleware::AMQPLogWriter do
92
92
  :identity => Hoodoo::Utilities.stringify( @session.identity.to_h )
93
93
  }
94
94
 
95
- expect( @alchemy ).to receive( :send_message_to_service ).with( @queue, { "body" => expected_hash.to_json } ).once
95
+ expect( @alchemy ).to receive( :send_message_to_service ).with(
96
+ expected_routing_key,
97
+ { "body" => expected_hash.to_json }
98
+ ).once
96
99
 
97
100
  @logger.report( level, component, code, data )
98
101
  end
99
102
  end
103
+
104
+ it 'sends expected data' do
105
+ test_with_code( 'test_code', @default_routing_key )
106
+ end
107
+
108
+ context 'sends analytics data' do
109
+ context 'to default queue' do
110
+ it 'with no routing override (by String)' do
111
+ test_with_code( 'analytics', @default_routing_key )
112
+ end
113
+
114
+ it 'with no routing override (by Symbol)' do
115
+ test_with_code( :analytics, @default_routing_key )
116
+ end
117
+ end
118
+
119
+ context 'to custom queue' do
120
+ before :each do
121
+ ENV[ 'AMQ_ANALYTICS_LOGGING_ENDPOINT' ] = @custom_routing_key
122
+
123
+ # Recreate the logger instance from the outermost 'before each'
124
+ # block in order to re-run the initialiser and re-check ENV.
125
+ #
126
+ @logger = described_class.new( @alchemy, @default_routing_key )
127
+ end
128
+
129
+ after :each do
130
+ ENV.delete( 'AMQ_ANALYTICS_LOGGING_ENDPOINT' )
131
+ end
132
+
133
+ it 'with routing override (by String)' do
134
+ test_with_code( 'analytics', @custom_routing_key )
135
+ end
136
+
137
+ it 'with routing override (by Symbol)' do
138
+ test_with_code( :analytics, @custom_routing_key )
139
+ end
140
+ end
141
+ end
100
142
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoodoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.2
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loyalty New Zealand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-29 00:00:00.000000000 Z
11
+ date: 2016-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kgio