chillout 0.8.3 → 0.8.4

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: 8423a0fd777360d79146e8270eeb5536f6132e4f
4
- data.tar.gz: 1a2b4337e6ab9d2b62a13a111788f33b192d23a1
3
+ metadata.gz: 8308f094f935ed83592a06a45fe6b15dfc32fb7a
4
+ data.tar.gz: 2a23cac7e8d85f95ebf6f6fb5ba82cd531d3cc45
5
5
  SHA512:
6
- metadata.gz: 952cbad057b400710e7af9ed61e3f012476f673a3f5d6b4733b09f30d50a950517d42d1c24154a4c8cce1746a19cc63f623e23bdd2b7a54a5a5a594ce12a4d4f
7
- data.tar.gz: edde4d6c71087cc05108310b764aedc3bed7e10b390f87f49506b7a9698955b2c0ebad3c642d2d120de7f596dc46b2439a90a5344bf780b4c11b76937d3daab1
6
+ metadata.gz: b1d901f3d22ec457782f8376c30851b338779a2c3f63be2753213ecb111b215f4ed034084f78956db9411a80d6cb123bad0a0ada315da8dc66cf168085755fc9
7
+ data.tar.gz: 2848b76d928fa80ed56d8633b791744c5c5fe24d43c727570e5543b83c644aef0d3783daebc3ea612b5d1294108fd7159267fc8577f7133919994cc12e35b473
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # chillout gem changes
2
2
 
