yabeda 0.13.2 → 0.15.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: c713eeb29eb6f5eb9a022b2bb43f85961a72dca331629ca0ab335b2c72e9bd4d
4
- data.tar.gz: e9309522c7b6e8982518d8a03d52e6b3096c61647cdb63a618e957da5b6f50d4
3
+ metadata.gz: 4a403c359e0c88e79f3352df2521a880d17c2fee74457cd911e776d51042060f
4
+ data.tar.gz: 795a2312ba8de8ff41198444b87614fae3eb5fa803feed950f83d965c67f76a8
5
5
  SHA512:
6
- metadata.gz: 9cb7676c26c849772cd27ddb180e5d733af2243b890d9dbb83dc7ff73ca57ed861a651ee7fa22f36410800600976ee0920115b96f36d036ed65b5652b6ff4dce
7
- data.tar.gz: 0a145163ed0af2f669b8eaa235784b1bbbb0011a2222d4c5a44adca6461d264024a075c7c48a54fbdab089d8e8d2f41a3e96f9009fdb272b46ca2ba35d567c0c
6
+ metadata.gz: 1e432f7754fcbe31703dca2f753e8c19552e7e941a7e9e064430cd34066fbfb8f714920af8a8c88c2b1deadeab4f6ec464b24bc466d413d2f819670d59d21a70
7
+ data.tar.gz: 88f8f047866dff1244fc5609586d2ec4560bae818c926fae2de5428c073ebc10655ea3997a163d9923f86ef63720614ea3b49236025a54f91c27673564c0f4d0
@@ -21,6 +21,7 @@ jobs:
21
21
  include:
22
22
  - ruby: head
23
23
  optional: true
24
+ - ruby: "4.0"
24
25
  - ruby: "3.4"
25
26
  - ruby: "3.3"
26
27
  - ruby: "3.2"
