chillout 0.8.7 → 0.8.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -0
- data/CHANGELOG.md +5 -0
- data/lib/chillout.rb +1 -0
- data/lib/chillout/integrations/state_machine.rb +90 -0
- data/lib/chillout/railtie.rb +15 -1
- data/lib/chillout/version.rb +1 -1
- data/test/acceptance/client_sends_state_machine_metrics_test.rb +45 -0
- data/test/support/rails_4_0_0/Gemfile +1 -0
- data/test/support/rails_4_0_0/app/controllers/entities_controller.rb +1 -1
- data/test/support/rails_4_0_0/app/controllers/transitions_controller.rb +8 -0
- data/test/support/rails_4_0_0/app/models/entity.rb +35 -1
- data/test/support/rails_4_0_0/config/routes.rb +1 -0
- data/test/support/rails_4_0_0/db/schema.rb +2 -0
- data/test/support/rails_4_0_13/Gemfile +1 -0
- data/test/support/rails_4_0_13/app/controllers/entities_controller.rb +1 -1
- data/test/support/rails_4_0_13/app/controllers/transitions_controller.rb +8 -0
- data/test/support/rails_4_0_13/app/models/entity.rb +35 -1
- data/test/support/rails_4_0_13/config/routes.rb +1 -0
- data/test/support/rails_4_0_13/db/schema.rb +2 -0
- data/test/support/rails_4_1_0/Gemfile +1 -0
- data/test/support/rails_4_1_0/app/controllers/entities_controller.rb +1 -1
- data/test/support/rails_4_1_0/app/controllers/transitions_controller.rb +8 -0
- data/test/support/rails_4_1_0/app/models/entity.rb +35 -1
- data/test/support/rails_4_1_0/config/initializers/state_machine_integration_hack.rb +3 -0
- data/test/support/rails_4_1_0/config/routes.rb +1 -0
- data/test/support/rails_4_1_0/db/schema.rb +2 -0
- data/test/support/rails_4_1_16/Gemfile +2 -1
- data/test/support/rails_4_1_16/app/controllers/entities_controller.rb +1 -1
- data/test/support/rails_4_1_16/app/controllers/transitions_controller.rb +8 -0
- data/test/support/rails_4_1_16/app/jobs/create_entity_job.rb +1 -1
- data/test/support/rails_4_1_16/app/models/entity.rb +35 -1
- data/test/support/rails_4_1_16/config/initializers/state_machine_integration_hack.rb +3 -0
- data/test/support/rails_4_1_16/config/routes.rb +1 -0
- data/test/support/rails_4_1_16/db/schema.rb +2 -0
- data/test/support/rails_4_2_0/Gemfile +2 -1
- data/test/support/rails_4_2_0/app/controllers/entities_controller.rb +1 -1
- data/test/support/rails_4_2_0/app/controllers/transitions_controller.rb +8 -0
- data/test/support/rails_4_2_0/app/jobs/create_entity_job.rb +1 -1
- data/test/support/rails_4_2_0/app/models/entity.rb +35 -1
- data/test/support/rails_4_2_0/config/initializers/state_machine_integration_hack.rb +3 -0
- data/test/support/rails_4_2_0/config/routes.rb +1 -0
- data/test/support/rails_4_2_0/db/schema.rb +2 -0
- data/test/support/rails_4_2_8/Gemfile +7 -1
- data/test/support/rails_4_2_8/app/controllers/entities_controller.rb +1 -1
- data/test/support/rails_4_2_8/app/controllers/transitions_controller.rb +8 -0
- data/test/support/rails_4_2_8/app/jobs/create_entity_job.rb +1 -1
- data/test/support/rails_4_2_8/app/models/entity.rb +35 -1
- data/test/support/rails_4_2_8/config/initializers/state_machine_integration_hack.rb +3 -0
- data/test/support/rails_4_2_8/config/routes.rb +1 -0
- data/test/support/rails_4_2_8/db/schema.rb +2 -0
- data/test/support/rails_5_0_3/Gemfile +7 -1
- data/test/support/rails_5_0_3/app/controllers/entities_controller.rb +1 -1
- data/test/support/rails_5_0_3/app/controllers/transitions_controller.rb +8 -0
- data/test/support/rails_5_0_3/app/jobs/create_entity_job.rb +1 -1
- data/test/support/rails_5_0_3/app/models/entity.rb +35 -1
- data/test/support/rails_5_0_3/config/initializers/state_machine_integration_hack.rb +3 -0
- data/test/support/rails_5_0_3/config/routes.rb +1 -0
- data/test/support/rails_5_0_3/db/schema.rb +2 -0
- data/test/support/rails_5_1_1/Gemfile +6 -0
- data/test/support/rails_5_1_1/app/controllers/entities_controller.rb +1 -1
- data/test/support/rails_5_1_1/app/controllers/transitions_controller.rb +8 -0
- data/test/support/rails_5_1_1/app/jobs/create_entity_job.rb +1 -1
- data/test/support/rails_5_1_1/app/models/application_record.rb +3 -0
- data/test/support/rails_5_1_1/app/models/entity.rb +35 -1
- data/test/support/rails_5_1_1/app/models/user.rb +2 -0
- data/test/support/rails_5_1_1/config/routes.rb +2 -1
- data/test/support/rails_5_1_1/db/schema.rb +2 -0
- data/test/test_helper.rb +19 -3
- metadata +36 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 146543514bd9a57101ff6edfa2e7f4b9230c6b32
|
4
|
+
data.tar.gz: 8d99f8a62af72773cbe7344ccef119a435b066a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61bc007ffd4972c0a1d6bbd38288e326e40f4a11609be28e9454438a4cae84e51d9c3a52245f8a8f703e8fca510033fefb62226d63432fc6967c70c43c256f32
|
7
|
+
data.tar.gz: d7d9a20333b07c7a11139609060ef23669602615859a94e6c452d74e3ab14d978122dd7c878dc9103cbdfbe265e2ef12d3a174c25d7a222622d67d005e38c245
|
data/.travis.yml
CHANGED
@@ -44,6 +44,14 @@ matrix:
|
|
44
44
|
env: SAMPLE_APP=rails_5_0_3 STRATEGY=active_job SIDEKIQ_SUPPORTED=true
|
45
45
|
- rvm: 2.4.1
|
46
46
|
env: SAMPLE_APP=rails_5_1_1 STRATEGY=active_job SIDEKIQ_SUPPORTED=true
|
47
|
+
- rvm: 2.3.4
|
48
|
+
env: SAMPLE_APP=rails_4_0_0 STATE_MACHINE_VERSION=1.1.2
|
49
|
+
- rvm: 2.4.1
|
50
|
+
env: SAMPLE_APP=rails_5_1_1 STATE_MACHINES_ACTIVERECORD_VERSION=">=0.5"
|
51
|
+
- rvm: 2.4.1
|
52
|
+
env: SAMPLE_APP=rails_5_0_3 STATE_MACHINES_ACTIVERECORD_VERSION=0.4
|
53
|
+
- rvm: 2.4.1
|
54
|
+
env: SAMPLE_APP=rails_4_2_8 STATE_MACHINES_ACTIVERECORD_VERSION=0.3 STATE_MACHINES_VERSION=0.4
|
47
55
|
notifications:
|
48
56
|
slack:
|
49
57
|
secure: 6IAlvKplFv94Vaf0LES197FFIgt5cs1fUFA9820mmeoTGLDQcN+4Hpv+2/NRRqrfb2k+V+uFKmsuY8azHBoKHLIzH6d1T0NS82j54Ti+tm0iFZaKLHVp8TxuIge0/e0Niamod5mMziLTg6KcM+zNBYcoxS3th1mQNWQ2mtD9JZ8=
|
data/CHANGELOG.md
CHANGED
data/lib/chillout.rb
CHANGED
@@ -4,6 +4,7 @@ require "chillout/creations_container"
|
|
4
4
|
require "chillout/custom_advanced_metric"
|
5
5
|
require "chillout/middleware/creations_monitor"
|
6
6
|
require "chillout/integrations/sidekiq"
|
7
|
+
require "chillout/integrations/state_machine"
|
7
8
|
require "chillout/subscribers/action_controller_notifications"
|
8
9
|
require "chillout/server_side/dispatcher"
|
9
10
|
require "chillout/server_side/server_side"
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Chillout
|
2
|
+
module Integrations
|
3
|
+
|
4
|
+
class StateMachineTransitionMeasurement
|
5
|
+
|
6
|
+
def initialize(instance, transition, started, finished)
|
7
|
+
@class = instance.class.name
|
8
|
+
|
9
|
+
@attribute = transition.attribute.to_s
|
10
|
+
@event = transition.event.to_s
|
11
|
+
@from = transition.from.to_s
|
12
|
+
@to = transition.to.to_s
|
13
|
+
|
14
|
+
@started = started.utc
|
15
|
+
@finished = finished.utc
|
16
|
+
@duration = 1000.0 * (@finished.to_f - @started.to_f)
|
17
|
+
end
|
18
|
+
|
19
|
+
def job_class
|
20
|
+
@class
|
21
|
+
end
|
22
|
+
|
23
|
+
def as_measurements()
|
24
|
+
[{
|
25
|
+
series: "#{@class}##{@attribute}",
|
26
|
+
tags: {
|
27
|
+
class: @class,
|
28
|
+
attribute: @attribute,
|
29
|
+
event: @event,
|
30
|
+
from: @from,
|
31
|
+
to: @to,
|
32
|
+
},
|
33
|
+
timestamp: @finished.iso8601,
|
34
|
+
values: {
|
35
|
+
value: 1,
|
36
|
+
duration: @duration.to_f,
|
37
|
+
},
|
38
|
+
}]
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
class StateMachine
|
44
|
+
|
45
|
+
def available?
|
46
|
+
if defined?(::StateMachines::Integrations::ActiveRecord::VERSION) && defined?(::ActiveRecord)
|
47
|
+
return Gem::Version.new(::StateMachines::Integrations::ActiveRecord::VERSION) >= Gem::Version.new('0.3.0')
|
48
|
+
end
|
49
|
+
if defined?(::StateMachine) && defined?(::ActiveRecord)
|
50
|
+
require 'state_machine/version'
|
51
|
+
return Gem::Version.new(::StateMachine::VERSION) >= Gem::Version.new('1.1.2')
|
52
|
+
end
|
53
|
+
rescue
|
54
|
+
false
|
55
|
+
end
|
56
|
+
|
57
|
+
def enable(client)
|
58
|
+
callback_class = defined?(::StateMachine::Callback) ? ::StateMachine::Callback : ::StateMachines::Callback
|
59
|
+
ActiveRecord::Base.subclasses.select do |klass|
|
60
|
+
klass.respond_to?(:state_machines)
|
61
|
+
end.each do |klass|
|
62
|
+
klass.state_machines.each_value do |state_machine|
|
63
|
+
state_machine.callbacks[:before].unshift(
|
64
|
+
callback_class.new(:around, &callback(client))
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def callback(client)
|
73
|
+
Proc.new do |instance, transition, block|
|
74
|
+
started = Time.now.utc
|
75
|
+
block.call
|
76
|
+
finished = Time.now.utc
|
77
|
+
client.enqueue(StateMachineTransitionMeasurement.new(
|
78
|
+
instance,
|
79
|
+
transition,
|
80
|
+
started,
|
81
|
+
finished,
|
82
|
+
))
|
83
|
+
true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
data/lib/chillout/railtie.rb
CHANGED
@@ -4,15 +4,24 @@ require 'chillout/listener_injector'
|
|
4
4
|
module Chillout
|
5
5
|
class Railtie < Rails::Railtie
|
6
6
|
config.chillout = ActiveSupport::OrderedOptions.new
|
7
|
+
chillout_init = nil
|
8
|
+
|
7
9
|
initializer "chillout.creations_listener_initialization" do |rails_app|
|
8
10
|
chillout_config = rails_app.config.chillout
|
9
11
|
if chillout_config.present?
|
10
|
-
RailsInitializer.new(rails_app, chillout_config, Rails.logger)
|
12
|
+
chillout_init = RailsInitializer.new(rails_app, chillout_config, Rails.logger)
|
13
|
+
chillout_init.start
|
11
14
|
else
|
12
15
|
Rails.logger.debug "[Chillout] Not enabled for #{Rails.env}"
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
19
|
+
initializer "chillout.after_eager_load", after: :eager_load! do
|
20
|
+
if chillout_init
|
21
|
+
chillout_init.after_eager_load
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
16
25
|
rake_tasks do
|
17
26
|
load "chillout/tasks.rb"
|
18
27
|
end
|
@@ -53,6 +62,11 @@ module Chillout
|
|
53
62
|
Chillout.client = client
|
54
63
|
end
|
55
64
|
|
65
|
+
def after_eager_load
|
66
|
+
state_machine = Integrations::StateMachine.new
|
67
|
+
state_machine.enable(Chillout.client) if state_machine.available?
|
68
|
+
end
|
69
|
+
|
56
70
|
private
|
57
71
|
|
58
72
|
def options
|
data/lib/chillout/version.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ClientSendsStateMachineMetrics < AcceptanceTestCase
|
4
|
+
|
5
|
+
def test_client_sends_state_machine_metrics
|
6
|
+
test_app = TestApp.new
|
7
|
+
test_endpoint = TestEndpoint.new(port: 8085)
|
8
|
+
test_user = TestUser.new
|
9
|
+
|
10
|
+
test_endpoint.listen
|
11
|
+
test_app.boot(chillout_port: 8085)
|
12
|
+
if ENV['STRATEGY'] != 'active_job'
|
13
|
+
assert test_endpoint.has_received_information_about_startup
|
14
|
+
end
|
15
|
+
test_user.transition_entity('Yay')
|
16
|
+
assert transition = test_endpoint.has_one_state_machine_metric
|
17
|
+
|
18
|
+
assert_equal "Entity#state", transition["series"]
|
19
|
+
assert_equal "Entity", transition["tags"]["class"]
|
20
|
+
assert_equal "state", transition["tags"]["attribute"]
|
21
|
+
assert_equal "ignite", transition["tags"]["event"]
|
22
|
+
assert_equal "parked", transition["tags"]["from"]
|
23
|
+
assert_equal "idling", transition["tags"]["to"]
|
24
|
+
|
25
|
+
assert_equal 1, transition["values"]["value"]
|
26
|
+
assert_operator 100, :<, transition["values"]["duration"]
|
27
|
+
assert_operator 600, :>, transition["values"]["duration"]
|
28
|
+
|
29
|
+
assert transition = test_endpoint.has_one_state_machine_metric
|
30
|
+
|
31
|
+
assert_equal "Entity#state", transition["series"]
|
32
|
+
assert_equal "Entity", transition["tags"]["class"]
|
33
|
+
assert_equal "state", transition["tags"]["attribute"]
|
34
|
+
assert_equal "shift_up", transition["tags"]["event"]
|
35
|
+
assert_equal "idling", transition["tags"]["from"]
|
36
|
+
assert_equal "first_gear", transition["tags"]["to"]
|
37
|
+
|
38
|
+
assert_equal 1, transition["values"]["value"]
|
39
|
+
assert_operator 0, :<, transition["values"]["duration"]
|
40
|
+
assert_operator 200, :>, transition["values"]["duration"]
|
41
|
+
ensure
|
42
|
+
test_app.shutdown if test_app
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -1,2 +1,36 @@
|
|
1
1
|
class Entity < ActiveRecord::Base
|
2
|
-
|
2
|
+
state_machine :initial => :parked do
|
3
|
+
before_transition :parked => any - :parked, do: :put_on_seatbelt
|
4
|
+
after_transition any => :parked do |vehicle, _transition|
|
5
|
+
vehicle.seatbelt = 'off'
|
6
|
+
end
|
7
|
+
around_transition :benchmark
|
8
|
+
|
9
|
+
event :ignite do
|
10
|
+
transition :parked => :idling
|
11
|
+
end
|
12
|
+
|
13
|
+
event :shift_up do
|
14
|
+
transition :idling => :first_gear,
|
15
|
+
:first_gear => :second_gear,
|
16
|
+
:second_gear => :third_gear
|
17
|
+
end
|
18
|
+
|
19
|
+
state :first_gear, :second_gear do
|
20
|
+
validates_presence_of :seatbelt_on
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def put_on_seatbelt
|
25
|
+
sleep(0.1)
|
26
|
+
self.seatbelt = 'on'
|
27
|
+
end
|
28
|
+
|
29
|
+
def benchmark
|
30
|
+
yield
|
31
|
+
end
|
32
|
+
|
33
|
+
def seatbelt_on
|
34
|
+
self.seatbelt == 'on'
|
35
|
+
end
|
36
|
+
end
|
@@ -15,6 +15,8 @@ ActiveRecord::Schema.define(:version => 20130103115400) do
|
|
15
15
|
|
16
16
|
create_table "entities", :force => true do |t|
|
17
17
|
t.string "name"
|
18
|
+
t.string "state"
|
19
|
+
t.string "seatbelt"
|
18
20
|
t.datetime "created_at", :null => false
|
19
21
|
t.datetime "updated_at", :null => false
|
20
22
|
end
|
@@ -1,2 +1,36 @@
|
|
1
1
|
class Entity < ActiveRecord::Base
|
2
|
-
|
2
|
+
state_machine :initial => :parked do
|
3
|
+
before_transition :parked => any - :parked, do: :put_on_seatbelt
|
4
|
+
after_transition any => :parked do |vehicle, _transition|
|
5
|
+
vehicle.seatbelt = 'off'
|
6
|
+
end
|
7
|
+
around_transition :benchmark
|
8
|
+
|
9
|
+
event :ignite do
|
10
|
+
transition :parked => :idling
|
11
|
+
end
|
12
|
+
|
13
|
+
event :shift_up do
|
14
|
+
transition :idling => :first_gear,
|
15
|
+
:first_gear => :second_gear,
|
16
|
+
:second_gear => :third_gear
|
17
|
+
end
|
18
|
+
|
19
|
+
state :first_gear, :second_gear do
|
20
|
+
validates_presence_of :seatbelt_on
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def put_on_seatbelt
|
25
|
+
sleep(0.1)
|
26
|
+
self.seatbelt = 'on'
|
27
|
+
end
|
28
|
+
|
29
|
+
def benchmark
|
30
|
+
yield
|
31
|
+
end
|
32
|
+
|
33
|
+
def seatbelt_on
|
34
|
+
self.seatbelt == 'on'
|
35
|
+
end
|
36
|
+
end
|
@@ -15,6 +15,8 @@ ActiveRecord::Schema.define(:version => 20130103115400) do
|
|
15
15
|
|
16
16
|
create_table "entities", :force => true do |t|
|
17
17
|
t.string "name"
|
18
|
+
t.string "state"
|
19
|
+
t.string "seatbelt"
|
18
20
|
t.datetime "created_at", :null => false
|
19
21
|
t.datetime "updated_at", :null => false
|
20
22
|
end
|
@@ -1,2 +1,36 @@
|
|
1
1
|
class Entity < ActiveRecord::Base
|
2
|
-
|
2
|
+
state_machine :initial => :parked do
|
3
|
+
before_transition :parked => any - :parked, do: :put_on_seatbelt
|
4
|
+
after_transition any => :parked do |vehicle, _transition|
|
5
|
+
vehicle.seatbelt = 'off'
|
6
|
+
end
|
7
|
+
around_transition :benchmark
|
8
|
+
|
9
|
+
event :ignite do
|
10
|
+
transition :parked => :idling
|
11
|
+
end
|
12
|
+
|
13
|
+
event :shift_up do
|
14
|
+
transition :idling => :first_gear,
|
15
|
+
:first_gear => :second_gear,
|
16
|
+
:second_gear => :third_gear
|
17
|
+
end
|
18
|
+
|
19
|
+
state :first_gear, :second_gear do
|
20
|
+
validates_presence_of :seatbelt_on
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def put_on_seatbelt
|
25
|
+
sleep(0.1)
|
26
|
+
self.seatbelt = 'on'
|
27
|
+
end
|
28
|
+
|
29
|
+
def benchmark
|
30
|
+
yield
|
31
|
+
end
|
32
|
+
|
33
|
+
def seatbelt_on
|
34
|
+
self.seatbelt == 'on'
|
35
|
+
end
|
36
|
+
end
|