3
+ 0.8.4
4
+ -----
5
+
6
+ - Bugfix for [Custom metrics are not sent after 1st request](https://github.com/chilloutio/chillout/issues/4)
7
+
3
8
  0.8.3
4
9
  -----
5
10
 
data/lib/chillout.rb CHANGED
@@ -1,16 +1,21 @@
1
1
  require "chillout/version"
2
2
  require "chillout/config"
3
+ require "chillout/creations_container"
3
4
  require "chillout/middleware/creations_monitor"
4
5
  require "chillout/integrations/sidekiq"
5
6
  require "chillout/subscribers/action_controller_notifications"
6
7
  require "chillout/server_side/dispatcher"
7
8
  require "chillout/server_side/server_side"
8
9
  require "chillout/server_side/http_client"
9
- require "chillout/custom_metric"
10
10
  require "chillout/client"
11
11
 
12
12
  module Chillout
13
- Metric = CustomMetric.new
13
+ module Metric
14
+ def self.track(name)
15
+ Chillout.creations ||= CreationsContainer.new
16
+ Chillout.creations.increment!(name)
17
+ end
18
+ end
14
19
 
15
20
  def self.creations
16
21
  Thread.current[:creations]
@@ -21,5 +26,4 @@ module Chillout
21
26
  end
22
27
  end
23
28
 
24
- require 'chillout/railtie' if defined?(Rails)
25
-
29
+ require 'chillout/railtie' if defined?(Rails)
@@ -12,9 +12,8 @@ module Chillout
12
12
  class_name = monitored_class.name
13
13
  monitored_class.after_commit :on => :create do
14
14
  Rails.logger.debug "[Chillout] Model created: #{class_name}"
15
- Thread.current[:creations] ||= CreationsContainer.new
16
- creations = Thread.current[:creations]
17
- creations.increment!(class_name)
15
+ Chillout.creations ||= CreationsContainer.new
16
+ Chillout.creations.increment!(class_name)
18
17
  end
19
18
  end
20
19
  end
@@ -14,10 +14,10 @@ module Chillout
14
14
  status, headers, body = @app.call(env)
15
15
  return status, headers, body
16
16
  ensure
17
- if Thread.current[:creations]
17
+ if creations = Chillout.creations
18
18
  @client.logger.debug "Non-empty creations container found"
19
- @client.enqueue(Thread.current[:creations])
20
- Thread.current[:creations] = nil
19
+ @client.enqueue(creations)
20
+ Chillout.creations = nil
21
21
  end
22
22
 
23
23
  body.close if body && body.respond_to?(:close) && $!
@@ -9,8 +9,7 @@ module Chillout
9
9
  def call(_worker, _job, _queue)
10
10
  yield
11
11
  ensure
12
- if Chillout.creations
13
- creations = Chillout.creations
12
+ if creations = Chillout.creations
14
13
  Chillout.creations = nil
15
14
  @client.enqueue(creations)
16
15
  end
@@ -1,3 +1,3 @@
1
1
  module Chillout
2
- VERSION = "0.8.3"
2
+ VERSION = "0.8.4"
3
3
  end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class ChilloutModuleTest < ChilloutTestCase
4
+ def test_custom_metrics
5
+ Chillout::Metric.track('RegistrationCompleted')
6
+ assert_equal 1, Chillout.creations['RegistrationCompleted']
7
+ end
8
+ end
@@ -16,9 +16,9 @@ module Chillout
16
16
  def app
17
17
  client = @client
18
18
  deepest_level = lambda do |env|
19
- Thread.current[:creations] = CreationsContainer.new
20
- 2.times { Thread.current[:creations].increment!("User") }
21
- 3.times { Thread.current[:creations].increment!("Cart") }
19
+ Chillout.creations = CreationsContainer.new
20
+ Chillout.creations.increment!("User", 2)
21
+ Chillout.creations.increment!("Cart",3 )
22
22
  [200, env, ['hello']]
23
23
  end
24
24
  Rack::Builder.new do
@@ -11,7 +11,7 @@ module Chillout
11
11
 
12
12
  def call_with_model_creation
13
13
  @app = lambda do |env|
14
- Thread.current[:creations] = :creations
14
+ Chillout.creations = :creations
15
15
  [200, env, ['hello']]
16
16
  end
17
17
  @middleware = CreationsMonitor.new(@app, @client)
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.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Lomnicki
@@ -206,7 +206,6 @@ files:
206
206
  - lib/chillout/config.rb
207
207
  - lib/chillout/creation_listener.rb
208
208
  - lib/chillout/creations_container.rb
209
- - lib/chillout/custom_metric.rb
210
209
  - lib/chillout/generators/install.rb
211
210
  - lib/chillout/integrations/sidekiq.rb
212
211
  - lib/chillout/job.rb
@@ -228,10 +227,10 @@ files:
228
227
  - test/acceptance/client_sends_metrics_test.rb
229
228
  - test/acceptance/sidekiq_workers_send_metrics_test.rb
230
229
  - test/check_result_test.rb
230
+ - test/chillout_test.rb
231
231
  - test/client_test.rb
232
232
  - test/config_test.rb
233
233
  - test/creations_container_test.rb
234
- - test/custom_metric_test.rb
235
234
  - test/dispatcher_test.rb
236
235
  - test/http_client_test.rb
237
236
  - test/integration/client_test.rb
@@ -630,10 +629,10 @@ test_files:
630
629
  - test/acceptance/client_sends_metrics_test.rb
631
630
  - test/acceptance/sidekiq_workers_send_metrics_test.rb
632
631
  - test/check_result_test.rb
632
+ - test/chillout_test.rb
633
633
  - test/client_test.rb
634
634
  - test/config_test.rb
635
635
  - test/creations_container_test.rb
636
- - test/custom_metric_test.rb
637
636
  - test/dispatcher_test.rb
638
637
  - test/http_client_test.rb
639
638
  - test/integration/client_test.rb
@@ -1,27 +0,0 @@
1
- require 'chillout/creations_container'
2
-
3
- module Chillout
4
- class CustomMetric
5
- def initialize(creations_container = nil)
6
- @creations_container = creations_container
7
- end
8
-
9
- def track(name)
10
- creations_container.increment!(name)
11
- end
12
-
13
- private
14
- def creations_container
15
- if container_not_initialized?
16
- Thread.current[:creations] ||= CreationsContainer.new
17
- @creations_container = Thread.current[:creations]
18
- else
19
- @creations_container
20
- end
21
- end
22
-
23
- def container_not_initialized?
24
- @creations_container.nil?
25
- end
26
- end
27
- end
@@ -1,15 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CustomMetricTest < ChilloutTestCase
4
- def setup
5
- @creations_container = MiniTest::Mock.new
6
- end
7
-
8
- def test_custom_creation
9
- @creations_container.expect(:nil?, false, [])
10
- @creations_container.expect(:increment!, nil, ['foo'])
11
- @custom_metric = Chillout::CustomMetric.new(@creations_container)
12
- @custom_metric.track('foo')
13
- @creations_container.verify
14
- end
15
- end