chillout 0.8.6 → 0.8.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -2
- data/CHANGELOG.md +6 -0
- data/Gemfile +3 -1
- data/lib/chillout/middleware/sidekiq.rb +55 -1
- data/lib/chillout/version.rb +1 -1
- data/test/acceptance/sidekiq_workers_send_metrics_test.rb +19 -2
- data/test/middleware/sidekiq_test.rb +31 -2
- data/test/support/rails_4_1_16/Gemfile +5 -0
- data/test/support/rails_4_1_16/app/jobs/create_entity_job.rb +6 -0
- data/test/support/rails_4_2_0/Gemfile +2 -2
- data/test/support/rails_4_2_8/Gemfile +1 -1
- data/test/support/rails_5_0_3/Gemfile +1 -1
- data/test/support/rails_5_1_1/Gemfile +1 -1
- data/test/test_helper.rb +30 -22
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6631dcadcf73b03ed3a10a4ef2e7d79ac081c3cf
|
4
|
+
data.tar.gz: e2097e2a4d295b7fd0f6c36f6eac008aad94523c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d10872b0af3d30b51ef10dfaa6530e177cc1d3f329ea39a621127d691dc10d9befc1a73e4fc2e3029fa06c0605df6fc51369bf0d662f0f3babd603a8ec6fe61b
|
7
|
+
data.tar.gz: b1a7b075053a58cb0e06e7f75cac2f6c6c4ca255c7a8abe9056eae3c05ea9549ece21bc5341ff6ac263631f479466d4474f8c1571ec77f5b0e2024a2079639b7
|
data/.travis.yml
CHANGED
@@ -10,7 +10,7 @@ env:
|
|
10
10
|
- SAMPLE_APP=rails_4_0_0
|
11
11
|
- SAMPLE_APP=rails_4_0_13
|
12
12
|
- SAMPLE_APP=rails_4_1_0
|
13
|
-
- SAMPLE_APP=rails_4_1_16
|
13
|
+
- SAMPLE_APP=rails_4_1_16 SIDEKIQ_SUPPORTED=true
|
14
14
|
- SAMPLE_APP=rails_4_2_0 SIDEKIQ_SUPPORTED=true
|
15
15
|
- SAMPLE_APP=rails_4_2_8 SIDEKIQ_SUPPORTED=true
|
16
16
|
- SAMPLE_APP=rails_5_0_3 SIDEKIQ_SUPPORTED=true
|
@@ -24,7 +24,7 @@ matrix:
|
|
24
24
|
- rvm: 2.4.1
|
25
25
|
env: SAMPLE_APP=rails_4_1_0
|
26
26
|
- rvm: 2.4.1
|
27
|
-
env: SAMPLE_APP=rails_4_1_16
|
27
|
+
env: SAMPLE_APP=rails_4_1_16 SIDEKIQ_SUPPORTED=true
|
28
28
|
- rvm: 2.4.1
|
29
29
|
env: SAMPLE_APP=rails_4_2_0 SIDEKIQ_SUPPORTED=true
|
30
30
|
- rvm: 2.1.10
|
@@ -34,6 +34,10 @@ matrix:
|
|
34
34
|
- rvm: 2.1.10
|
35
35
|
env: SAMPLE_APP=rails_5_1_1 SIDEKIQ_SUPPORTED=true
|
36
36
|
include:
|
37
|
+
- rvm: 2.1.10
|
38
|
+
env: SIDEKIQ_VERSION=3.5.3 SAMPLE_APP=rails_4_1_16 SIDEKIQ_SUPPORTED=true
|
39
|
+
- rvm: 2.1.10
|
40
|
+
env: SIDEKIQ_VERSION=4.0 SAMPLE_APP=rails_4_1_16 SIDEKIQ_SUPPORTED=true
|
37
41
|
- rvm: 2.4.1
|
38
42
|
env: SAMPLE_APP=rails_4_2_8 STRATEGY=active_job SIDEKIQ_SUPPORTED=true
|
39
43
|
- rvm: 2.4.1
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -1,18 +1,72 @@
|
|
1
1
|
module Chillout
|
2
2
|
module Middleware
|
3
3
|
|
4
|
+
class SidekiqJobMeasurement
|
5
|
+
attr_reader :retriable, :queue, :started,
|
6
|
+
:finished, :delay, :duration, :success
|
7
|
+
|
8
|
+
def initialize(job, queue, started, finished, success)
|
9
|
+
@class = job["class"].to_s
|
10
|
+
@retriable = job["retry"].to_s
|
11
|
+
@queue = queue
|
12
|
+
@started = started.utc
|
13
|
+
@finished = finished.utc
|
14
|
+
enqueued_at = job["enqueued_at"] || @finished.to_f
|
15
|
+
@delay = 1000.0 * (@finished.to_f - enqueued_at)
|
16
|
+
@duration = 1000.0 * (@finished.to_f - @started.to_f)
|
17
|
+
@success = success.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
def job_class
|
21
|
+
@class
|
22
|
+
end
|
23
|
+
|
24
|
+
def as_measurements()
|
25
|
+
[{
|
26
|
+
series: "sidekiq_jobs",
|
27
|
+
tags: {
|
28
|
+
class: @class,
|
29
|
+
retriable: @retriable,
|
30
|
+
queue: @queue,
|
31
|
+
success: @success.to_s,
|
32
|
+
},
|
33
|
+
timestamp: @finished.iso8601,
|
34
|
+
values: {
|
35
|
+
finished: 1,
|
36
|
+
duration: @duration.to_f,
|
37
|
+
delay: @delay.to_f
|
38
|
+
},
|
39
|
+
}]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
4
43
|
class SidekiqCreationsMonitor
|
5
44
|
def initialize(options)
|
6
45
|
@client = options.fetch(:client)
|
7
46
|
end
|
8
47
|
|
9
|
-
def call(_worker,
|
48
|
+
def call(_worker, job, queue)
|
49
|
+
started = Time.now.utc
|
50
|
+
success = false
|
10
51
|
yield
|
52
|
+
success = true
|
11
53
|
ensure
|
54
|
+
enqueue(queue, job, started, success)
|
55
|
+
end
|
56
|
+
|
57
|
+
def enqueue(_queue, job, started, success)
|
58
|
+
finished = Time.now.utc
|
12
59
|
if creations = Chillout.creations
|
13
60
|
Chillout.creations = nil
|
14
61
|
@client.enqueue(creations)
|
15
62
|
end
|
63
|
+
@client.enqueue(SidekiqJobMeasurement.new(
|
64
|
+
job,
|
65
|
+
_queue,
|
66
|
+
started,
|
67
|
+
finished,
|
68
|
+
success
|
69
|
+
))
|
16
70
|
end
|
17
71
|
end
|
18
72
|
|
data/lib/chillout/version.rb
CHANGED
@@ -8,15 +8,32 @@ class SidekiqWorkersSendMetricsTest < AcceptanceTestCase
|
|
8
8
|
test_endpoint = TestEndpoint.new(port: 8081)
|
9
9
|
|
10
10
|
test_endpoint.listen
|
11
|
-
test_sidekiq_worker.boot(chillout_port: 8081)
|
12
11
|
test_sidekiq_worker.push_job
|
12
|
+
test_sidekiq_worker.boot(chillout_port: 8081)
|
13
13
|
|
14
14
|
if ENV['STRATEGY'] != 'active_job'
|
15
15
|
assert test_endpoint.has_received_information_about_startup
|
16
16
|
end
|
17
17
|
assert test_endpoint.has_one_creation_for_entity_resource
|
18
|
+
|
19
|
+
assert sidekiq = test_endpoint.has_one_sidekiq_metric
|
20
|
+
assert_equal "CreateEntityJob", sidekiq.fetch("tags").fetch("class")
|
21
|
+
assert_equal "default", sidekiq.fetch("tags").fetch("queue")
|
22
|
+
assert_equal "true", sidekiq.fetch("tags").fetch("retriable")
|
23
|
+
assert_equal "true", sidekiq.fetch("tags").fetch("success")
|
24
|
+
|
25
|
+
assert sidekiq.fetch("timestamp")
|
26
|
+
|
27
|
+
assert_equal 1, sidekiq.fetch("values").fetch("finished")
|
28
|
+
assert_operator 90, :>, sidekiq.fetch("values").fetch("duration")
|
29
|
+
assert_operator 0, :<, sidekiq.fetch("values").fetch("duration")
|
30
|
+
assert_operator 8000, :>, sidekiq.fetch("values").fetch("delay")
|
31
|
+
assert_operator 200, :<, sidekiq.fetch("values").fetch("delay")
|
18
32
|
ensure
|
19
|
-
|
33
|
+
if test_sidekiq_worker
|
34
|
+
test_sidekiq_worker.clear_jobs
|
35
|
+
test_sidekiq_worker.shutdown
|
36
|
+
end
|
20
37
|
end
|
21
38
|
|
22
39
|
end if ENV['SIDEKIQ_SUPPORTED']
|
@@ -24,8 +24,13 @@ module Chillout
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def test_enqueues_stats_and_clears_creations
|
28
28
|
@client.expects(:enqueue).with(FakeJob::MOCK_CREATIONS)
|
29
|
+
@client.expects(:enqueue).with do |measurement|
|
30
|
+
SidekiqJobMeasurement === measurement &&
|
31
|
+
measurement.success == "true" &&
|
32
|
+
measurement.job_class == "Chillout::Middleware::SidekiqTest::FakeJob"
|
33
|
+
end
|
29
34
|
Sidekiq::Testing.inline! { FakeJob.perform_async }
|
30
35
|
assert_nil Chillout.creations
|
31
36
|
end
|
@@ -35,11 +40,35 @@ module Chillout
|
|
35
40
|
def perform; end
|
36
41
|
end
|
37
42
|
|
38
|
-
def
|
43
|
+
def test_enqueues_stats_only_when_no_creations
|
44
|
+
@client.expects(:enqueue).with do |measurement|
|
45
|
+
SidekiqJobMeasurement === measurement
|
46
|
+
end
|
39
47
|
Sidekiq::Testing.inline! { EmptyJob.perform_async }
|
40
48
|
assert_nil Chillout.creations
|
41
49
|
end
|
42
50
|
|
51
|
+
class ErrorJob
|
52
|
+
Doh = Class.new(StandardError)
|
53
|
+
include Sidekiq::Worker
|
54
|
+
def perform
|
55
|
+
raise Doh
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_enqueues_stats_even_on_failure
|
60
|
+
@client.expects(:enqueue).with do |measurement|
|
61
|
+
SidekiqJobMeasurement === measurement &&
|
62
|
+
measurement.success == "false"
|
63
|
+
end
|
64
|
+
Sidekiq::Testing.inline! do
|
65
|
+
assert_raises(ErrorJob::Doh) do
|
66
|
+
ErrorJob.perform_async
|
67
|
+
end
|
68
|
+
end
|
69
|
+
assert_nil Chillout.creations
|
70
|
+
end
|
71
|
+
|
43
72
|
end
|
44
73
|
end
|
45
74
|
end
|
@@ -3,3 +3,8 @@ source 'https://rubygems.org'
|
|
3
3
|
gem 'rails', '4.1.16'
|
4
4
|
gem 'sqlite3'
|
5
5
|
gem 'chillout', :path => '../../../'
|
6
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2')
|
7
|
+
gem "sidekiq", ENV['SIDEKIQ_VERSION'] || "~> 4.2"
|
8
|
+
else
|
9
|
+
gem "sidekiq", ENV['SIDEKIQ_VERSION'] || ">= 5"
|
10
|
+
end
|
@@ -4,7 +4,7 @@ gem 'rails', '4.2.0'
|
|
4
4
|
gem 'sqlite3'
|
5
5
|
gem 'chillout', :path => '../../../'
|
6
6
|
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2')
|
7
|
-
gem "sidekiq", "~> 4.2"
|
7
|
+
gem "sidekiq", ENV['SIDEKIQ_VERSION'] || "~> 4.2"
|
8
8
|
else
|
9
|
-
gem
|
9
|
+
gem "sidekiq", ENV['SIDEKIQ_VERSION'] || ">= 5"
|
10
10
|
end
|
data/test/test_helper.rb
CHANGED
@@ -5,6 +5,7 @@ require 'rack/test'
|
|
5
5
|
require 'pathname'
|
6
6
|
require 'bbq/spawn'
|
7
7
|
require 'sidekiq/testing'
|
8
|
+
require 'sidekiq/api'
|
8
9
|
|
9
10
|
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
|
10
11
|
|
@@ -135,6 +136,12 @@ class TestSidekiqServer
|
|
135
136
|
)
|
136
137
|
end
|
137
138
|
end
|
139
|
+
|
140
|
+
def clear_jobs
|
141
|
+
Sidekiq::Testing.disable! do
|
142
|
+
Sidekiq::Queue.new.💣
|
143
|
+
end
|
144
|
+
end
|
138
145
|
end
|
139
146
|
|
140
147
|
class TestEndpoint
|
@@ -145,6 +152,7 @@ class TestEndpoint
|
|
145
152
|
@metrics = Queue.new
|
146
153
|
@startups = Queue.new
|
147
154
|
@port = port
|
155
|
+
@all_metrics = []
|
148
156
|
end
|
149
157
|
|
150
158
|
def listen
|
@@ -182,36 +190,33 @@ class TestEndpoint
|
|
182
190
|
end
|
183
191
|
|
184
192
|
def has_one_creation_for_entity_resource
|
185
|
-
|
186
|
-
begin
|
187
|
-
many = metrics.pop(true)
|
188
|
-
metric = many["measurements"].find{|m| m["series"] == "Entity" }
|
189
|
-
return metric if metric
|
190
|
-
rescue ThreadError
|
191
|
-
sleep(1)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
false
|
193
|
+
look_for_series("Entity")
|
195
194
|
end
|
196
195
|
|
197
196
|
def has_one_purchase
|
198
|
-
|
199
|
-
begin
|
200
|
-
many = metrics.pop(true)
|
201
|
-
metric = many["measurements"].find{|m| m["series"] == "purchases" }
|
202
|
-
return metric if metric
|
203
|
-
rescue ThreadError
|
204
|
-
sleep(1)
|
205
|
-
end
|
206
|
-
end
|
207
|
-
false
|
197
|
+
look_for_series("purchases")
|
208
198
|
end
|
209
199
|
|
210
200
|
def has_one_controller_metric
|
201
|
+
look_for_series("request")
|
202
|
+
end
|
203
|
+
|
204
|
+
def has_one_sidekiq_metric
|
205
|
+
look_for_series("sidekiq_jobs")
|
206
|
+
end
|
207
|
+
|
208
|
+
private
|
209
|
+
|
210
|
+
def look_for(&search)
|
211
211
|
10.times do
|
212
212
|
begin
|
213
|
+
metric = @all_metrics.find(&search)
|
214
|
+
return metric if metric
|
215
|
+
|
213
216
|
many = metrics.pop(true)
|
214
|
-
|
217
|
+
@all_metrics.concat(many["measurements"])
|
218
|
+
|
219
|
+
metric = @all_metrics.find(&search)
|
215
220
|
return metric if metric
|
216
221
|
rescue ThreadError
|
217
222
|
sleep(1)
|
@@ -220,5 +225,8 @@ class TestEndpoint
|
|
220
225
|
false
|
221
226
|
end
|
222
227
|
|
223
|
-
|
228
|
+
def look_for_series(series)
|
229
|
+
look_for{|m| m["series"] == series }
|
230
|
+
end
|
224
231
|
|
232
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chillout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Lomnicki
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2017-07-
|
14
|
+
date: 2017-07-07 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: multi_json
|
@@ -388,6 +388,7 @@ files:
|
|
388
388
|
- test/support/rails_4_1_16/app/controllers/entities_controller.rb
|
389
389
|
- test/support/rails_4_1_16/app/controllers/purchases_controller.rb
|
390
390
|
- test/support/rails_4_1_16/app/helpers/application_helper.rb
|
391
|
+
- test/support/rails_4_1_16/app/jobs/create_entity_job.rb
|
391
392
|
- test/support/rails_4_1_16/app/models/.keep
|
392
393
|
- test/support/rails_4_1_16/app/models/concerns/.keep
|
393
394
|
- test/support/rails_4_1_16/app/models/entity.rb
|
@@ -800,6 +801,7 @@ test_files:
|
|
800
801
|
- test/support/rails_4_1_16/app/controllers/entities_controller.rb
|
801
802
|
- test/support/rails_4_1_16/app/controllers/purchases_controller.rb
|
802
803
|
- test/support/rails_4_1_16/app/helpers/application_helper.rb
|
804
|
+
- test/support/rails_4_1_16/app/jobs/create_entity_job.rb
|
803
805
|
- test/support/rails_4_1_16/app/models/.keep
|
804
806
|
- test/support/rails_4_1_16/app/models/concerns/.keep
|
805
807
|
- test/support/rails_4_1_16/app/models/entity.rb
|