freddy 1.7.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +31 -0
- data/.rubocop.yml +9 -28
- data/.ruby-gemset +1 -1
- data/.ruby-version +1 -1
- data/Gemfile +3 -4
- data/README.md +5 -10
- data/freddy.gemspec +10 -17
- data/lib/freddy.rb +9 -14
- data/lib/freddy/adapters.rb +3 -28
- data/lib/freddy/adapters/bunny_adapter.rb +19 -2
- data/lib/freddy/consumers.rb +1 -1
- data/lib/freddy/consumers/respond_to_consumer.rb +3 -13
- data/lib/freddy/consumers/response_consumer.rb +2 -4
- data/lib/freddy/consumers/tap_into_consumer.rb +12 -24
- data/lib/freddy/delivery.rb +46 -13
- data/lib/freddy/payload.rb +2 -33
- data/lib/freddy/producers.rb +1 -1
- data/lib/freddy/producers/reply_producer.rb +12 -5
- data/lib/freddy/producers/send_and_forget_producer.rb +5 -11
- data/lib/freddy/producers/send_and_wait_response_producer.rb +19 -33
- data/lib/freddy/request_manager.rb +1 -9
- data/lib/freddy/tracing.rb +37 -0
- data/lib/freddy/version.rb +5 -0
- data/spec/.rubocop.yml +26 -0
- data/spec/freddy/error_response_spec.rb +6 -6
- data/spec/freddy/payload_spec.rb +25 -16
- data/spec/integration/concurrency_spec.rb +8 -12
- data/spec/integration/tracing_spec.rb +15 -32
- data/spec/spec_helper.rb +5 -13
- metadata +28 -15
- data/.npmignore +0 -8
- data/.travis.yml +0 -16
- data/lib/freddy/adapters/march_hare_adapter.rb +0 -64
- data/lib/freddy/trace_carrier.rb +0 -28
- data/spec/freddy/trace_carrier_spec.rb +0 -56
@@ -1,13 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'opentracing_test_tracer'
|
3
2
|
|
4
3
|
describe 'Tracing' do
|
5
|
-
let(:tracer) { OpenTracingTestTracer.build(logger: logger) }
|
6
4
|
let(:logger) { spy }
|
7
5
|
|
8
|
-
before { OpenTracing.global_tracer = tracer }
|
9
|
-
after { OpenTracing.global_tracer = nil }
|
10
|
-
|
11
6
|
context 'when receiving a traced request' do
|
12
7
|
let(:freddy) { Freddy.build(logger, config) }
|
13
8
|
let(:freddy2) { Freddy.build(logger, config) }
|
@@ -18,21 +13,13 @@ describe 'Tracing' do
|
|
18
13
|
before do
|
19
14
|
freddy.respond_to(destination) do |_payload, msg_handler|
|
20
15
|
msg_handler.success(
|
21
|
-
trace_initiator:
|
22
|
-
trace_id: active_span.context.trace_id,
|
23
|
-
parent_id: active_span.context.parent_id,
|
24
|
-
span_id: active_span.context.span_id
|
25
|
-
},
|
16
|
+
trace_initiator: current_span_attributes,
|
26
17
|
current_receiver: freddy.deliver_with_response(destination2, {})
|
27
18
|
)
|
28
19
|
end
|
29
20
|
|
30
21
|
freddy2.respond_to(destination2) do |_payload, msg_handler|
|
31
|
-
msg_handler.success(
|
32
|
-
trace_id: active_span.context.trace_id,
|
33
|
-
parent_id: active_span.context.parent_id,
|
34
|
-
span_id: active_span.context.span_id
|
35
|
-
)
|
22
|
+
msg_handler.success(current_span_attributes)
|
36
23
|
end
|
37
24
|
end
|
38
25
|
|
@@ -75,31 +62,19 @@ describe 'Tracing' do
|
|
75
62
|
before do
|
76
63
|
freddy.respond_to(destination) do |_payload, msg_handler|
|
77
64
|
msg_handler.success({
|
78
|
-
trace_initiator:
|
79
|
-
trace_id: active_span.context.trace_id,
|
80
|
-
parent_id: active_span.context.parent_id,
|
81
|
-
span_id: active_span.context.span_id
|
82
|
-
}
|
65
|
+
trace_initiator: current_span_attributes
|
83
66
|
}.merge(freddy.deliver_with_response(destination2, {})))
|
84
67
|
end
|
85
68
|
|
86
69
|
freddy2.respond_to(destination2) do |_payload, msg_handler|
|
87
70
|
msg_handler.success(
|
88
|
-
previous_receiver:
|
89
|
-
trace_id: active_span.context.trace_id,
|
90
|
-
parent_id: active_span.context.parent_id,
|
91
|
-
span_id: active_span.context.span_id
|
92
|
-
},
|
71
|
+
previous_receiver: current_span_attributes,
|
93
72
|
current_receiver: freddy2.deliver_with_response(destination3, {})
|
94
73
|
)
|
95
74
|
end
|
96
75
|
|
97
76
|
freddy3.respond_to(destination3) do |_payload, msg_handler|
|
98
|
-
msg_handler.success(
|
99
|
-
trace_id: active_span.context.trace_id,
|
100
|
-
parent_id: active_span.context.parent_id,
|
101
|
-
span_id: active_span.context.span_id
|
102
|
-
)
|
77
|
+
msg_handler.success(current_span_attributes)
|
103
78
|
end
|
104
79
|
end
|
105
80
|
|
@@ -131,7 +106,15 @@ describe 'Tracing' do
|
|
131
106
|
end
|
132
107
|
end
|
133
108
|
|
134
|
-
def
|
135
|
-
|
109
|
+
def current_span_attributes
|
110
|
+
{
|
111
|
+
trace_id: current_span.context.trace_id,
|
112
|
+
parent_id: current_span.parent_span_id,
|
113
|
+
span_id: current_span.context.span_id
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
def current_span
|
118
|
+
OpenTelemetry::Trace.current_span
|
136
119
|
end
|
137
120
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,14 +2,9 @@ require 'rubygems'
|
|
2
2
|
require 'bundler'
|
3
3
|
Bundler.setup
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
SimpleCov::Formatter::HTMLFormatter,
|
9
|
-
CodeClimate::TestReporter::Formatter
|
10
|
-
])
|
11
|
-
add_filter '/spec/'
|
12
|
-
end
|
5
|
+
ENV['OTEL_TRACES_EXPORTER'] = 'none'
|
6
|
+
require 'opentelemetry/sdk'
|
7
|
+
OpenTelemetry::SDK.configure
|
13
8
|
|
14
9
|
require 'pry'
|
15
10
|
require 'freddy'
|
@@ -22,10 +17,6 @@ RSpec.configure do |config|
|
|
22
17
|
config.run_all_when_everything_filtered = true
|
23
18
|
config.filter_run :focus
|
24
19
|
config.order = 'random'
|
25
|
-
|
26
|
-
config.before do
|
27
|
-
OpenTracing.global_tracer ||= OpenTracing::Tracer.new
|
28
|
-
end
|
29
20
|
end
|
30
21
|
|
31
22
|
def random_destination
|
@@ -43,6 +34,7 @@ end
|
|
43
34
|
def wait_for
|
44
35
|
100.times do
|
45
36
|
return if yield
|
37
|
+
|
46
38
|
sleep 0.005
|
47
39
|
end
|
48
40
|
end
|
@@ -53,7 +45,7 @@ def deliver(custom_destination = destination)
|
|
53
45
|
end
|
54
46
|
|
55
47
|
def logger
|
56
|
-
Logger.new(
|
48
|
+
Logger.new($stdout).tap { |l| l.level = Logger::ERROR }
|
57
49
|
end
|
58
50
|
|
59
51
|
def config
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: freddy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Glia TechMovers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -67,19 +67,33 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.6'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: opentelemetry-api
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.0.0.rc3
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.0.0.rc3
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: opentelemetry-semantic_conventions
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: thread
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,13 +115,12 @@ executables: []
|
|
101
115
|
extensions: []
|
102
116
|
extra_rdoc_files: []
|
103
117
|
files:
|
118
|
+
- ".github/workflows/ci.yml"
|
104
119
|
- ".gitignore"
|
105
|
-
- ".npmignore"
|
106
120
|
- ".rspec"
|
107
121
|
- ".rubocop.yml"
|
108
122
|
- ".ruby-gemset"
|
109
123
|
- ".ruby-version"
|
110
|
-
- ".travis.yml"
|
111
124
|
- Gemfile
|
112
125
|
- LICENCE.txt
|
113
126
|
- README.md
|
@@ -116,7 +129,6 @@ files:
|
|
116
129
|
- lib/freddy.rb
|
117
130
|
- lib/freddy/adapters.rb
|
118
131
|
- lib/freddy/adapters/bunny_adapter.rb
|
119
|
-
- lib/freddy/adapters/march_hare_adapter.rb
|
120
132
|
- lib/freddy/consumers.rb
|
121
133
|
- lib/freddy/consumers/respond_to_consumer.rb
|
122
134
|
- lib/freddy/consumers/response_consumer.rb
|
@@ -135,7 +147,9 @@ files:
|
|
135
147
|
- lib/freddy/responder_handler.rb
|
136
148
|
- lib/freddy/sync_response_container.rb
|
137
149
|
- lib/freddy/timeout_error.rb
|
138
|
-
- lib/freddy/
|
150
|
+
- lib/freddy/tracing.rb
|
151
|
+
- lib/freddy/version.rb
|
152
|
+
- spec/.rubocop.yml
|
139
153
|
- spec/freddy/consumers/respond_to_consumer_spec.rb
|
140
154
|
- spec/freddy/error_response_spec.rb
|
141
155
|
- spec/freddy/freddy_spec.rb
|
@@ -143,15 +157,14 @@ files:
|
|
143
157
|
- spec/freddy/payload_spec.rb
|
144
158
|
- spec/freddy/responder_handler_spec.rb
|
145
159
|
- spec/freddy/sync_response_container_spec.rb
|
146
|
-
- spec/freddy/trace_carrier_spec.rb
|
147
160
|
- spec/integration/concurrency_spec.rb
|
148
161
|
- spec/integration/reply_spec.rb
|
149
162
|
- spec/integration/tap_into_with_group_spec.rb
|
150
163
|
- spec/integration/tracing_spec.rb
|
151
164
|
- spec/spec_helper.rb
|
152
|
-
homepage:
|
165
|
+
homepage: https://github.com/salemove/freddy
|
153
166
|
licenses:
|
154
|
-
-
|
167
|
+
- MIT
|
155
168
|
metadata: {}
|
156
169
|
post_install_message:
|
157
170
|
rdoc_options: []
|
@@ -161,18 +174,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
174
|
requirements:
|
162
175
|
- - ">="
|
163
176
|
- !ruby/object:Gem::Version
|
164
|
-
version: '
|
177
|
+
version: '2.7'
|
165
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
179
|
requirements:
|
167
180
|
- - ">="
|
168
181
|
- !ruby/object:Gem::Version
|
169
182
|
version: '0'
|
170
183
|
requirements: []
|
171
|
-
rubygems_version: 3.
|
184
|
+
rubygems_version: 3.1.4
|
172
185
|
signing_key:
|
173
186
|
specification_version: 4
|
174
187
|
summary: API for inter-application messaging supporting acknowledgements and request-response
|
175
188
|
test_files:
|
189
|
+
- spec/.rubocop.yml
|
176
190
|
- spec/freddy/consumers/respond_to_consumer_spec.rb
|
177
191
|
- spec/freddy/error_response_spec.rb
|
178
192
|
- spec/freddy/freddy_spec.rb
|
@@ -180,7 +194,6 @@ test_files:
|
|
180
194
|
- spec/freddy/payload_spec.rb
|
181
195
|
- spec/freddy/responder_handler_spec.rb
|
182
196
|
- spec/freddy/sync_response_container_spec.rb
|
183
|
-
- spec/freddy/trace_carrier_spec.rb
|
184
197
|
- spec/integration/concurrency_spec.rb
|
185
198
|
- spec/integration/reply_spec.rb
|
186
199
|
- spec/integration/tap_into_with_group_spec.rb
|
data/.npmignore
DELETED
data/.travis.yml
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.5.6
|
4
|
-
- jruby-9.2.8.0
|
5
|
-
addons:
|
6
|
-
code_climate:
|
7
|
-
repo_token: 1f3842b985fdeff6a36168165d491ca5f444667e9381a85c899a61706a9dd285
|
8
|
-
apt:
|
9
|
-
packages:
|
10
|
-
- rabbitmq-server
|
11
|
-
services:
|
12
|
-
- rabbitmq
|
13
|
-
before_script:
|
14
|
-
- gem install bundler
|
15
|
-
- bundle install
|
16
|
-
script: bundle exec rake
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'march_hare'
|
4
|
-
|
5
|
-
class Freddy
|
6
|
-
module Adapters
|
7
|
-
class MarchHareAdapter
|
8
|
-
def self.connect(config)
|
9
|
-
hare = MarchHare.connect(config)
|
10
|
-
new(hare)
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(hare)
|
14
|
-
@hare = hare
|
15
|
-
end
|
16
|
-
|
17
|
-
def create_channel(prefetch: nil)
|
18
|
-
hare_channel = @hare.create_channel
|
19
|
-
hare_channel.basic_qos(prefetch) if prefetch
|
20
|
-
Channel.new(hare_channel)
|
21
|
-
end
|
22
|
-
|
23
|
-
def close
|
24
|
-
@hare.close
|
25
|
-
end
|
26
|
-
|
27
|
-
class Channel
|
28
|
-
extend Forwardable
|
29
|
-
|
30
|
-
NO_ROUTE = 312
|
31
|
-
|
32
|
-
def initialize(channel)
|
33
|
-
@channel = channel
|
34
|
-
end
|
35
|
-
|
36
|
-
def_delegators :@channel, :topic, :default_exchange, :consumers, :acknowledge, :reject
|
37
|
-
|
38
|
-
def queue(*args)
|
39
|
-
Queue.new(@channel.queue(*args))
|
40
|
-
end
|
41
|
-
|
42
|
-
def on_no_route
|
43
|
-
@channel.on_return do |reply_code, _, exchange_name, _, properties|
|
44
|
-
if exchange_name != Freddy::FREDDY_TOPIC_EXCHANGE_NAME && reply_code == NO_ROUTE
|
45
|
-
yield(properties.correlation_id)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class Queue < Shared::Queue
|
52
|
-
def subscribe(manual_ack: false)
|
53
|
-
@queue.subscribe(manual_ack: manual_ack) do |meta, payload|
|
54
|
-
parsed_payload = Payload.parse(payload)
|
55
|
-
delivery = Delivery.new(
|
56
|
-
parsed_payload, meta, meta.routing_key, meta.delivery_tag
|
57
|
-
)
|
58
|
-
yield(delivery)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
data/lib/freddy/trace_carrier.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Freddy
|
4
|
-
# Carrier for rabbitmq following OpenTracing API
|
5
|
-
# See https://github.com/opentracing/opentracing-ruby/blob/master/lib/opentracing/carrier.rb
|
6
|
-
class TraceCarrier
|
7
|
-
def initialize(properties)
|
8
|
-
@properties = properties
|
9
|
-
end
|
10
|
-
|
11
|
-
def [](key)
|
12
|
-
@properties.headers && @properties.headers["x-trace-#{key}"]
|
13
|
-
end
|
14
|
-
|
15
|
-
def []=(key, value)
|
16
|
-
@properties[:headers] ||= {}
|
17
|
-
@properties[:headers]["x-trace-#{key}"] = value
|
18
|
-
end
|
19
|
-
|
20
|
-
def each(&block)
|
21
|
-
Hash[
|
22
|
-
(@properties.headers || {})
|
23
|
-
.select { |key, _| key =~ /^x-trace/ }
|
24
|
-
.map { |key, value| [key.sub(/x-trace-/, ''), value] }
|
25
|
-
].each(&block)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Freddy::TraceCarrier do
|
4
|
-
subject(:carrier) { described_class.new(properties) }
|
5
|
-
|
6
|
-
context 'when adding trace information' do
|
7
|
-
let(:properties) { { x: 'y' } }
|
8
|
-
let(:key_name) { 'some-key' }
|
9
|
-
let(:key_value) { 'some-key' }
|
10
|
-
|
11
|
-
it 'adds a header with x-trace- prefix' do
|
12
|
-
carrier[key_name] = key_value
|
13
|
-
expect(properties[:headers]["x-trace-#{key_name}"]).to eq(key_value)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'when extracting trace information' do
|
18
|
-
let(:key_name) { 'some-key' }
|
19
|
-
let(:serialized_key_name) { "x-trace-#{key_name}" }
|
20
|
-
let(:key_value) { 'some-key' }
|
21
|
-
|
22
|
-
let(:properties) do
|
23
|
-
double(headers: { serialized_key_name => key_value })
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'extracts a header with x-trace- prefix' do
|
27
|
-
expect(carrier[key_name]).to eq(key_value)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#each' do
|
32
|
-
context 'when headers are present' do
|
33
|
-
let(:properties) do
|
34
|
-
double(
|
35
|
-
headers: {
|
36
|
-
'x-trace-key1' => 'value1',
|
37
|
-
'x-trace-key2' => 'value2',
|
38
|
-
'other-key' => 'value3'
|
39
|
-
}
|
40
|
-
)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'iterates over keys starting with x-trace- prefix' do
|
44
|
-
expect(carrier.each.count).to eq(2)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'when no headers' do
|
49
|
-
let(:properties) { double(headers: nil) }
|
50
|
-
|
51
|
-
it 'iterates over an empty list' do
|
52
|
-
expect(carrier.each.count).to eq(0)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|