yabeda 0.5.0 → 0.8.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: 324b1326a709ae2ef5754ab07f117a6f7ee801df3f35c0c973198e85c6e7c1b1
4
- data.tar.gz: b06be1f053df8d40fa31a3cd0f84ecc52ea7f0fc59c72bf1d13f938862dc16dd
3
+ metadata.gz: f7c6b79b60dd1c6ea62fe35f811be834bb64baecd5a7fcdfcd35b3f42415d45d
4
+ data.tar.gz: 7f1d0130e059e95769e8a663edde3c05b0cc0a49f7af91e22a8ba2cf2a55027a
5
5
  SHA512:
6
- metadata.gz: 61a38c13f05a2357c1dee89891e6738675be94c587fd271950584aa14e581ab49cf87fe27d023b39290357763fed11e8d22f53a6e39930a4d8e0f7959f420cc7
7
- data.tar.gz: e5c8f67eed9e8c2e46d8ae6367c12ea287a39eadd75985e78942da285ea8e2ec8d73ea73c54b04c9efe7eb0215ffcff48c0c60fe0fa61c4ca50b134e024fe1aa
6
+ metadata.gz: 40a72d78f2a675c8b0b1c476a9dd29345454a341e7cccbc5353862c4783b85f0825ee387a558547f5b796a126b2c229a6347f09bd1cde1c3935002dbabeea3a2
7
+ data.tar.gz: 502631f8472f5f474c3cdbfac887e3e62015a6231246f84512b1251446a4f8913fb62a0cd97f7f6c4d60679318fcac421c9563397ec656f16b3fafc0c38b4f6f
@@ -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,45 @@ 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.8.0 - 2020-08-21
9
+
10
+ ### Added
11
+
12
+ - Added railtie to automatically configure Yabeda on Rails: moved from [yabeda-rails](https://github.com/yabeda-rb/yabeda-rails) gem. [@Envek]
13
+
14
+ ## 0.7.0 - 2020-08-07
15
+
16
+ ### Added
17
+
18
+ - `#increment` and `#decrement` convenience methods for `Yabeda::Gauge`. [#13](https://github.com/yabeda-rb/yabeda/pull/13) by [@dsalahutdinov]
19
+ - Ability to use custom step in `#increment` and `#decrement` for gauges. [@Envek]
20
+
21
+ ### Fixed
22
+
23
+ - Account for default tags in `Yabeda::Metric#get`. [@Envek]
24
+
25
+ ## 0.6.2 - 2020-08-04
26
+
27
+ ### Fixed
28
+
29
+ - 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]
30
+
31
+ ## 0.6.1 - 2020-07-16
32
+
33
+ ### Fixed
34
+
35
+ - 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]
36
+
37
+ ## 0.6.0 - 2020-07-15
38
+
39
+ ### Added
40
+
41
+ - `Yabeda.with_tags` to redefine default tags for limited amount of time–for all metrics measured during a block execution. [@Envek]
42
+
43
+ ### Fixed
44
+
45
+ - Default tags were not sent to adapters for metrics declared before `default_tag` declaration. [@Envek]
46
+
8
47
  ## 0.5.0 - 2020-01-29
9
48
 
10
49
  ### Added
@@ -45,7 +84,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
45
84
 
46
85
  ### Fixed
47
86
 
48
- - Removed accidental dependency from Rails. @dsalahutdinov
87
+ - Removed accidental dependency from Rails. [@dsalahutdinov]
49
88
 
50
89
  ## 0.1.1 - 2018-10-17
51
90
 
@@ -58,4 +97,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
58
97
  - Initial release of evil-metrics gem. @Envek
59
98
 
60
99
  [@Envek]: https://github.com/Envek "Andrey Novikov"
