yabeda 0.3.0 → 0.6.2

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
  SHA256:
3
- metadata.gz: 84d57c72434b9d26ac68f5244de32338f90203c73f8c488541ea3e284ca763bf
4
- data.tar.gz: c06c5b0475a260a15962c98d89346fa894eebad8200e728234814686cedbee48
3
+ metadata.gz: fbc7c44d3d257c23cdbce5b423db52c4f2591c21737d939d9dce8df53c557f04
4
+ data.tar.gz: 9c68a889b0f978a4471b0458e4d48903ab019ae7dfc6948b55cb5a5147060127
5
5
  SHA512:
6
- metadata.gz: ce0c24fc3f77ae77295b9b0746cc4885743a60bb9d02ce092f71beaf4493cf9bf135703ebfbb39d44c990aa2409c4e423fe99aeeebb6ac1f0cec2f0b5279496e
7
- data.tar.gz: 3f709b4c288ccf9fed8ddf9f890de3182c427cfe3837e3bb47cc70eec350a754ee19736fd788eaa6b7ed3a9f785160301d597eff5347fa4506667ae16c4027d2
6
+ metadata.gz: 2cd9007fda7bd41d90a20238ac81dd4d2efe46e39f5473e7e0c318f5efb984f6b3e0843a06fb5c325514f0e4282fae98b2fcfc9f9920bdfbccfca946de32b910
7
+ data.tar.gz: 0d429f2971ff62ec68d36bedf089ef5f203a8c63cabaddd917704529d6aaf307999ac3d2716207abb9c37be23e42d5dcdc3115d5a6eb8551eb23ef940aefb80d
@@ -10,12 +10,9 @@ Metrics/BlockLength:
10
10
  - "Gemfile"
11
11
  - "spec/**/*"
12
12
 
13
- Metrics/LineLength:
13
+ Layout/LineLength:
14
14
  Max: 120
15
15
 
16
- Style/BracesAroundHashParameters:
17
- EnforcedStyle: context_dependent
18
-
19
16
  Style/StringLiterals:
20
17
  EnforcedStyle: double_quotes
21
18
 
@@ -47,3 +44,11 @@ Style/TrailingCommaInHashLiteral:
47
44
  Enabled: true
48
45
  EnforcedStyleForMultiline: consistent_comma
49
46
 
47
+ Style/HashEachMethods:
48
+ Enabled: true
49
+
50
+ Style/HashTransformKeys:
51
+ Enabled: true
52
+
53
+ Style/HashTransformValues:
54
+ Enabled: true
@@ -1,5 +1,4 @@
1
1
  ---
2
- sudo: false
3
2
  language: ruby
4
3
  cache: bundler
5
4
  rvm:
