appsignal 1.2.0.alpha.2 → 1.2.0.alpha.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 933e766ae7c1e093d8550927bb4585607a136935
4
- data.tar.gz: 46996d9237382423ffe444ef48e199c3a6db6c0d
3
+ metadata.gz: 37ce7a608d4c05aca6924e338f6c40fad52f4ae3
4
+ data.tar.gz: 63cb650e05a4a77088aee56f7382faa5844620aa
5
5
  SHA512:
6
- metadata.gz: ed0342c7f1be05351ea7ceaed903a153a06b094e186158fab39cb8dcfd354c3b6a694fd02ec9f562c00add31a168ba8b4c2b2739fa8e4b57e98f7d95f1224957
7
- data.tar.gz: 6de43ca1045c5200fa0e4355b728a5fd5e2a5d43d90e40a98313e60755968c2a3a378ed14c9f9da166591dfbb42705a509440b32e6ac3b5378a05acb37044138
6
+ metadata.gz: ea0336e1283562830aff2934ac941be1b5b23c17c18b9e38c39b67b2853c485e1b2cd3ece759df2373d1d954e8fa436168421c548a62d8ce4ccad07eb0f782b7
7
+ data.tar.gz: 02e5f376610e448a59e5bc3d0f01dcbc97918a77e9e0b46d972efaedcbe4c29941c76ccb7e90b61513f31d84061974426e2b55f5c70467d32c868fa5d6d354a2
@@ -1,6 +1,7 @@
1
1
  # 1.2.0
2
2
  * Restart background thread when FD's are closed
3
3
  * Beta version of collecting host metrics (disabled by default)
4
+ * Hooks for Shuryoken
4
5
 
5
6
  # 1.1.7
6
7
  * Make logging resilient for closing FD's (daemons gem does this)
@@ -93,6 +93,7 @@ require 'appsignal/hooks/puma'
93
93
  require 'appsignal/hooks/rake'
94
94
  require 'appsignal/hooks/redis'
95
95
  require 'appsignal/hooks/sequel'
96
+ require 'appsignal/hooks/shoryuken'
96
97
  require 'appsignal/hooks/sidekiq'
97
98
  require 'appsignal/hooks/unicorn'
98
99
  require 'appsignal/hooks/mongo_ruby_driver'
@@ -0,0 +1,42 @@
1
+ module Appsignal
2
+ class Hooks
3
+ class ShoryukenMiddleware
4
+ def call(worker_instance, queue, sqs_msg, body)
5
+ metadata = {
6
+ :queue => queue
7
+ }
8
+ exclude_keys = [ :job_class, :queue_name, :arguments ]
9
+ metadata.merge!(body.reject{ |key| exclude_keys.member?(key.to_sym) })
10
+ metadata.merge!(sqs_msg.attributes)
11
+
12
+ options = {
13
+ :class => body['job_class'],
14
+ :method => 'perform',
15
+ :metadata => metadata
16
+ }
17
+ options[:params] = body['arguments'] if body.key?('arguments')
18
+ options[:queue_start] = Time.at(sqs_msg.attributes['SentTimestamp'].to_i / 1000) if sqs_msg.attributes.key?('SentTimestamp')
19
+
20
+ Appsignal.monitor_transaction('perform_job.shoryuken', options) do
21
+ yield
22
+ end
23
+ end
24
+ end
25
+
26
+ class ShoryukenHook < Appsignal::Hooks::Hook
27
+ register :shoryuken
28
+
29
+ def dependencies_present?
30
+ defined?(::Shoryuken)
31
+ end
32
+
33
+ def install
34
+ ::Shoryuken.configure_server do |config|
35
+ config.server_middleware do |chain|
36
+ chain.add Appsignal::Hooks::ShoryukenMiddleware
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,5 @@
1
1
  require 'yaml'
2
2
 
3
3
  module Appsignal
4
- VERSION = '1.2.0.alpha.2'
4
+ VERSION = '1.2.0.alpha.3'
5
5
  end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Appsignal::Hooks::ShoryukenMiddleware do
