fastly_nsq 1.12.0 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +8 -1
- data/Gemfile +1 -0
- data/lib/fastly_nsq.rb +8 -0
- data/lib/fastly_nsq/feeder.rb +1 -0
- data/lib/fastly_nsq/listener.rb +18 -11
- data/lib/fastly_nsq/new_relic.rb +68 -0
- data/lib/fastly_nsq/version.rb +1 -1
- data/spec/new_relic.rb +92 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a96d39aaf8bfa8168a11523a097d7b06231d38f46f152d2b2432e07f51e7f69
|
4
|
+
data.tar.gz: 5107261e47c9c8786a86aff6369868acd98895e0e04b0745e6f31da1ac85f42b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4d4bd99d0789eafcc85826942b564d541ad760c9d7c64892cb7627a38984493b5812e02d73fe93b8ce9580a28c9f5f4abf6ac9e86f5e87823d349af87e4d493
|
7
|
+
data.tar.gz: 25c21fcee5324ca0cb16be4fde1dd4cc434d90c7d0dc9da6fdb5158ced9b2d6e978b33799aff3aecb52fad67b84686637309b543f787adf7625ad7f984931931
|
data/ChangeLog.md
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [v1.
|
3
|
+
## [v1.13.0](https://github.com/fastly/fastly_nsq/tree/v1.13.0)
|
4
4
|
|
5
|
+
[Full Changelog](https://github.com/fastly/fastly_nsq/compare/v1.12.0...v1.13.0)
|
6
|
+
|
7
|
+
**Merged pull requests:**
|
8
|
+
|
9
|
+
- Add NewRelic support [\#90](https://github.com/fastly/fastly_nsq/pull/90) ([leklund](https://github.com/leklund))
|
10
|
+
|
11
|
+
## [v1.12.0](https://github.com/fastly/fastly_nsq/tree/v1.12.0) (2018-07-25)
|
5
12
|
[Full Changelog](https://github.com/fastly/fastly_nsq/compare/v1.11.0...v1.12.0)
|
6
13
|
|
7
14
|
**Merged pull requests:**
|
data/Gemfile
CHANGED
data/lib/fastly_nsq.rb
CHANGED
@@ -138,6 +138,13 @@ module FastlyNsq
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
141
|
+
|
142
|
+
# Instance of FastlyNsq::NewRelic
|
143
|
+
#
|
144
|
+
# @return [FastlyNsq::NewRelic]
|
145
|
+
def tracer
|
146
|
+
@tracer ||= FastlyNsq::NewRelic.new
|
147
|
+
end
|
141
148
|
end
|
142
149
|
end
|
143
150
|
|
@@ -148,6 +155,7 @@ require 'fastly_nsq/listener'
|
|
148
155
|
require 'fastly_nsq/manager'
|
149
156
|
require 'fastly_nsq/message'
|
150
157
|
require 'fastly_nsq/messenger'
|
158
|
+
require 'fastly_nsq/new_relic'
|
151
159
|
require 'fastly_nsq/priority_queue'
|
152
160
|
require 'fastly_nsq/priority_thread_pool'
|
153
161
|
require 'fastly_nsq/producer'
|
data/lib/fastly_nsq/feeder.rb
CHANGED
data/lib/fastly_nsq/listener.rb
CHANGED
@@ -113,21 +113,28 @@ class FastlyNsq::Listener
|
|
113
113
|
def call(nsq_message)
|
114
114
|
message = FastlyNsq::Message.new(nsq_message)
|
115
115
|
|
116
|
+
msg_info = {
|
117
|
+
channel: channel,
|
118
|
+
topic: topic,
|
119
|
+
attempts: nsq_message.attempts,
|
120
|
+
id: Digest::MD5.hexdigest(nsq_message.body.to_s),
|
121
|
+
metadata: message.meta,
|
122
|
+
}
|
123
|
+
|
116
124
|
logger.info do
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
id: Digest::MD5.hexdigest(nsq_message.body.to_s),
|
122
|
-
metadata: message.meta,
|
123
|
-
}.tap do |l|
|
124
|
-
l[:data] = message.body if logger.level == Logger::DEBUG
|
125
|
+
if logger.level == Logger::DEBUG
|
126
|
+
msg_info.merge(data: message.body)
|
127
|
+
else
|
128
|
+
msg_info
|
125
129
|
end
|
126
130
|
end
|
127
131
|
|
128
|
-
|
129
|
-
|
130
|
-
|
132
|
+
FastlyNsq.tracer.trace_with_newrelic(params: msg_info, class_name: processor.class.to_s) do
|
133
|
+
preprocessor&.call(message)
|
134
|
+
result = processor.call(message)
|
135
|
+
message.finish if result
|
136
|
+
end
|
137
|
+
|
131
138
|
message
|
132
139
|
end
|
133
140
|
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'newrelic_rpm'
|
5
|
+
rescue LoadError # rubocop:disable Lint/HandleExceptions
|
6
|
+
end
|
7
|
+
|
8
|
+
##
|
9
|
+
# FastlyNsq::NewRelic supports tracing methods with NewRelic
|
10
|
+
# if the +newrelic_rpm+ is enabled
|
11
|
+
class FastlyNsq::NewRelic
|
12
|
+
include NewRelic::Agent::Instrumentation::ControllerInstrumentation if defined?(::NewRelic)
|
13
|
+
|
14
|
+
CATEGORY = 'OtherTransaction/FastlyNsqProcessor'
|
15
|
+
|
16
|
+
attr_reader :agent
|
17
|
+
|
18
|
+
##
|
19
|
+
# Create a FastlyNsq::NewRelic instance
|
20
|
+
# @param agent [#notice_error] optional and should only be used if you need to override the default +NewRelic::Agent+
|
21
|
+
# @example
|
22
|
+
# tracer = FastlyNsq::NewRelic.new
|
23
|
+
# tracer.notice_error(exception)
|
24
|
+
def initialize(agent = nil)
|
25
|
+
@agent = agent || (Object.const_defined?('NewRelic') ? NewRelic::Agent : nil)
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Returns true if NewRelic is loaded and available.
|
30
|
+
# @return [Boolean]
|
31
|
+
def enabled?
|
32
|
+
@enabled ||= Object.const_defined?('NewRelic')
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Notify NewRelic of an exception only if `enabled? == true`
|
37
|
+
# and an +agent+ is defined
|
38
|
+
# @param exception [Exception]
|
39
|
+
def notice_error(exception)
|
40
|
+
return unless enabled? && agent
|
41
|
+
|
42
|
+
agent.notice_error(exception)
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Trace passed block with new relic if `enabled? == true`
|
47
|
+
# @param trace_args [Hash] tracing parameters passed to NewRelic
|
48
|
+
#
|
49
|
+
# @see {https://www.rubydoc.info/github/newrelic/rpm/NewRelic%2FAgent%2FInstrumentation%2FControllerInstrumentation:perform_action_with_newrelic_trace}
|
50
|
+
def trace_with_newrelic(**args)
|
51
|
+
if enabled?
|
52
|
+
perform_action_with_newrelic_trace(trace_args(args)) do
|
53
|
+
yield
|
54
|
+
end
|
55
|
+
else
|
56
|
+
yield
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def trace_args(**args)
|
63
|
+
{
|
64
|
+
name: 'call',
|
65
|
+
category: CATEGORY,
|
66
|
+
}.merge(args)
|
67
|
+
end
|
68
|
+
end
|
data/lib/fastly_nsq/version.rb
CHANGED
data/spec/new_relic.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe FastlyNsq::NewRelic do
|
6
|
+
let(:agent) { double 'NewRelic::Agent', notice_error: true }
|
7
|
+
let(:tracer) { FastlyNsq::NewRelic.new(agent) }
|
8
|
+
|
9
|
+
describe '#enabled?' do
|
10
|
+
it 'returns false unless NewRelic is loaded' do
|
11
|
+
allow(Object).to receive(:const_defined?).with('NewRelic').and_return(false)
|
12
|
+
expect(tracer.enabled?).to be false
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns true id NewRelic is loaded' do
|
16
|
+
expect(tracer.enabled?).to be true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'enabled' do
|
21
|
+
before do
|
22
|
+
allow(Object).to receive(:const_defined?).with('NewRelic').and_return(true)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#notice_error' do
|
26
|
+
it 'call agent.notice_error' do
|
27
|
+
ex = Exception.new
|
28
|
+
|
29
|
+
tracer.notice_error(ex)
|
30
|
+
expect(agent).to have_received(:notice_error).with(ex)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#trace_with_newrelic' do
|
35
|
+
it 'calls perform_action_with_newrelic_trace and yields' do
|
36
|
+
allow(tracer).to receive(:perform_action_with_newrelic_trace).and_yield
|
37
|
+
|
38
|
+
expect { |b| tracer.trace_with_newrelic({}, &b) }.to yield_control
|
39
|
+
expect(tracer).to have_received(:perform_action_with_newrelic_trace)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'calls perform_action_with_newrelic_trace with trace_args' do
|
43
|
+
params = { id: 1, vp: 'joe biden' }
|
44
|
+
|
45
|
+
expected = {
|
46
|
+
name: 'call',
|
47
|
+
category: FastlyNsq::NewRelic::CATEGORY,
|
48
|
+
params: params,
|
49
|
+
class_name: 'SomeClass',
|
50
|
+
}
|
51
|
+
|
52
|
+
allow(tracer).to receive(:perform_action_with_newrelic_trace).and_yield
|
53
|
+
expect { |b| tracer.trace_with_newrelic(params: params, class_name: 'SomeClass', &b) }.to yield_control
|
54
|
+
|
55
|
+
expect(tracer).to have_received(:perform_action_with_newrelic_trace).with(expected)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'always sends the default trace args' do
|
59
|
+
expected = {
|
60
|
+
name: 'call',
|
61
|
+
category: FastlyNsq::NewRelic::CATEGORY,
|
62
|
+
}
|
63
|
+
allow(tracer).to receive(:perform_action_with_newrelic_trace).and_yield
|
64
|
+
|
65
|
+
expect { |b| tracer.trace_with_newrelic(&b) }.to yield_control
|
66
|
+
|
67
|
+
expect(tracer).to have_received(:perform_action_with_newrelic_trace).with(expected)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'disabled' do
|
73
|
+
before do
|
74
|
+
allow(Object).to receive(:const_defined?).with('NewRelic').and_return(false)
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '#notice_error' do
|
78
|
+
it 'returns nil' do
|
79
|
+
expect(tracer.notice_error('ex')).to be nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#trace_with_newrelic' do
|
84
|
+
it 'yields' do
|
85
|
+
allow(tracer).to receive(:perform_action_with_newrelic_trace)
|
86
|
+
|
87
|
+
expect { |b| tracer.trace_with_newrelic({}, &b) }.to yield_control
|
88
|
+
expect(tracer).not_to have_received(:perform_action_with_newrelic_trace)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastly_nsq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tommy O'Neil
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2018-07-
|
16
|
+
date: 2018-07-27 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: awesome_print
|
@@ -220,6 +220,7 @@ files:
|
|
220
220
|
- lib/fastly_nsq/manager.rb
|
221
221
|
- lib/fastly_nsq/message.rb
|
222
222
|
- lib/fastly_nsq/messenger.rb
|
223
|
+
- lib/fastly_nsq/new_relic.rb
|
223
224
|
- lib/fastly_nsq/priority_queue.rb
|
224
225
|
- lib/fastly_nsq/priority_thread_pool.rb
|
225
226
|
- lib/fastly_nsq/producer.rb
|
@@ -241,6 +242,7 @@ files:
|
|
241
242
|
- spec/matchers/delegate.rb
|
242
243
|
- spec/message_spec.rb
|
243
244
|
- spec/messenger_spec.rb
|
245
|
+
- spec/new_relic.rb
|
244
246
|
- spec/priority_thread_pool_spec.rb
|
245
247
|
- spec/producer_spec.rb
|
246
248
|
- spec/spec_helper.rb
|