@@ -5,6 +5,44 @@ 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.6.2 - 2020-08-04
9
+
10
+ ### Fixed
11
+
12
+ - Compatibility with plugins (like [yabeda-puma-plugin](https://github.com/yabeda-rb/yabeda-puma-plugin)) that for some reason configures itself after Yabeda configuration was already applied by `Yabeda.configure!` (was broken in 0.6.0). [@Envek]
13
+
14
+ ## 0.6.1 - 2020-07-16
15
+
16
+ ### Fixed
17
+
18
+ - Compatibility with Ruby < 2.6 due to usage of [new `Hash#merge(*others)` with multiple arguments](https://rubyreferences.github.io/rubychanges/2.6.html#hashmerge-with-multiple-arguments) in 0.6.0. [@Envek]
19
+
20
+ ## 0.6.0 - 2020-07-15
21
+
22
+ ### Added
23
+
24
+ - `Yabeda.with_tags` to redefine default tags for limited amount of time–for all metrics measured during a block execution. [@Envek]
25
+
26
+ ### Fixed
27
+
28
+ - Default tags were not sent to adapters for metrics declared before `default_tag` declaration. [@Envek]
29
+
30
+ ## 0.5.0 - 2020-01-29
31
+
32
+ ### Added
33
+
34
+ - Ability to specify aggregation policy for metrics collected from multiple process and exposed via single endpoint. [@Envek]
35
+
36
+ For now it is only used by yabeda-prometheus when official Prometheus client is configured to use file storage for metrics.
37
+
38
+ ## 0.4.0 - 2020-01-28
39
+
40
+ ### Changed
41
+
42
+ - Configuration of gem was changed from synchronous (at the moment when `configure` block was executed) to postponed (only on `configure!` method call). [@Envek]
43
+
44
+ This should allow to fix problems when metrics from gems are registered too early, before required changes to the monitoring system clients.
45
+
8
46
  ## 0.3.0 - 2020-01-15
9
47
 
10
48
  ### Added
@@ -41,4 +79,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
41
79
 
42
80
  - Initial release of evil-metrics gem. @Envek
43
81
 
82
+ [@Envek]: https://github.com/Envek "Andrey Novikov"
44
83
  [@asusikov]: https://github.com/asusikov "Alexander Susikov"
data/Gemfile CHANGED
@@ -11,6 +11,6 @@ group :development, :test do
11
11
  gem "pry"
12
12
  gem "pry-byebug", platform: :mri
13
13
 
14
- gem "rubocop"
14
+ gem "rubocop", "~> 0.80.0"
15
15
  gem "rubocop-rspec"
16
16
  end
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,28 @@ 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
87
+
88
+ # You can redefine them for limited amount of time
89
+ Yabeda.with_tags(rails_environment: 'staging') do
90
+ Yabeda.your_app.bells_rang_count.increment({bell_size: bell.size}, by: 1)
91
+ end
79
92
  ```
80
93
 
81
- 5. See the docs for the adapter you're using
82
- 6. Enjoy!
94
+ 6. See the docs for the adapter you're using
95
+ 7. Enjoy!
96
+
97
+ ## Available monitoring system adapters
98
+
99
+ - [Prometheus](https://github.com/yabeda-rb/yabeda-prometheus)
100
+ - [Datadog](https://github.com/yabeda-rb/yabeda-datadog)
101
+ - [NewRelic](https://github.com/yabeda-rb/yabeda-newrelic)
102
+ - [Statsd](https://github.com/asusikov/yabeda-statsd)
103
+ - _…and more! You can write your own adapter and open a pull request to add it into this list._
83
104
 
84
105
  ## Roadmap (aka TODO or Help wanted)
85
106
 
@@ -116,3 +137,5 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/yabeda
116
137
  ## License
117
138
 
118
139
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
140
+
141
+ [yabeda-rails]: https://github.com/yabeda-rb/yabeda-rails/ "Yabeda plugin for collecting and exporting basic metrics for Rails applications"
@@ -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,53 @@ 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
+ # rubocop: disable Metrics/MethodLength, Metrics/AbcSize
64
+ def configure!
65
+ raise(AlreadyConfiguredError, @configured_by) if already_configured?
66
+
67
+ configurators.each do |(group, block)|
68
+ group group
69
+ class_eval(&block)
70
+ group nil
71
+ end
72
+
73
+ # Register metrics in adapters after evaluating all configuration blocks
74
+ # to ensure that all global settings (like default tags) will be applied.
75
+ adapters.each_value do |adapter|
76
+ metrics.each_value do |metric|
77
+ adapter.register!(metric)
78
+ end
79
+ end
80
+
81
+ @configured_by = caller_locations(1, 1)[0].to_s
82
+ end
83
+ # rubocop: enable Metrics/MethodLength, Metrics/AbcSize
84
+
85
+ # Forget all the configuration.
86
+ # For testing purposes as it doesn't rollback changes in adapters.
87
+ # @api private
88
+ def reset!
89
+ default_tags.clear
90
+ adapters.clear
91
+ groups.clear
92
+ metrics.clear
93
+ collectors.clear
94
+ configurators.clear
95
+ instance_variable_set(:@configured_by, nil)
96
+ end
48
97
  end
49
98
  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
 
@@ -61,14 +62,30 @@ module Yabeda
61
62
  ::Yabeda.default_tags[name] = value
62
63
  end
63
64
 
65
+ # Redefine default tags for a limited amount of time
66
+ # @param tags Hash{Symbol=>#to_s}
67
+ def with_tags(**tags)
68
+ Thread.current[:yabeda_temporary_tags] = tags
69
+ yield
70
+ ensure
71
+ Thread.current[:yabeda_temporary_tags] = {}
72
+ end
73
+
74
+ # Get tags set by +with_tags+
75
+ # @api private
76
+ # @return Hash
77
+ def temporary_tags
78
+ Thread.current[:yabeda_temporary_tags] || {}
79
+ end
80
+
64
81
  private
65
82
 
66
83
  def register_metric(metric)
67
84
  name = [metric.group, metric.name].compact.join("_")
68
85
  ::Yabeda.define_singleton_method(name) { metric }
69
86
  ::Yabeda.metrics[name] = metric
70
- ::Yabeda.adapters.each_value { |adapter| adapter.register!(metric) }
71
87
  register_group_for(metric) if metric.group
88
+ ::Yabeda.adapters.each_value { |adapter| adapter.register!(metric) } if ::Yabeda.configured?
72
89
  metric
73
90
  end
74
91
 
@@ -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
@@ -13,6 +13,7 @@ module Yabeda
13
13
  option :unit, optional: true, comment: "In which units it is measured. E.g. `seconds`"
14
14
  option :per, optional: true, comment: "Per which unit is measured `unit`. E.g. `call` as in seconds per call"
15
15
  option :group, optional: true, comment: "Category name for grouping metrics"
16
+ option :aggregation, optional: true, comment: "How adapters should aggregate values from different processes"
16
17
 
17
18
  # Returns the value for the given label set
18
19
  def get(labels = {})
@@ -4,7 +4,7 @@ module Yabeda
4
4
  # Class to merge tags
5
5
  class Tags
6
6
  def self.build(tags)
7
- ::Yabeda.default_tags.merge(tags)
7
+ ::Yabeda.default_tags.merge(Yabeda.temporary_tags).merge(tags)
8
8
  end
9
9
  end
10
10
  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.6.2"
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.6.2
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-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -111,7 +111,7 @@ dependencies:
111
111
  description: 'Collect statistics about how your application is performing with ease.
112
112
  Export metrics to various monitoring systems.
113
113
 
114
- '
114
+ '
115
115
  email:
116
116
  - envek@envek.name
117
117
  executables: []
@@ -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
@@ -163,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
164
  - !ruby/object:Gem::Version
164
165
  version: '0'
165
166
  requirements: []
166
- rubygems_version: 3.0.3
167
+ rubygems_version: 3.1.2
167
168
  signing_key:
168
169
  specification_version: 4
169
170
  summary: Extensible framework for collecting metric for your Ruby application