5
+ let(:current_transaction) { background_job_transaction }
6
+
7
+ let(:worker_instance) { double }
8
+ let(:queue) { double }
9
+ let(:sqs_msg) {
10
+ double(:attributes => {})
11
+ }
12
+ let(:body) {{}}
13
+
14
+ before do
15
+ Appsignal.stub(:is_ignored_exception? => false)
16
+ Appsignal::Transaction.stub(:current => current_transaction)
17
+ start_agent
18
+ end
19
+
20
+ context "with a performance call" do
21
+ let(:queue) { 'some-funky-queue-name' }
22
+ let(:sqs_msg) {
23
+ double(:attributes => { 'SentTimestamp' => Time.parse('1976-11-18 0:00:00UTC').to_i * 1000 })
24
+ }
25
+ let(:body) {{
26
+ 'job_class' => 'TestClass',
27
+ 'arguments' => ['Model', "1"],
28
+ }}
29
+
30
+ it "should wrap in a transaction with the correct params" do
31
+ Appsignal.should_receive(:monitor_transaction).with(
32
+ 'perform_job.shoryuken',
33
+ :class => 'TestClass',
34
+ :method => 'perform',
35
+ :metadata => {
36
+ :queue => 'some-funky-queue-name',
37
+ 'SentTimestamp' => 217123200000
38
+ },
39
+ :params => ['Model', "1"],
40
+ :queue_start => Time.parse('1976-11-18 0:00:00UTC').utc
41
+ )
42
+ end
43
+
44
+ after do
45
+ Timecop.freeze(Time.parse('01-01-2001 10:01:00UTC')) do
46
+ Appsignal::Hooks::ShoryukenMiddleware.new.call(worker_instance, queue, sqs_msg, body) do
47
+ # nothing
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ context "with an erroring call" do
54
+ let(:error) { VerySpecificError.new('on fire') }
55
+
56
+ it "should add the exception to appsignal" do
57
+ Appsignal::Transaction.any_instance.should_receive(:set_error).with(error)
58
+ end
59
+
60
+ after do
61
+ begin
62
+ Timecop.freeze(Time.parse('01-01-2001 10:01:00UTC')) do
63
+ Appsignal::Hooks::ShoryukenMiddleware.new.call(worker_instance, queue, sqs_msg, body) do
64
+ raise error
65
+ end
66
+ end
67
+ rescue VerySpecificError
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ describe Appsignal::Hooks::ShoryukenHook do
74
+ context "with shoryuken" do
75
+ before(:all) do
76
+ module Shoryuken
77
+ def self.configure_server
78
+ end
79
+ end
80
+ Appsignal::Hooks::ShoryukenHook.new.install
81
+ end
82
+
83
+ after(:all) do
84
+ Object.send(:remove_const, :Shoryuken)
85
+ end
86
+
87
+ its(:dependencies_present?) { should be_true }
88
+ end
89
+
90
+ context "without shoryuken" do
91
+ its(:dependencies_present?) { should be_false }
92
+ end
93
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appsignal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.alpha.2
4
+ version: 1.2.0.alpha.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Beekman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-25 00:00:00.000000000 Z
12
+ date: 2016-05-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -175,6 +175,7 @@ files:
175
175
  - lib/appsignal/hooks/rake.rb
176
176
  - lib/appsignal/hooks/redis.rb
177
177
  - lib/appsignal/hooks/sequel.rb
178
+ - lib/appsignal/hooks/shoryuken.rb
178
179
  - lib/appsignal/hooks/sidekiq.rb
179
180
  - lib/appsignal/hooks/unicorn.rb
180
181
  - lib/appsignal/integrations/capistrano/appsignal.cap
@@ -238,6 +239,7 @@ files:
238
239
  - spec/lib/appsignal/hooks/rake_spec.rb
239
240
  - spec/lib/appsignal/hooks/redis_spec.rb
240
241
  - spec/lib/appsignal/hooks/sequel_spec.rb
242
+ - spec/lib/appsignal/hooks/shoryuken_spec.rb
241
243
  - spec/lib/appsignal/hooks/sidekiq_spec.rb
242
244
  - spec/lib/appsignal/hooks/unicorn_spec.rb
243
245
  - spec/lib/appsignal/hooks_spec.rb
@@ -335,6 +337,7 @@ test_files:
335
337
  - spec/lib/appsignal/hooks/rake_spec.rb
336
338
  - spec/lib/appsignal/hooks/redis_spec.rb
337
339
  - spec/lib/appsignal/hooks/sequel_spec.rb
340
+ - spec/lib/appsignal/hooks/shoryuken_spec.rb
338
341
  - spec/lib/appsignal/hooks/sidekiq_spec.rb
339
342
  - spec/lib/appsignal/hooks/unicorn_spec.rb
340
343
  - spec/lib/appsignal/hooks_spec.rb