yabeda 0.2.0 → 0.3.0

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: fce95ac4969384292f6a3151b1aebb3c1affc3a41317f6e9c30543de90e50146
4
- data.tar.gz: f1df0f753c8530166727ec53f7fe227f5fa67cafe39fe42d04309632981d0c47
3
+ metadata.gz: 84d57c72434b9d26ac68f5244de32338f90203c73f8c488541ea3e284ca763bf
4
+ data.tar.gz: c06c5b0475a260a15962c98d89346fa894eebad8200e728234814686cedbee48
5
5
  SHA512:
6
- metadata.gz: 616b4376b04364a5e6e6c88b9c8b763dbaf02dd304a611fde4968a06be43c2773b6a9b6f6aac4e3629a0481cd5aa81b1ca731b1ecc5118970a1c1f0f0c2ad7d3
7
- data.tar.gz: 1ee600f68346abc63dfc2dbc66d52a169584b43005db91f5fd952accf836b66ffcee478d95cb37ffa81bb4921769aeb7f04e0bbeb329c073064ed290de1808c0
6
+ metadata.gz: ce0c24fc3f77ae77295b9b0746cc4885743a60bb9d02ce092f71beaf4493cf9bf135703ebfbb39d44c990aa2409c4e423fe99aeeebb6ac1f0cec2f0b5279496e
7
+ data.tar.gz: 3f709b4c288ccf9fed8ddf9f890de3182c427cfe3837e3bb47cc70eec350a754ee19736fd788eaa6b7ed3a9f785160301d597eff5347fa4506667ae16c4027d2
@@ -5,6 +5,12 @@ 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.3.0 - 2020-01-15
9
+
10
+ ### Added
11
+
12
+ - Ability to specify default tag which value will be automatically added to all metrics. [#7](https://github.com/yabeda-rb/yabeda/pull/7) by [@asusikov].
13
+
8
14
  ## 0.2.0 - 2020-01-14
9
15
 
10
16
  ### Added
@@ -34,3 +40,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
34
40
  ## 0.1.0 - 2018-10-03
35
41
 
36
42
  - Initial release of evil-metrics gem. @Envek
43
+
44
+ [@asusikov]: https://github.com/asusikov "Alexander Susikov"
data/README.md CHANGED
@@ -71,8 +71,15 @@ And then execute:
71
71
  end
72
72
  ```
73
73
 
74
- 4. See the docs for the adapter you're using
75
- 5. Enjoy!
74
+ 4. _Optionally_ setup default tags that will be added to all metrics
75
+ ```ruby
76
+ Yabeda.configure do
77
+ default_tag :rails_environment, 'production'
78
+ end
79
+ ```
80
+
81
+ 5. See the docs for the adapter you're using
82
+ 6. Enjoy!
76
83
 
77
84
  ## Roadmap (aka TODO or Help wanted)
78
85
 
@@ -4,6 +4,7 @@ require "concurrent"
4
4
 
5
5
  require "yabeda/version"
6
6
  require "yabeda/dsl"
7
+ require "yabeda/tags"
7
8
 
8
9
  # Extendable framework for collecting and exporting metrics from Ruby apps
9
10
  module Yabeda
@@ -30,6 +31,11 @@ module Yabeda
30
31
  @collectors ||= Concurrent::Array.new
31
32
  end
32
33
 
34
+ # @return [Hash<Symbol, Symbol>] All added default tags
35
+ def default_tags
36
+ @default_tags ||= Concurrent::Hash.new
37
+ end
38
+
33
39
  # @param [Symbol] name
34
40
  # @param [BaseAdapter] instance
35
41
  def register_adapter(name, instance)
@@ -4,11 +4,12 @@ module Yabeda
4
4
  # Growing-only counter
5
5
  class Counter < Metric
6
6
  def increment(tags, by: 1)
7
- values[tags] += by
7
+ all_tags = ::Yabeda::Tags.build(tags)
8
+ values[all_tags] += by
8
9
  ::Yabeda.adapters.each do |_, adapter|
9
- adapter.perform_counter_increment!(self, tags, by)
10
+ adapter.perform_counter_increment!(self, all_tags, by)
10
11
  end
11
- values[tags]
12
+ values[all_tags]
12
13
  end
13
14
 
14
15
  def values
@@ -53,6 +53,14 @@ module Yabeda
53
53
  register_metric(metric)
54
54
  end
55
55
 
56
+ # Add default tag for all metric
57
+ #
58
+ # @param name [Symbol] Name of default tag
59
+ # @param value [String] Value of default tag
60
+ def default_tag(name, value)
61
+ ::Yabeda.default_tags[name] = value
62
+ end
63
+
56
64
  private
57
65
 
58
66
  def register_metric(metric)
@@ -4,9 +4,10 @@ module Yabeda
4
4
  # Arbitrary value, can be changed in both sides
5
5
  class Gauge < Metric
6
6
  def set(tags, value)
7
- values[tags] = value
7
+ all_tags = ::Yabeda::Tags.build(tags)
8
+ values[all_tags] = value
8
9
  ::Yabeda.adapters.each do |_, adapter|
9
- adapter.perform_gauge_set!(self, tags, value)
10
+ adapter.perform_gauge_set!(self, all_tags, value)
10
11
  end
11
12
  value
12
13
  end
@@ -7,9 +7,10 @@ module Yabeda
7
7
  option :buckets
8
8
 
9
9
  def measure(tags, value)
10
- values[tags] = value
10
+ all_tags = ::Yabeda::Tags.build(tags)
11
+ values[all_tags] = value
11
12
  ::Yabeda.adapters.each do |_, adapter|
12
- adapter.perform_histogram_measure!(self, tags, value)
13
+ adapter.perform_histogram_measure!(self, all_tags, value)
13
14
  end
14
15
  value
15
16
  end
@@ -22,5 +22,9 @@ module Yabeda
22
22
  def values
23
23
  @values ||= Concurrent::Hash.new
24
24
  end
25
+
26
+ def tags
27
+ (Yabeda.default_tags.keys + Array(super)).uniq
28
+ end
25
29
  end
26
30
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yabeda
4
+ # Class to merge tags
5
+ class Tags
6
+ def self.build(tags)
7
+ ::Yabeda.default_tags.merge(tags)
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yabeda
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.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.2.0
4
+ version: 0.3.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-14 00:00:00.000000000 Z
11
+ date: 2020-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -141,6 +141,7 @@ files:
141
141
  - lib/yabeda/group.rb
142
142
  - lib/yabeda/histogram.rb
143
143
  - lib/yabeda/metric.rb
144
+ - lib/yabeda/tags.rb
144
145
  - lib/yabeda/version.rb
145
146
  - yabeda.gemspec
146
147
  homepage: https://github.com/yabeda-rb/yabeda