yabeda 0.2.0 → 0.6.1
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 +4 -4
- data/.rubocop.yml +9 -4
- data/.travis.yml +0 -1
- data/CHANGELOG.md +41 -0
- data/Gemfile +1 -1
- data/README.md +34 -4
- data/lib/yabeda.rb +55 -0
- data/lib/yabeda/counter.rb +4 -3
- data/lib/yabeda/dsl/class_methods.rb +26 -2
- data/lib/yabeda/dsl/metric_builder.rb +0 -2
- data/lib/yabeda/errors.rb +15 -0
- data/lib/yabeda/gauge.rb +3 -2
- data/lib/yabeda/histogram.rb +3 -2
- data/lib/yabeda/metric.rb +5 -0
- data/lib/yabeda/tags.rb +10 -0
- data/lib/yabeda/version.rb +1 -1
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2f29f3127ff98f3b4d6a31849685b3ad8b0df4fdde074317a2f1bf487f78698
|
4
|
+
data.tar.gz: a2f77eb4d92ab8b17aa85bd4eeec02b221a677d3e210a1abc48a9f39ad905063
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67a977f74a4ed9ac12ef5c6b683c62a39eb7f4a298dbf4bffa2e6fb6245e563ae2a3bc181935ee626d0ef18d4171d856611651bab5a89c5a7a8856856a50055e
|
7
|
+
data.tar.gz: c8000204d2d037e59b29cc37a8605e4106114fee711b7b39ed87b8c0abdabfd247e7e3f60907d0412ff6a745070f5a23898dfdf145a367f900d047b7f90ddfa8
|
data/.rubocop.yml
CHANGED
@@ -10,12 +10,9 @@ Metrics/BlockLength:
|
|
10
10
|
- "Gemfile"
|
11
11
|
- "spec/**/*"
|
12
12
|
|
13
|
-
|
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
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,44 @@ 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.6.1 - 2020-07-16
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
|
12
|
+
- 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]
|
13
|
+
|
14
|
+
## 0.6.0 - 2020-07-15
|
15
|
+
|
16
|
+
### Added
|
17
|
+
|
18
|
+
- `Yabeda.with_tags` to redefine default tags for limited amount of time–for all metrics measured during a block execution. [@Envek]
|
19
|
+
|
20
|
+
### Fixed
|
21
|
+
|
22
|
+
- Default tags were not sent to adapters for metrics declared before `default_tag` declaration. [@Envek]
|
23
|
+
|
24
|
+
## 0.5.0 - 2020-01-29
|
25
|
+
|
26
|
+
### Added
|
27
|
+
|
28
|
+
- Ability to specify aggregation policy for metrics collected from multiple process and exposed via single endpoint. [@Envek]
|
29
|
+
|
30
|
+
For now it is only used by yabeda-prometheus when official Prometheus client is configured to use file storage for metrics.
|
31
|
+
|
32
|
+
## 0.4.0 - 2020-01-28
|
33
|
+
|
34
|
+
### Changed
|
35
|
+
|
36
|
+
- Configuration of gem was changed from synchronous (at the moment when `configure` block was executed) to postponed (only on `configure!` method call). [@Envek]
|
37
|
+
|
38
|
+
This should allow to fix problems when metrics from gems are registered too early, before required changes to the monitoring system clients.
|
39
|
+
|
40
|
+
## 0.3.0 - 2020-01-15
|
41
|
+
|
42
|
+
### Added
|
43
|
+
|
44
|
+
- 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].
|
45
|
+
|
8
46
|
## 0.2.0 - 2020-01-14
|
9
47
|
|
10
48
|
### Added
|
@@ -34,3 +72,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
34
72
|
## 0.1.0 - 2018-10-03
|
35
73
|
|
36
74
|
- Initial release of evil-metrics gem. @Envek
|
75
|
+
|
76
|
+
[@Envek]: https://github.com/Envek "Andrey Novikov"
|
77
|
+
[@asusikov]: https://github.com/asusikov "Alexander Susikov"
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -43,7 +43,15 @@ And then execute:
|
|
43
43
|
end
|
44
44
|
```
|
45
45
|
|
46
|
-
2.
|
46
|
+
2. After your application was initialized and all metrics was declared, you need to apply Yabeda configuration:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
Yabeda.configure!
|
50
|
+
```
|
51
|
+
|
52
|
+
_But [yabeda-rails] will do this for you automatically._
|
53
|
+
|
54
|
+
3. Access metric in your app and use it!
|
47
55
|
|
48
56
|
```ruby
|
49
57
|
def ring_the_bell(id)
|
@@ -59,7 +67,7 @@ And then execute:
|
|
59
67
|
end
|
60
68
|
```
|
61
69
|
|
62
|
-
|
70
|
+
4. Setup collecting of metrics that do not tied to specific events in you application. E.g.: reporting your app's current state
|
63
71
|
```ruby
|
64
72
|
Yabeda.configure do
|
65
73
|
# This block will be executed periodically few times in a minute
|
@@ -71,8 +79,28 @@ And then execute:
|
|
71
79
|
end
|
72
80
|
```
|
73
81
|
|
74
|
-
|
75
|
-
|
82
|
+
5. _Optionally_ setup default tags that will be added to all metrics
|
83
|
+
```ruby
|
84
|
+
Yabeda.configure do
|
85
|
+
default_tag :rails_environment, 'production'
|
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
|
92
|
+
```
|
93
|
+
|
94
|
+
6. See the docs for the adapter you're using
|
95
|
+
7. Enjoy!
|
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._
|
76
104
|
|
77
105
|
## Roadmap (aka TODO or Help wanted)
|
78
106
|
|
@@ -109,3 +137,5 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/yabeda
|
|
109
137
|
## License
|
110
138
|
|
111
139
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
140
|
+
|
141
|
+
[yabeda-rails]: https://github.com/yabeda-rb/yabeda-rails/ "Yabeda plugin for collecting and exporting basic metrics for Rails applications"
|
data/lib/yabeda.rb
CHANGED
@@ -4,6 +4,8 @@ require "concurrent"
|
|
4
4
|
|
5
5
|
require "yabeda/version"
|
6
6
|
require "yabeda/dsl"
|
7
|
+
require "yabeda/tags"
|
8
|
+
require "yabeda/errors"
|
7
9
|
|
8
10
|
# Extendable framework for collecting and exporting metrics from Ruby apps
|
9
11
|
module Yabeda
|
@@ -30,6 +32,11 @@ module Yabeda
|
|
30
32
|
@collectors ||= Concurrent::Array.new
|
31
33
|
end
|
32
34
|
|
35
|
+
# @return [Hash<Symbol, Symbol>] All added default tags
|
36
|
+
def default_tags
|
37
|
+
@default_tags ||= Concurrent::Hash.new
|
38
|
+
end
|
39
|
+
|
33
40
|
# @param [Symbol] name
|
34
41
|
# @param [BaseAdapter] instance
|
35
42
|
def register_adapter(name, instance)
|
@@ -39,5 +46,53 @@ module Yabeda
|
|
39
46
|
instance.register!(metric)
|
40
47
|
end
|
41
48
|
end
|
49
|
+
|
50
|
+
# @return [Array<Proc>] All configuration blocks for postponed setup
|
51
|
+
def configurators
|
52
|
+
@configurators ||= Concurrent::Array.new
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [Boolean] Whether +Yabeda.configure!+ has been already called
|
56
|
+
def configured?
|
57
|
+
!@configured_by.nil?
|
58
|
+
end
|
59
|
+
alias already_configured? configured?
|
60
|
+
|
61
|
+
# Perform configuration: registration of metrics and collector blocks
|
62
|
+
# @return [void]
|
63
|
+
# rubocop: disable Metrics/MethodLength, Metrics/AbcSize
|
64
|
+
def configure!
|
65
|
+
raise(AlreadyConfiguredError, @configured_by) if already_configured?
|
66
|
+
|
67
|
+
configurators.each do |(group, block)|
|
68
|
+
group group
|
69
|
+
class_eval(&block)
|
70
|
+
group nil
|
71
|
+
end
|
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
|
+
|
81
|
+
@configured_by = caller_locations(1, 1)[0].to_s
|
82
|
+
end
|
83
|
+
# rubocop: enable Metrics/MethodLength, Metrics/AbcSize
|
84
|
+
|
85
|
+
# Forget all the configuration.
|
86
|
+
# For testing purposes as it doesn't rollback changes in adapters.
|
87
|
+
# @api private
|
88
|
+
def reset!
|
89
|
+
default_tags.clear
|
90
|
+
adapters.clear
|
91
|
+
groups.clear
|
92
|
+
metrics.clear
|
93
|
+
collectors.clear
|
94
|
+
configurators.clear
|
95
|
+
instance_variable_set(:@configured_by, nil)
|
96
|
+
end
|
42
97
|
end
|
43
98
|
end
|
data/lib/yabeda/counter.rb
CHANGED
@@ -4,11 +4,12 @@ module Yabeda
|
|
4
4
|
# Growing-only counter
|
5
5
|
class Counter < Metric
|
6
6
|
def increment(tags, by: 1)
|
7
|
-
|
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,
|
10
|
+
adapter.perform_counter_increment!(self, all_tags, by)
|
10
11
|
end
|
11
|
-
values[
|
12
|
+
values[all_tags]
|
12
13
|
end
|
13
14
|
|
14
15
|
def values
|
@@ -14,7 +14,8 @@ module Yabeda
|
|
14
14
|
module ClassMethods
|
15
15
|
# Block for grouping and simplifying configuration of related metrics
|
16
16
|
def configure(&block)
|
17
|
-
|
17
|
+
Yabeda.configurators.push([@group, block])
|
18
|
+
class_exec(&block) if Yabeda.configured?
|
18
19
|
@group = nil
|
19
20
|
end
|
20
21
|
|
@@ -53,13 +54,36 @@ module Yabeda
|
|
53
54
|
register_metric(metric)
|
54
55
|
end
|
55
56
|
|
57
|
+
# Add default tag for all metric
|
58
|
+
#
|
59
|
+
# @param name [Symbol] Name of default tag
|
60
|
+
# @param value [String] Value of default tag
|
61
|
+
def default_tag(name, value)
|
62
|
+
::Yabeda.default_tags[name] = value
|
63
|
+
end
|
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
|
+
|
56
81
|
private
|
57
82
|
|
58
83
|
def register_metric(metric)
|
59
84
|
name = [metric.group, metric.name].compact.join("_")
|
60
85
|
::Yabeda.define_singleton_method(name) { metric }
|
61
86
|
::Yabeda.metrics[name] = metric
|
62
|
-
::Yabeda.adapters.each_value { |adapter| adapter.register!(metric) }
|
63
87
|
register_group_for(metric) if metric.group
|
64
88
|
metric
|
65
89
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yabeda
|
4
|
+
class ConfigurationError < StandardError; end
|
5
|
+
|
6
|
+
# Raises on repeated call to +Yabeda.configure!+
|
7
|
+
class AlreadyConfiguredError < StandardError
|
8
|
+
def initialize(configuring_location)
|
9
|
+
super
|
10
|
+
@message = "Yabeda was already configured in #{configuring_location}"
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :message
|
14
|
+
end
|
15
|
+
end
|
data/lib/yabeda/gauge.rb
CHANGED
@@ -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
|
-
|
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,
|
10
|
+
adapter.perform_gauge_set!(self, all_tags, value)
|
10
11
|
end
|
11
12
|
value
|
12
13
|
end
|
data/lib/yabeda/histogram.rb
CHANGED
@@ -7,9 +7,10 @@ module Yabeda
|
|
7
7
|
option :buckets
|
8
8
|
|
9
9
|
def measure(tags, value)
|
10
|
-
|
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,
|
13
|
+
adapter.perform_histogram_measure!(self, all_tags, value)
|
13
14
|
end
|
14
15
|
value
|
15
16
|
end
|
data/lib/yabeda/metric.rb
CHANGED
@@ -13,6 +13,7 @@ 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 = {})
|
@@ -22,5 +23,9 @@ module Yabeda
|
|
22
23
|
def values
|
23
24
|
@values ||= Concurrent::Hash.new
|
24
25
|
end
|
26
|
+
|
27
|
+
def tags
|
28
|
+
(Yabeda.default_tags.keys + Array(super)).uniq
|
29
|
+
end
|
25
30
|
end
|
26
31
|
end
|
data/lib/yabeda/tags.rb
ADDED
data/lib/yabeda/version.rb
CHANGED
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
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Novikov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -137,17 +137,19 @@ files:
|
|
137
137
|
- lib/yabeda/dsl/class_methods.rb
|
138
138
|
- lib/yabeda/dsl/metric_builder.rb
|
139
139
|
- lib/yabeda/dsl/option_builder.rb
|
140
|
+
- lib/yabeda/errors.rb
|
140
141
|
- lib/yabeda/gauge.rb
|
141
142
|
- lib/yabeda/group.rb
|
142
143
|
- lib/yabeda/histogram.rb
|
143
144
|
- lib/yabeda/metric.rb
|
145
|
+
- lib/yabeda/tags.rb
|
144
146
|
- lib/yabeda/version.rb
|
145
147
|
- yabeda.gemspec
|
146
148
|
homepage: https://github.com/yabeda-rb/yabeda
|
147
149
|
licenses:
|
148
150
|
- MIT
|
149
151
|
metadata: {}
|
150
|
-
post_install_message:
|
152
|
+
post_install_message:
|
151
153
|
rdoc_options: []
|
152
154
|
require_paths:
|
153
155
|
- lib
|
@@ -162,8 +164,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
164
|
- !ruby/object:Gem::Version
|
163
165
|
version: '0'
|
164
166
|
requirements: []
|
165
|
-
rubygems_version: 3.
|
166
|
-
signing_key:
|
167
|
+
rubygems_version: 3.1.2
|
168
|
+
signing_key:
|
167
169
|
specification_version: 4
|
168
170
|
summary: Extensible framework for collecting metric for your Ruby application
|
169
171
|
test_files: []
|