Class: Yabeda::Counter
Overview
Growing-only counter
Instance Attribute Summary
Attributes inherited from Metric
#adapter, #aggregation, #comment, #group, #name, #per, #tags, #unit
Class Method Summary collapse
-
.parse_args(*args) ⇒ Object
private
rubocop:disable Metrics/MethodLength.
Instance Method Summary collapse
-
#increment(tags = {}, by: 1) ⇒ Object
Increment the counter for given set of tags by the given increment value.
- #values ⇒ Object
Methods inherited from Metric
#adapters, #get, #initialize, #inspect
Constructor Details
This class inherits a constructor from Yabeda::Metric
Class Method Details
.parse_args(*args) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:disable Metrics/MethodLength
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/yabeda/counter.rb', line 26 def self.parse_args(*args) case args.size when 0 # increment() [EMPTY_TAGS, 1] when 1 # increment(by: 5) or increment(tags) if args[0].key?(:by) [EMPTY_TAGS, args.fetch(:by)] else [args[0], 1] end when 2 # increment(tags, by: 5) [args[0], args[1].fetch(:by, 1)] else raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0..2)" end end |
Instance Method Details
#increment(tags = {}, by: 1) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/yabeda/counter.rb', line 10 def increment(*args) , by = self.class.parse_args(*args) = ::Yabeda::Tags.build(, group) values[] += by adapters.each_value do |adapter| adapter.perform_counter_increment!(self, , by) end values[] end |
#values ⇒ Object
20 21 22 |
# File 'lib/yabeda/counter.rb', line 20 def values @values ||= Concurrent::Hash.new(0) end |