data/CHANGELOG.md CHANGED
@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ## 0.15.0 - 2026-03-04
11
+
12
+ ### Fixed
13
+
14
+ - Concurrency issues with metrics' increment/decrement helper methods. [@cconstantine-onesignal][] in [#45](https://github.com/yabeda-rb/yabeda/pull/45)
15
+
16
+ ## 0.14.0 - 2025-09-10
17
+
18
+ ### Added
19
+
20
+ - Allow to limit groups per adapter. [@killondark][] in [#41](https://github.com/yabeda-rb/yabeda/pull/41)
21
+
22
+ ```ruby
23
+ Yabeda.configure do
24
+ group :mushrooms do
25
+ counter :champignon_counter
26
+ end
27
+
28
+ adapter :basket_adapter do
29
+ include_group :mushrooms
30
+ end
31
+ end
32
+ ```
33
+
10
34
  ## 0.13.2 - 2025-09-09
11
35
 
12
36
  ### Fixed
@@ -196,3 +220,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
196
220
  [@bibendi]: https://github.com/bibendi "Misha Merkushin"
197
221
  [@Keallar]: https://github.com/Keallar "Eugene Lysanskiy"
198
222
  [@jbockler]: https://github.com/jbockler "Josch Bockler"
223
+ [@killondark]: https://github.com/killondark "Alexander Marychev"
224
+ [@cconstantine-onesignal]: https://github.com/cconstantine-onesignal "Chris Constantine"
data/Gemfile CHANGED
@@ -13,8 +13,7 @@ group :development, :test do
13
13
  gem "yard"
14
14
  gem "yard-dry-initializer"
15
15
 
16
- gem "pry"
17
- gem "pry-byebug", platform: :mri
16
+ gem "debug"
18
17
 
19
18
  gem "rubocop", "~> 1.0", require: false
20
19
  gem "rubocop-rspec", require: false
data/README.md CHANGED
@@ -158,6 +158,8 @@ These are developed and maintained by other awesome folks:
158
158
  - [yabeda-shoryuken](https://github.com/retsef/yabeda-shoryuken) — metrics for [Shoryuken](https://github.com/ruby-shoryuken/shoryuken) jobs execution message queues.
159
159
  - [yabeda-rack-ratelimit](https://github.com/basecamp/yabeda-rack-ratelimit) — metrics for [Rack::Ratelimit](https://github.com/jeremy/rack-ratelimit)
160
160
  - [yabeda-hanami](https://github.com/mlibrary/yabeda-hanami) — metrics for [Hanami](https://hanamirb.org/) The web, with simplicity.
161
+ - [yabeda-jemalloc](http://github.com/jondavidschober/yabeda-jemalloc) - metrics for [Jemalloc](https://jemalloc.net/) via the `stats` FFI
162
+ - [yabeda-rack-queue](https://github.com/speedshop/yabeda-rack-queue) - metrics for reporting queue times of Rack applications.
161
163
  - _…and more! You can write your own adapter and open a pull request to add it into this list._
162
164
 
163
165
  ## Configuration
@@ -246,6 +248,19 @@ Yabeda.configure do
246
248
  end
247
249
  ```
248
250
 
251
+ Or use another DSL to describe this logic:
252
+
253
+ ```ruby
254
+ Yabeda.configure do
255
+ group :mushrooms do
256
+ counter :champignon_counter
257
+ end
258
+
259
+ adapter :basket_adapter do
260
+ include_group :mushrooms
261
+ end
262
+ end
263
+ ```
249
264
 
250
265
  ## Roadmap (aka TODO or Help wanted)
251
266
 
@@ -29,6 +29,13 @@ module Yabeda
29
29
  raise NotImplementedError, "#{self.class} doesn't support setting gauges"
30
30
  end
31
31
 
32
+ # Optional method that adapters can implement for native gauge increment/decrement
33
+ def perform_gauge_increment!(_gauge, _tags, _increment)
34
+ # used to indicate adapter does not implement this method. return a non-nil value
35
+ # in your adapter to indicate it is supported
36
+ nil
37
+ end
38
+
32
39
  def register_histogram!(_metric)
33
40
  raise NotImplementedError, "#{self.class} doesn't support histograms as metric type!"
34
41
  end
@@ -10,15 +10,11 @@ module Yabeda
10
10
  def increment(*args)
11
11
  tags, by = self.class.parse_args(*args)
12
12
  all_tags = ::Yabeda::Tags.build(tags, group)
13
- values[all_tags] += by
13
+ value = increment_value(all_tags, by: by)
14
14
  adapters.each_value do |adapter|
15
15
  adapter.perform_counter_increment!(self, all_tags, by)
16
16
  end
17
- values[all_tags]
18
- end
19
-
20
- def values
21
- @values ||= Concurrent::Hash.new(0)
17
+ value
22
18
  end
23
19
 
24
20
  # @api private
@@ -96,10 +96,25 @@ module Yabeda
96
96
  #
97
97
  # @param adapter_names [Array<Symbol>] Names of adapters to use
98
98
  def adapter(*adapter_names, group: @group)
99
- raise ConfigurationError, "Adapter limitation can't be defined outside of group" unless group
99
+ raise ConfigurationError, "Adapter limitation can't be defined without adapter_names" if adapter_names.empty?
100
+
101
+ @adapter_names = adapter_names
102
+ if group
103
+ include_group(group)
104
+ else
105
+ return yield if block_given?
106
+
107
+ raise ConfigurationError, "Yabeda.adapter should be called either inside group declaration " \
108
+ "or should have block provided with a call to include_group. No metric group provided."
109
+ end
110
+ ensure @adapter_names = nil
111
+ end
112
+
113
+ def include_group(group)
114
+ raise ConfigurationError, "Adapter limitation can't be defined without of group name" unless group
100
115
 
101
116
  Yabeda.groups[group] ||= Yabeda::Group.new(group)
102
- Yabeda.groups[group].adapter(*adapter_names)
117
+ Yabeda.groups[group].adapter(*@adapter_names)
103
118
  end
104
119
 
105
120
  private
data/lib/yabeda/gauge.rb CHANGED
@@ -5,7 +5,8 @@ module Yabeda
5
5
  class Gauge < Metric
6
6
  def set(tags, value)
7
7
  all_tags = ::Yabeda::Tags.build(tags, group)
8
- values[all_tags] = value
8
+ atomic_value = values[all_tags] ||= Concurrent::Atom.new(0)
9
+ atomic_value.swap { |_| value }
9
10
  adapters.each_value do |adapter|
10
11
  adapter.perform_gauge_set!(self, all_tags, value)
11
12
  end
@@ -18,7 +19,14 @@ module Yabeda
18
19
  # @param by [Integer] increment value
19
20
  def increment(*args)
20
21
  tags, by = Counter.parse_args(*args)
21
- set(tags, get(tags).to_i + by)
22
+ all_tags = ::Yabeda::Tags.build(tags, group)
23
+ next_value = increment_value(all_tags, by: by)
24
+ adapters.each_value do |adapter|
25
+ if adapter.perform_gauge_increment!(self, all_tags, by).nil?
26
+ adapter.perform_gauge_set!(self, all_tags, next_value)
27
+ end
28
+ end
29
+ next_value
22
30
  end
23
31
 
24
32
  # @overload decrement(tags = {}, by: 1)
@@ -27,7 +35,14 @@ module Yabeda
27
35
  # @param by [Integer] decrement value
28
36
  def decrement(*args)
29
37
  tags, by = Counter.parse_args(*args)
30
- set(tags, get(tags).to_i - by)
38
+ all_tags = ::Yabeda::Tags.build(tags, group)
39
+ next_value = increment_value(all_tags, by: -by)
40
+ adapters.each_value do |adapter|
41
+ if adapter.perform_gauge_increment!(self, all_tags, -by).nil?
42
+ adapter.perform_gauge_set!(self, all_tags, next_value)
43
+ end
44
+ end
45
+ next_value
31
46
  end
32
47
  end
33
48
  end
data/lib/yabeda/metric.rb CHANGED
@@ -17,14 +17,11 @@ module Yabeda
17
17
  # rubocop:disable Layout/LineLength
18
18
  option :adapter, optional: true, comment: "Monitoring system adapter to register metric in and report metric values to (other adapters won't be used)"
19
19
  # rubocop:enable Layout/LineLength
20
+ option :values, optional: true, default: proc { Concurrent::Hash.new }
20
21
 
21
22
  # Returns the value for the given label set
22
23
  def get(labels = {})
23
- values[::Yabeda::Tags.build(labels, group)]
24
- end
25
-
26
- def values
27
- @values ||= Concurrent::Hash.new
24
+ @values[::Yabeda::Tags.build(labels, group)]&.value
28
25
  end
29
26
 
30
27
  # Returns allowed tags for metric (with account for global and group-level +default_tags+)
@@ -62,5 +59,12 @@ module Yabeda
62
59
 
63
60
  super
64
61
  end
62
+
63
+ # Atomically increment the stored value, assumed to be given all labels, including group labels
64
+ # @api private
65
+ def increment_value(labels = {}, by: 1)
66
+ atomic_value = values[labels] ||= Concurrent::Atom.new(0)
67
+ atomic_value.swap { |prev| prev + by }
68
+ end
65
69
  end
66
70
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yabeda
4
- VERSION = "0.13.2"
4
+ VERSION = "0.15.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.13.2
4
+ version: 0.15.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: 2025-09-09 00:00:00.000000000 Z
11
+ date: 2026-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: anyway_config