hoodoo 1.9.2 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YjU2MjRlMTgwYjU3ZDdhOTBhZjk4M2E5NGEwZjk5Mjg4MDM0YjMyMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YWFhZjNkZGJkNDMyZDI1NmE4NDk0NGQyMzAxNGFkMDZlMWU0NzRkMw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDBiYjhmNDc5OTQ2ODAyNjI5NzU3YzY0YjE4MmQzYTRiMjRkY2NmYjdkZDJl
|
10
|
+
N2UxYThkMDhiMzBjMmQ4YWQ1YjcyMDhlMjM2ZDVjNjhiNGJhMTg4ZjgzZTg1
|
11
|
+
MDA0NWQ1OWZmMWM0MzhlNDkzZmNjODM4ZTdkOTUxMTQzYmFmNGY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
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
|
-
|
42
|
-
|
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(
|
98
|
+
@alchemy.send_message_to_service(
|
99
|
+
@routing_keys[ code.to_sym ],
|
100
|
+
{ "body" => message }
|
101
|
+
)
|
87
102
|
end
|
88
103
|
end
|
89
104
|
|
data/lib/hoodoo/version.rb
CHANGED
@@ -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
|
57
|
-
@
|
58
|
-
@
|
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
|
-
|
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(
|
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.
|
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-
|
11
|
+
date: 2016-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kgio
|