yabeda 0.4.0 → 0.7.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: 30e7d6e3fee4aac1922285af3fe9abc61cbfedff88ec2c2b95f70478383c02df
4
- data.tar.gz: b5ff1691c1c692672b3d03fd46fc13f299d8851f61d3a65e1571389787b8b050
3
+ metadata.gz: 8e30282089c3784919bbdfef129e36f9898bbe30376dec4148ab45551835e95a
4
+ data.tar.gz: 9abb1750e05b17f4f97f5d3c91d9eaf6f638c735b82d46baa1618500edf373da
5
5
  SHA512:
6
- metadata.gz: 0b0872f973fe39a30be8c3c74f91e7c472aa246f7be08ed0d719c605b9ab42c7625b47c294dec04a15f82b4cc90984953b5658cc8041c51776ce3bb3ea70a1a9
7
- data.tar.gz: 6ae9978212486a4deeefbb173cc7c103f5fa3a3f64db4c5ec21188a9a38aa94af39c741b900970ab5649d5ced0bf5979acd65bd531fdfa7b577640d85e7ab531
6
+ metadata.gz: b8fb61bea63f36d9f8ea98985c12d5247cefe7463ad2129f3bbda1ffbff34cc8faa4b71d797f44e02cc957a2159cdca3b53996fbf641e496476ab04e47489f3d
7
+ data.tar.gz: 66f06b7e63832eda3d43e0266fc4aa38726b261215a5308930bc9757a344dd60f43844a3d9b5f74a62069e1c090664248505d8a2408f0d6801685ccd926ea8b4
@@ -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,47 @@ 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.7.0 - 2020-08-07
9
+
10
+ ### Added
11
+
12
+ - `#increment` and `#decrement` convenience methods for `Yabeda::Gauge`. [#13](https://github.com/yabeda-rb/yabeda/pull/13) by [@dsalahutdinov]
13
+ - Ability to use custom step in `#increment` and `#decrement` for gauges. [@Envek]
14
+
15
+ ### Fixed
16
+
17
+ - Account for default tags in `Yabeda::Metric#get`. [@Envek]
18
+
19
+ ## 0.6.2 - 2020-08-04
20
+
21
+ ### Fixed
22
+
23
+ - 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]
24
+
25
+ ## 0.6.1 - 2020-07-16
26
+
27
+ ### Fixed
28
+
29
+ - 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]
30
+
31
+ ## 0.6.0 - 2020-07-15
32
+
33
+ ### Added
34
+
35
+ - `Yabeda.with_tags` to redefine default tags for limited amount of time–for all metrics measured during a block execution. [@Envek]
36
+
37
+ ### Fixed
38
+
39
+ - Default tags were not sent to adapters for metrics declared before `default_tag` declaration. [@Envek]
40
+
41
+ ## 0.5.0 - 2020-01-29
42
+
43
+ ### Added
44
+
45
+ - Ability to specify aggregation policy for metrics collected from multiple process and exposed via single endpoint. [@Envek]
46
+
47
+ For now it is only used by yabeda-prometheus when official Prometheus client is configured to use file storage for metrics.
48
+
8
49
  ## 0.4.0 - 2020-01-28
9
50
 
10
51
  ### Changed
@@ -37,7 +78,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
37
78
 
38
79
  ### Fixed
39
80
 
40
- - Removed accidental dependency from Rails. @dsalahutdinov
81
+ - Removed accidental dependency from Rails. [@dsalahutdinov]
41
82
 
42
83
  ## 0.1.1 - 2018-10-17
43
84
 
@@ -50,4 +91,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
50
91
  - Initial release of evil-metrics gem. @Envek
51
92
 
52
93
  [@Envek]: https://github.com/Envek "Andrey Novikov"
94
+ [@dsalahutdinov]: https://github.com/dsalahutdinov "Dmitry Salahutdinov"
53
95
  [@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
@@ -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
@@ -60,6 +60,7 @@ module Yabeda
60
60
 
61
61
  # Perform configuration: registration of metrics and collector blocks
62
62
  # @return [void]
63
+ # rubocop: disable Metrics/MethodLength, Metrics/AbcSize
63
64
  def configure!
64
65
  raise(AlreadyConfiguredError, @configured_by) if already_configured?
65
66
 
@@ -69,8 +70,17 @@ module Yabeda
69
70
  group nil
70
71
  end
71
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
+
72
81
  @configured_by = caller_locations(1, 1)[0].to_s
73
82
  end
83
+ # rubocop: enable Metrics/MethodLength, Metrics/AbcSize
74
84
 
75
85
  # Forget all the configuration.
76
86
  # 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
@@ -13,10 +13,11 @@ 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 = {})
19
- values[labels]
20
+ values[::Yabeda::Tags.build(labels)]
20
21
  end
21
22
 
22
23
  def values
@@ -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.4.0"
4
+ VERSION = "0.7.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.4.0
4
+ version: 0.7.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-28 00:00:00.000000000 Z
11
+ date: 2020-08-07 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: []
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  - !ruby/object:Gem::Version
165
165
  version: '0'
166
166
  requirements: []
167
- rubygems_version: 3.0.3
167
+ rubygems_version: 3.1.2
168
168
  signing_key:
169
169
  specification_version: 4
170
170
  summary: Extensible framework for collecting metric for your Ruby application