yabeda 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84d57c72434b9d26ac68f5244de32338f90203c73f8c488541ea3e284ca763bf
4
- data.tar.gz: c06c5b0475a260a15962c98d89346fa894eebad8200e728234814686cedbee48
3
+ metadata.gz: 30e7d6e3fee4aac1922285af3fe9abc61cbfedff88ec2c2b95f70478383c02df
4
+ data.tar.gz: b5ff1691c1c692672b3d03fd46fc13f299d8851f61d3a65e1571389787b8b050
5
5
  SHA512:
6
- metadata.gz: ce0c24fc3f77ae77295b9b0746cc4885743a60bb9d02ce092f71beaf4493cf9bf135703ebfbb39d44c990aa2409c4e423fe99aeeebb6ac1f0cec2f0b5279496e
7
- data.tar.gz: 3f709b4c288ccf9fed8ddf9f890de3182c427cfe3837e3bb47cc70eec350a754ee19736fd788eaa6b7ed3a9f785160301d597eff5347fa4506667ae16c4027d2
6
+ metadata.gz: 0b0872f973fe39a30be8c3c74f91e7c472aa246f7be08ed0d719c605b9ab42c7625b47c294dec04a15f82b4cc90984953b5658cc8041c51776ce3bb3ea70a1a9
7
+ data.tar.gz: 6ae9978212486a4deeefbb173cc7c103f5fa3a3f64db4c5ec21188a9a38aa94af39c741b900970ab5649d5ced0bf5979acd65bd531fdfa7b577640d85e7ab531
data/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 0.4.0 - 2020-01-28
9
+
10
+ ### Changed
11
+
12
+ - Configuration of gem was changed from synchronous (at the moment when `configure` block was executed) to postponed (only on `configure!` method call). [@Envek]
13
+
14
+ This should allow to fix problems when metrics from gems are registered too early, before required changes to the monitoring system clients.
15
+
8
16
  ## 0.3.0 - 2020-01-15
9
17
 
10
18
  ### Added
@@ -41,4 +49,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
41
49
 
42
50
  - Initial release of evil-metrics gem. @Envek
43
51
 
52
+ [@Envek]: https://github.com/Envek "Andrey Novikov"
44
53
  [@asusikov]: https://github.com/asusikov "Alexander Susikov"
data/README.md CHANGED
@@ -43,7 +43,15 @@ And then execute:
43
43
  end
44
44
  ```
45
45
 
46
- 2. Access metric in your app and use it!
46
+ 2. After your application was initialized and all metrics was declared, you need to apply Yabeda configuration:
47
+
48
+ ```ruby
49
+ Yabeda.configure!
50
+ ```
51
+
52
+ _But [yabeda-rails] will do this for you automatically._
53
+
54
+ 3. Access metric in your app and use it!
47
55
 
48
56
  ```ruby
49
57
  def ring_the_bell(id)
@@ -59,7 +67,7 @@ And then execute:
59
67
  end
60
68
  ```
61
69
 
62
- 3. Setup collecting of metrics that do not tied to specific events in you application. E.g.: reporting your app's current state
70
+ 4. Setup collecting of metrics that do not tied to specific events in you application. E.g.: reporting your app's current state
63
71
  ```ruby
64
72
  Yabeda.configure do
65
73
  # This block will be executed periodically few times in a minute
@@ -71,15 +79,15 @@ And then execute:
71
79
  end
72
80
  ```
73
81
 
74
- 4. _Optionally_ setup default tags that will be added to all metrics
82
+ 5. _Optionally_ setup default tags that will be added to all metrics
75
83
  ```ruby
76
84
  Yabeda.configure do
77
85
  default_tag :rails_environment, 'production'
78
86
  end
79
87
  ```
80
88
 
81
- 5. See the docs for the adapter you're using
82
- 6. Enjoy!
89
+ 6. See the docs for the adapter you're using
90
+ 7. Enjoy!
83
91
 
84
92
  ## Roadmap (aka TODO or Help wanted)
85
93
 
@@ -116,3 +124,5 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/yabeda
116
124
  ## License
117
125
 
118
126
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
127
+
128
+ [yabeda-rails]: https://github.com/yabeda-rb/yabeda-rails/ "Yabeda plugin for collecting and exporting basic metrics for Rails applications"
data/lib/yabeda.rb CHANGED
@@ -5,6 +5,7 @@ require "concurrent"
5
5
  require "yabeda/version"
6
6
  require "yabeda/dsl"
7
7
  require "yabeda/tags"
8
+ require "yabeda/errors"
8
9
 
9
10
  # Extendable framework for collecting and exporting metrics from Ruby apps
10
11
  module Yabeda
@@ -45,5 +46,43 @@ module Yabeda
45
46
  instance.register!(metric)
46
47
  end
47
48
  end
49
+
50
+ # @return [Array<Proc>] All configuration blocks for postponed setup
51
+ def configurators
52
+ @configurators ||= Concurrent::Array.new
53
+ end
54
+
55
+ # @return [Boolean] Whether +Yabeda.configure!+ has been already called
56
+ def configured?
57
+ !@configured_by.nil?
58
+ end
59
+ alias already_configured? configured?
60
+
61
+ # Perform configuration: registration of metrics and collector blocks
62
+ # @return [void]
63
+ def configure!
64
+ raise(AlreadyConfiguredError, @configured_by) if already_configured?
65
+
66
+ configurators.each do |(group, block)|
67
+ group group
68
+ class_eval(&block)
69
+ group nil
70
+ end
71
+
72
+ @configured_by = caller_locations(1, 1)[0].to_s
73
+ end
74
+
75
+ # Forget all the configuration.
76
+ # For testing purposes as it doesn't rollback changes in adapters.
77
+ # @api private
78
+ def reset!
79
+ default_tags.clear
80
+ adapters.clear
81
+ groups.clear
82
+ metrics.clear
83
+ collectors.clear
84
+ configurators.clear
85
+ instance_variable_set(:@configured_by, nil)
86
+ end
48
87
  end
49
88
  end
@@ -14,7 +14,8 @@ module Yabeda
14
14
  module ClassMethods
15
15
  # Block for grouping and simplifying configuration of related metrics
16
16
  def configure(&block)
17
- class_exec(&block)
17
+ Yabeda.configurators.push([@group, block])
18
+ class_exec(&block) if Yabeda.configured?
18
19
  @group = nil
19
20
  end
20
21
 
@@ -3,8 +3,6 @@
3
3
  require "yabeda/dsl/option_builder"
4
4
 
5
5
  module Yabeda
6
- class ConfigurationError < StandardError; end
7
-
8
6
  module DSL
9
7
  # Handles DSL for working with individual metrics
10
8
  class MetricBuilder
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yabeda
4
+ class ConfigurationError < StandardError; end
5
+
6
+ # Raises on repeated call to +Yabeda.configure!+
7
+ class AlreadyConfiguredError < StandardError
8
+ def initialize(configuring_location)
9
+ super
10
+ @message = "Yabeda was already configured in #{configuring_location}"
11
+ end
12
+
13
+ attr_reader :message
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yabeda
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yabeda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Novikov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-15 00:00:00.000000000 Z
11
+ date: 2020-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -137,6 +137,7 @@ files:
137
137
  - lib/yabeda/dsl/class_methods.rb
138
138
  - lib/yabeda/dsl/metric_builder.rb
139
139
  - lib/yabeda/dsl/option_builder.rb
140
+ - lib/yabeda/errors.rb
140
141
  - lib/yabeda/gauge.rb
141
142
  - lib/yabeda/group.rb
142
143
  - lib/yabeda/histogram.rb