100
+ [@dsalahutdinov]: https://github.com/dsalahutdinov "Dmitry Salahutdinov"
61
101
  [@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
@@ -49,7 +49,7 @@ And then execute:
49
49
  Yabeda.configure!
50
50
  ```
51
51
 
52
- _But [yabeda-rails] will do this for you automatically._
52
+ _If you're using Ruby on Rails then it will be configured automatically!_
53
53
 
54
54
  3. Access metric in your app and use it!
55
55
 
@@ -84,11 +84,24 @@ And then execute:
84
84
  Yabeda.configure do
85
85
  default_tag :rails_environment, 'production'
86
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
87
92
  ```
88
93
 
89
94
  6. See the docs for the adapter you're using
90
95
  7. Enjoy!
91
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._
104
+
92
105
  ## Roadmap (aka TODO or Help wanted)
93
106
 
94
107
  - Ability to change metric settings for individual adapters
@@ -6,6 +6,7 @@ require "yabeda/version"
6
6
  require "yabeda/dsl"
7
7
  require "yabeda/tags"
8
8
  require "yabeda/errors"
9
+ require "yabeda/railtie" if defined?(Rails)
9
10
 
10
11
  # Extendable framework for collecting and exporting metrics from Ruby apps
11
12
  module Yabeda
@@ -60,6 +61,7 @@ module Yabeda
60
61
 
61
62
  # Perform configuration: registration of metrics and collector blocks
62
63
  # @return [void]
64
+ # rubocop: disable Metrics/MethodLength, Metrics/AbcSize
63
65
  def configure!
64
66
  raise(AlreadyConfiguredError, @configured_by) if already_configured?
65
67
 
@@ -69,8 +71,17 @@ module Yabeda
69
71
  group nil
70
72
  end
71
73
 
74
+ # Register metrics in adapters after evaluating all configuration blocks
75
+ # to ensure that all global settings (like default tags) will be applied.
76
+ adapters.each_value do |adapter|
77
+ metrics.each_value do |metric|
78
+ adapter.register!(metric)
79
+ end
80
+ end
81
+
72
82
  @configured_by = caller_locations(1, 1)[0].to_s
73
83
  end
84
+ # rubocop: enable Metrics/MethodLength, Metrics/AbcSize
74
85
 
75
86
  # Forget all the configuration.
76
87
  # For testing purposes as it doesn't rollback changes in adapters.
@@ -62,14 +62,30 @@ module Yabeda
62
62
  ::Yabeda.default_tags[name] = value
63
63
  end
64
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
+
65
81
  private
66
82
 
67
83
  def register_metric(metric)
68
84
  name = [metric.group, metric.name].compact.join("_")
69
85
  ::Yabeda.define_singleton_method(name) { metric }
70
86
  ::Yabeda.metrics[name] = metric
71
- ::Yabeda.adapters.each_value { |adapter| adapter.register!(metric) }
72
87
  register_group_for(metric) if metric.group
88
+ ::Yabeda.adapters.each_value { |adapter| adapter.register!(metric) } if ::Yabeda.configured?
73
89
  metric
74
90
  end
75
91
 
@@ -11,5 +11,13 @@ module Yabeda
11
11
  end
12
12
  value
13
13
  end
14
+
15
+ def increment(tags, by: 1)
16
+ set(tags, get(tags).to_i + by)
17
+ end
18
+
19
+ def decrement(tags, by: 1)
20
+ set(tags, get(tags).to_i - by)
21
+ end
14
22
  end
15
23
  end
@@ -17,7 +17,7 @@ module Yabeda
17
17
 
18
18
  # Returns the value for the given label set
19
19
  def get(labels = {})
20
- values[labels]
20
+ values[::Yabeda::Tags.build(labels)]
21
21
  end
22
22
 
23
23
  def values
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yabeda
4
+ module Rails
5
+ class Railtie < ::Rails::Railtie # :nodoc:
6
+ config.after_initialize do
7
+ Yabeda.configure! unless Yabeda.already_configured?
8
+ end
9
+ end
10
+ end
11
+ end
@@ -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.5.0"
4
+ VERSION = "0.8.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.5.0
4
+ version: 0.8.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-29 00:00:00.000000000 Z
11
+ date: 2020-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -142,6 +142,7 @@ files:
142
142
  - lib/yabeda/group.rb
143
143
  - lib/yabeda/histogram.rb
144
144
  - lib/yabeda/metric.rb
145
+ - lib/yabeda/railtie.rb
145
146
  - lib/yabeda/tags.rb
146
147
  - lib/yabeda/version.rb
147
148
  - yabeda.gemspec
@@ -164,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
165
  - !ruby/object:Gem::Version
165
166
  version: '0'
166
167
  requirements: []
167
- rubygems_version: 3.0.3
168
+ rubygems_version: 3.1.2
168
169
  signing_key:
169
170
  specification_version: 4
170
171
  summary: Extensible framework for collecting metric for your Ruby application