hoodoo 1.4.1 → 1.5.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 +8 -8
- data/lib/hoodoo/client/endpoint/endpoints/amqp.rb +1 -1
- data/lib/hoodoo/middleware.rb +0 -1
- data/lib/hoodoo/services/middleware/amqp_log_writer.rb +4 -4
- data/lib/hoodoo/version.rb +1 -1
- data/spec/services/middleware/amqp_log_writer_spec.rb +2 -3
- data/spec/services/middleware/middleware_exotic_communication_spec.rb +1 -1
- data/spec/services/middleware/middleware_logging_spec.rb +2 -2
- metadata +4 -7
- data/lib/hoodoo/services/middleware/amqp_log_message.rb +0 -124
- data/spec/services/middleware/amqp_log_message_spec.rb +0 -58
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
MDhkYWM2MjczODEyMTY0ZmUzM2JmNTE2NDNhNDI0ODVmMzRiNjk2Mg==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
N2U4NzAwMTg2YTMwZWFmYjcxMmEwMjM2MWUwOGUxZjJjNTVlOWY3NA==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
MWJlMThiNzJhMzQwMmJiNGUwMDJlNjc0ZTE5MTgyYTA5ZjU4MGQ4YzQ0Yzg2
|
|
10
|
+
M2VhODY0YTkwNmYxZDJjYjM5NzI3M2VlZTYwN2MxYjQ0ZGM3OTEzNjNiYjRl
|
|
11
|
+
MjE0YWQwOTIwZDJmMzUyMTVmODZlZDc1NWE5NjA5YTA3MDQxMDE=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
OWNkYTUyNmY1MGJhYzNlNWY5NmZhNWZiZjc3NjhjODYwODAzMDY5NjRjZmQz
|
|
14
|
+
OGE3OTQ1NTNmYmRjOTA4ZTRmZTgyODNlMGMyZDQ4ZjViYjBhOGYwZGM5ODZl
|
|
15
|
+
OGFlMjIzMTc4YzJmM2ZlNTFhODZjMTVkYzQ3YTViMzg1NmVjYWI=
|
|
@@ -164,7 +164,7 @@ module Hoodoo
|
|
|
164
164
|
http_message[ 'session_id' ] = self.session_id()
|
|
165
165
|
end
|
|
166
166
|
|
|
167
|
-
amqp_response = self.alchemy().
|
|
167
|
+
amqp_response = self.alchemy().send_request_to_resource( http_message )
|
|
168
168
|
|
|
169
169
|
description_of_response = DescriptionOfResponse.new
|
|
170
170
|
description_of_response.action = action
|
data/lib/hoodoo/middleware.rb
CHANGED
|
@@ -20,7 +20,6 @@ require 'hoodoo/presenters'
|
|
|
20
20
|
# Middleware
|
|
21
21
|
|
|
22
22
|
require 'hoodoo/services/middleware/rack_monkey_patch'
|
|
23
|
-
require 'hoodoo/services/middleware/amqp_log_message'
|
|
24
23
|
require 'hoodoo/services/middleware/amqp_log_writer'
|
|
25
24
|
require 'hoodoo/services/middleware/interaction'
|
|
26
25
|
require 'hoodoo/services/middleware/endpoints/inter_resource_remote'
|
|
@@ -70,13 +70,13 @@ module Hoodoo; module Services
|
|
|
70
70
|
data[ :id ] ||= Hoodoo::UUID.generate()
|
|
71
71
|
|
|
72
72
|
session = data[ :session ] || {}
|
|
73
|
-
message =
|
|
73
|
+
message = {
|
|
74
74
|
|
|
75
75
|
:id => data[ :id ],
|
|
76
76
|
:level => level,
|
|
77
77
|
:component => component,
|
|
78
78
|
:code => code,
|
|
79
|
-
:reported_at => Time.now,
|
|
79
|
+
:reported_at => Time.now.iso8601( 12 ),
|
|
80
80
|
|
|
81
81
|
:data => data,
|
|
82
82
|
|
|
@@ -84,9 +84,9 @@ module Hoodoo; module Services
|
|
|
84
84
|
:caller_id => session[ 'caller_id' ],
|
|
85
85
|
:identity => ( session[ 'identity' ] || {} ).to_h
|
|
86
86
|
|
|
87
|
-
}
|
|
87
|
+
}.to_json()
|
|
88
88
|
|
|
89
|
-
@alchemy.
|
|
89
|
+
@alchemy.send_message_to_service( @routing_key, { "body" => message } )
|
|
90
90
|
end
|
|
91
91
|
end
|
|
92
92
|
|
data/lib/hoodoo/version.rb
CHANGED
|
@@ -60,7 +60,7 @@ describe Hoodoo::Services::Middleware::AMQPLogWriter do
|
|
|
60
60
|
level = 'warn'
|
|
61
61
|
component = 'test_component'
|
|
62
62
|
code = 'test_code'
|
|
63
|
-
reported_at = Time.now
|
|
63
|
+
reported_at = Time.now.iso8601( 12 )
|
|
64
64
|
id = Hoodoo::UUID.generate
|
|
65
65
|
interaction_id = Hoodoo::UUID.generate
|
|
66
66
|
data = {
|
|
@@ -83,8 +83,7 @@ describe Hoodoo::Services::Middleware::AMQPLogWriter do
|
|
|
83
83
|
:identity => Hoodoo::Utilities.stringify( @session.identity.to_h )
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
expect(
|
|
87
|
-
expect( @alchemy ).to receive( :send_message_to_queue ).with( @queue, {} ).once
|
|
86
|
+
expect( @alchemy ).to receive( :send_message_to_service ).with( @queue, { "body" => expected_hash.to_json } ).once
|
|
88
87
|
|
|
89
88
|
@logger.report( level, component, code, data )
|
|
90
89
|
end
|
|
@@ -102,7 +102,7 @@ describe Hoodoo::Services::Middleware do
|
|
|
102
102
|
mock_query[ 'filter' ] = URI.encode_www_form( mock_query[ 'filter' ] ) if ( mock_query[ 'filter' ].is_a?( ::Hash ) )
|
|
103
103
|
end
|
|
104
104
|
|
|
105
|
-
expect( @mock_alchemy ).to receive( :
|
|
105
|
+
expect( @mock_alchemy ).to receive( :send_request_to_resource ).once do | message |
|
|
106
106
|
expect( message ).to eq( {
|
|
107
107
|
'scheme' => 'http',
|
|
108
108
|
'verb' => mock_method,
|
|
@@ -214,7 +214,7 @@ describe Hoodoo::Services::Middleware do
|
|
|
214
214
|
it 'has the expected "development" mode loggers' do
|
|
215
215
|
force_logging_to( 'development' )
|
|
216
216
|
|
|
217
|
-
expect_any_instance_of(FakeAlchemy).to receive(:
|
|
217
|
+
expect_any_instance_of(FakeAlchemy).to receive(:send_message_to_service).at_least(:once)
|
|
218
218
|
spec_helper_silence_stdout() do
|
|
219
219
|
get '/v1/test_log/hello', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
|
220
220
|
end
|
|
@@ -228,7 +228,7 @@ describe Hoodoo::Services::Middleware do
|
|
|
228
228
|
it 'has the expected "production" mode loggers' do
|
|
229
229
|
force_logging_to( 'production' )
|
|
230
230
|
|
|
231
|
-
expect_any_instance_of(FakeAlchemy).to receive(:
|
|
231
|
+
expect_any_instance_of(FakeAlchemy).to receive(:send_message_to_service).at_least(:once)
|
|
232
232
|
get '/v1/test_log/hello', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
|
233
233
|
|
|
234
234
|
instances = Hoodoo::Services::Middleware.logger.instances
|
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.5.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-02
|
|
11
|
+
date: 2016-03-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: kgio
|
|
@@ -100,14 +100,14 @@ dependencies:
|
|
|
100
100
|
requirements:
|
|
101
101
|
- - ~>
|
|
102
102
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: '0
|
|
103
|
+
version: '1.0'
|
|
104
104
|
type: :development
|
|
105
105
|
prerelease: false
|
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
107
|
requirements:
|
|
108
108
|
- - ~>
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
|
-
version: '0
|
|
110
|
+
version: '1.0'
|
|
111
111
|
- !ruby/object:Gem::Dependency
|
|
112
112
|
name: rspec
|
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -359,7 +359,6 @@ files:
|
|
|
359
359
|
- lib/hoodoo/services/discovery/results/for_http.rb
|
|
360
360
|
- lib/hoodoo/services/discovery/results/for_local.rb
|
|
361
361
|
- lib/hoodoo/services/discovery/results/for_remote.rb
|
|
362
|
-
- lib/hoodoo/services/middleware/amqp_log_message.rb
|
|
363
362
|
- lib/hoodoo/services/middleware/amqp_log_writer.rb
|
|
364
363
|
- lib/hoodoo/services/middleware/endpoints/inter_resource_local.rb
|
|
365
364
|
- lib/hoodoo/services/middleware/endpoints/inter_resource_remote.rb
|
|
@@ -456,7 +455,6 @@ files:
|
|
|
456
455
|
- spec/services/discovery/results/for_http_spec.rb
|
|
457
456
|
- spec/services/discovery/results/for_local_spec.rb
|
|
458
457
|
- spec/services/discovery/results/for_remote_spec.rb
|
|
459
|
-
- spec/services/middleware/amqp_log_message_spec.rb
|
|
460
458
|
- spec/services/middleware/amqp_log_writer_spec.rb
|
|
461
459
|
- spec/services/middleware/endpoints/inter_resource_local_spec.rb
|
|
462
460
|
- spec/services/middleware/endpoints/inter_resource_remote_spec.rb
|
|
@@ -585,7 +583,6 @@ test_files:
|
|
|
585
583
|
- spec/services/discovery/results/for_http_spec.rb
|
|
586
584
|
- spec/services/discovery/results/for_local_spec.rb
|
|
587
585
|
- spec/services/discovery/results/for_remote_spec.rb
|
|
588
|
-
- spec/services/middleware/amqp_log_message_spec.rb
|
|
589
586
|
- spec/services/middleware/amqp_log_writer_spec.rb
|
|
590
587
|
- spec/services/middleware/endpoints/inter_resource_local_spec.rb
|
|
591
588
|
- spec/services/middleware/endpoints/inter_resource_remote_spec.rb
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
########################################################################
|
|
2
|
-
# File:: amqp_log_message.rb
|
|
3
|
-
# (C):: Loyalty New Zealand 2014
|
|
4
|
-
#
|
|
5
|
-
# Purpose:: Structured logging onto an AMQP-based queue, via the
|
|
6
|
-
# Alchemy Flux gem. This class just exists to rationalise
|
|
7
|
-
# any parameters inbound in order to generate a clean
|
|
8
|
-
# representation for Flux.
|
|
9
|
-
#
|
|
10
|
-
# The middleware uses this to put log and error messages
|
|
11
|
-
# on the queue. Interested services use this to read such
|
|
12
|
-
# messages from the queue.
|
|
13
|
-
# ----------------------------------------------------------------------
|
|
14
|
-
# 20-Nov-2014 (ADH): Created.
|
|
15
|
-
########################################################################
|
|
16
|
-
|
|
17
|
-
module Hoodoo; module Services
|
|
18
|
-
class Middleware
|
|
19
|
-
|
|
20
|
-
# A representation of a log message placed on an AMQP-based queue.
|
|
21
|
-
# The primary expected communications interface is Alchemy Flux at
|
|
22
|
-
# the time of writing.
|
|
23
|
-
#
|
|
24
|
-
class AMQPLogMessage
|
|
25
|
-
|
|
26
|
-
# The Time +strftime+ formatter used for string conversions in this
|
|
27
|
-
# class.
|
|
28
|
-
#
|
|
29
|
-
TIME_FORMATTER = '%Y-%m-%d %H:%M:%S.%12N %Z'
|
|
30
|
-
|
|
31
|
-
# A UUID to assign to this log message. See Hoodoo::UUID::generate.
|
|
32
|
-
#
|
|
33
|
-
attr_accessor :id
|
|
34
|
-
|
|
35
|
-
# Logging level. See Hoodoo::Logger.
|
|
36
|
-
#
|
|
37
|
-
attr_accessor :level
|
|
38
|
-
|
|
39
|
-
# Logging component. See Hoodoo::Logger.
|
|
40
|
-
#
|
|
41
|
-
attr_accessor :component
|
|
42
|
-
|
|
43
|
-
# Component log code. See Hoodoo::Logger.
|
|
44
|
-
#
|
|
45
|
-
attr_accessor :code
|
|
46
|
-
|
|
47
|
-
# The time at which this log message is being reported to the Logger
|
|
48
|
-
# instance. This is a formatted *String* to high accuracy. See also
|
|
49
|
-
# #reported_at=.
|
|
50
|
-
#
|
|
51
|
-
attr_reader :reported_at
|
|
52
|
-
|
|
53
|
-
# Set the time read back by #reported_at using a Time instance. This
|
|
54
|
-
# is formatted internally as a String via TIME_FORMATTER and reported
|
|
55
|
-
# as such in subsequent calls to #reported_at.
|
|
56
|
-
#
|
|
57
|
-
# Conversion from Time to String is done here, rather than by the
|
|
58
|
-
# caller setting this instance's variables, so that we can internally
|
|
59
|
-
# enforce the accuracy required for this field.
|
|
60
|
-
#
|
|
61
|
-
# +time+:: The Time instance to set (and process into a string
|
|
62
|
-
# internally via TIME_FORMATTER), *or* a String instance
|
|
63
|
-
# already so formatted, *or* +nil+ to clear the value.
|
|
64
|
-
#
|
|
65
|
-
def reported_at=( time )
|
|
66
|
-
if time.is_a?( String )
|
|
67
|
-
@reported_at = time
|
|
68
|
-
elsif time.is_a?( Time )
|
|
69
|
-
@reported_at = time.strftime( TIME_FORMATTER )
|
|
70
|
-
else
|
|
71
|
-
@reported_at = nil
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# Log payload. See Hoodoo::Logger.
|
|
76
|
-
#
|
|
77
|
-
attr_accessor :data
|
|
78
|
-
|
|
79
|
-
# Optional calling Caller ID, via session data inside the payload - see
|
|
80
|
-
# Hoodoo::Logger.
|
|
81
|
-
#
|
|
82
|
-
attr_accessor :caller_id
|
|
83
|
-
|
|
84
|
-
# Optional interaction UUID, via session data inside the payload - see
|
|
85
|
-
# Hoodoo::Logger.
|
|
86
|
-
#
|
|
87
|
-
attr_accessor :interaction_id
|
|
88
|
-
|
|
89
|
-
# Optional hash of identity properties from the session data inside the
|
|
90
|
-
# payload - see Hoodoo::Logger.
|
|
91
|
-
#
|
|
92
|
-
attr_accessor :identity
|
|
93
|
-
|
|
94
|
-
# Create an instance with options keyed on the attributes defined for
|
|
95
|
-
# the class. Option keys may be Strings or Symbols but must only match
|
|
96
|
-
# defined attribute names.
|
|
97
|
-
#
|
|
98
|
-
def initialize( options = {} )
|
|
99
|
-
options.each do | name, value |
|
|
100
|
-
send( "#{ name }=", value )
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
# Retrieve a simple Hash representation of this instance.
|
|
105
|
-
#
|
|
106
|
-
def to_h
|
|
107
|
-
{
|
|
108
|
-
'id' => @id,
|
|
109
|
-
'level' => @level,
|
|
110
|
-
'component' => @component,
|
|
111
|
-
'code' => @code,
|
|
112
|
-
'reported_at' => @reported_at,
|
|
113
|
-
|
|
114
|
-
'data' => @data,
|
|
115
|
-
|
|
116
|
-
'interaction_id' => @interaction_id,
|
|
117
|
-
'caller_id' => @caller_id,
|
|
118
|
-
'identity' => Hoodoo::Utilities.stringify( @identity )
|
|
119
|
-
}
|
|
120
|
-
end
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
end
|
|
124
|
-
end; end
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
require 'spec_helper.rb'
|
|
2
|
-
|
|
3
|
-
describe Hoodoo::Services::Middleware::AMQPLogMessage do
|
|
4
|
-
|
|
5
|
-
let( :now ) { Time.now }
|
|
6
|
-
let( :base_hash ) {
|
|
7
|
-
{
|
|
8
|
-
:id => '1',
|
|
9
|
-
:level => 'info',
|
|
10
|
-
:component => 'RSpec',
|
|
11
|
-
:code => 'hello',
|
|
12
|
-
|
|
13
|
-
:data => { 'this' => 'that' },
|
|
14
|
-
|
|
15
|
-
:interaction_id => '3',
|
|
16
|
-
:caller_id => '2',
|
|
17
|
-
:identity => { :foo => '4', :bar => '5' },
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
############################################################################
|
|
22
|
-
# All tests must use 'let' to define values for 'reported_at' and
|
|
23
|
-
# 'expected_reported_at'.
|
|
24
|
-
############################################################################
|
|
25
|
-
|
|
26
|
-
let( :hash ) { base_hash().merge( :reported_at => reported_at() ) }
|
|
27
|
-
let( :expected_result ) {
|
|
28
|
-
Hoodoo::Utilities.stringify( hash() ).merge( 'reported_at' => expected_reported_at() )
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
shared_examples 'a well formed logger' do
|
|
32
|
-
it 'and canonicalises the fields' do
|
|
33
|
-
obj = described_class.new( hash() )
|
|
34
|
-
expect( obj.to_h ).to eq( expected_result() )
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context 'with a Time object in "reported_at"' do
|
|
39
|
-
let( :reported_at ) { Time.now }
|
|
40
|
-
let( :expected_reported_at ) { reported_at().strftime( Hoodoo::Services::Middleware::AMQPLogMessage::TIME_FORMATTER ) }
|
|
41
|
-
|
|
42
|
-
it_behaves_like 'a well formed logger'
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
context 'with a String object in "reported_at"' do
|
|
46
|
-
let( :reported_at ) { Time.now.iso8601 }
|
|
47
|
-
let( :expected_reported_at ) { reported_at() }
|
|
48
|
-
|
|
49
|
-
it_behaves_like 'a well formed logger'
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
context 'with "nil" in "reported_at"' do
|
|
53
|
-
let( :reported_at ) { nil }
|
|
54
|
-
let( :expected_reported_at ) { reported_at() }
|
|
55
|
-
|
|
56
|
-
it_behaves_like 'a well formed logger'
|
|
57
|
-
end
|
|
58
|
-
end
|