yabeda 0.9.0 → 0.10.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 +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +16 -1
- data/lib/yabeda.rb +47 -0
- data/lib/yabeda/base_adapter.rb +3 -0
- data/lib/yabeda/config.rb +13 -0
- data/lib/yabeda/histogram.rb +13 -1
- data/lib/yabeda/version.rb +1 -1
- data/yabeda-logo.png +0 -0
- data/yabeda.gemspec +1 -0
- metadata +24 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df5873bc79b044f45361239ef207d63f8a97776d39908652b11629dbb67fd317
|
4
|
+
data.tar.gz: d6d170503bfbc5ea7a2e1b2ce4415710efc1e68487350a67e270ae4b2f77c102
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8bde67925e08a45425963e778c1e6cd5dcc9a24c46cce96abeb84d56adc99529ecc58556cb930652be64d7cea604563181b69abc1157388e896d9eb76af53a8
|
7
|
+
data.tar.gz: 77d9400f003c06e387b3b75cf42d95a52546c2b240021905e649198fe78f0ff2b502da771dbce50c95e837608218026bbea5e310334371cc417567ee67c60392
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,20 @@ 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
|
+
## Unreleased
|
9
|
+
|
10
|
+
## 0.10.0 - 2021-07-21
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- Ability to pass a block to `Yabeda::Histogram#measure` to automatically measure its runtime in seconds using [monotonic time](https://blog.dnsimple.com/2018/03/elapsed-time-with-ruby-the-right-way/).
|
15
|
+
- Debug mode that will enable some additional metrics to help debug performance issues with your usage of Yabeda (or Yabeda itself). Use environment variable `YABEDA_DEBUG` to enable it or call `Yabeda.debug!`.
|
16
|
+
- Debugging histogram `yabeda_collect_duration` that measures duration of every collect block, as they are used for collecting metrics of application state and usually makes some potentially slow queries to databases, network requests, etc.
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
|
20
|
+
- Adapters now should use method `Yabeda.collect!` instead of manual calling of every collector block.
|
21
|
+
|
8
22
|
## 0.9.0 - 2021-05-07
|
9
23
|
|
10
24
|
### Added
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Yabeda
|
1
|
+
# 
|
2
2
|
|
3
3
|
[](https://rubygems.org/gems/yabeda)
|
4
4
|
|
@@ -147,6 +147,20 @@ These are developed and maintained by other awesome folks:
|
|
147
147
|
- [yabeda-gc](https://github.com/ianks/yabeda-gc) — metrics for Ruby garbage collection.
|
148
148
|
- _…and more! You can write your own adapter and open a pull request to add it into this list._
|
149
149
|
|
150
|
+
## Configuration
|
151
|
+
|
152
|
+
Configuration is handled by [anyway_config] gem. With it you can load settings from environment variables (which names are constructed from config key upcased and prefixed with `YABEDA_`), YAML files, and other sources. See [anyway_config] docs for details.
|
153
|
+
|
154
|
+
Config key | Type | Default | Description |
|
155
|
+
---------- | -------- | ------- | ----------- |
|
156
|
+
`debug` | boolean | `false` | Collects metrics measuring Yabeda performance |
|
157
|
+
|
158
|
+
## Debugging metrics
|
159
|
+
|
160
|
+
- Time of collector block run: `yabeda_collect_duration` (segmented by block source location). Collector blocks are used for collecting metrics of application state and usually makes some potentially slow queries to databases, network requests, etc.
|
161
|
+
|
162
|
+
These are only enabled in debug mode. To enable it either set `debug` config key to `true` (e.g. by specifying `YABEDA_DEBUG=true` in your environment variables or executing `Yabeda.debug!` in your code).
|
163
|
+
|
150
164
|
## Roadmap (aka TODO or Help wanted)
|
151
165
|
|
152
166
|
- Ability to change metric settings for individual adapters
|
@@ -220,3 +234,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
220
234
|
[yabeda-puma-plugin]: https://github.com/yabeda-rb/yabeda-puma-plugin/ "Collects Puma web-server metrics from puma control application"
|
221
235
|
[yabeda-http_requests]: https://github.com/yabeda-rb/yabeda-http_requests/ "Builtin metrics to monitor external HTTP requests"
|
222
236
|
[yabeda-schked]: https://github.com/yabeda-rb/yabeda-schked/ "Built-in metrics for monitoring Schked recurring jobs out of the box"
|
237
|
+
[anyway_config]: https://github.com/palkan/anyway_config "Configuration library for Ruby gems and applications"
|
data/lib/yabeda.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "concurrent"
|
4
|
+
require "forwardable"
|
4
5
|
|
5
6
|
require "yabeda/version"
|
7
|
+
require "yabeda/config"
|
6
8
|
require "yabeda/dsl"
|
7
9
|
require "yabeda/tags"
|
8
10
|
require "yabeda/errors"
|
@@ -13,6 +15,8 @@ module Yabeda
|
|
13
15
|
include DSL
|
14
16
|
|
15
17
|
class << self
|
18
|
+
extend Forwardable
|
19
|
+
|
16
20
|
# @return [Hash<String, Yabeda::Metric>] All registered metrics
|
17
21
|
def metrics
|
18
22
|
@metrics ||= Concurrent::Hash.new
|
@@ -35,6 +39,25 @@ module Yabeda
|
|
35
39
|
@collectors ||= Concurrent::Array.new
|
36
40
|
end
|
37
41
|
|
42
|
+
def config
|
43
|
+
@config ||= Config.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def_delegators :config, :debug?
|
47
|
+
|
48
|
+
# Execute all collector blocks for periodical retrieval of metrics
|
49
|
+
#
|
50
|
+
# This method is intended to be used by monitoring systems adapters
|
51
|
+
def collect!
|
52
|
+
collectors.each do |collector|
|
53
|
+
if config.debug?
|
54
|
+
yabeda.collect_duration.measure({ location: collector.source_location.join(":") }, &collector)
|
55
|
+
else
|
56
|
+
collector.call
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
38
61
|
# @return [Hash<Symbol, Symbol>] All added global default tags
|
39
62
|
def default_tags
|
40
63
|
@default_tags ||= Concurrent::Hash.new
|
@@ -67,6 +90,8 @@ module Yabeda
|
|
67
90
|
def configure!
|
68
91
|
raise(AlreadyConfiguredError, @configured_by) if already_configured?
|
69
92
|
|
93
|
+
debug! if config.debug?
|
94
|
+
|
70
95
|
configurators.each do |(group, block)|
|
71
96
|
group group
|
72
97
|
class_eval(&block)
|
@@ -83,6 +108,27 @@ module Yabeda
|
|
83
108
|
|
84
109
|
@configured_by = caller_locations(1, 1)[0].to_s
|
85
110
|
end
|
111
|
+
|
112
|
+
# Enable and setup service metrics to monitor yabeda performance
|
113
|
+
def debug!
|
114
|
+
return false if @debug_was_enabled_by # Prevent multiple calls
|
115
|
+
|
116
|
+
config.debug ||= true # Enable debug mode in config if it wasn't enabled from other sources
|
117
|
+
@debug_was_enabled_by = caller_locations(1, 1)[0].to_s
|
118
|
+
|
119
|
+
configure do
|
120
|
+
group :yabeda
|
121
|
+
|
122
|
+
histogram :collect_duration,
|
123
|
+
tags: %i[location], unit: :seconds,
|
124
|
+
buckets: [0.0001, 0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60].freeze,
|
125
|
+
comment: "A histogram for the time required to evaluate collect blocks"
|
126
|
+
end
|
127
|
+
|
128
|
+
adapters.each_value(&:debug!)
|
129
|
+
|
130
|
+
true
|
131
|
+
end
|
86
132
|
# rubocop: enable Metrics/MethodLength, Metrics/AbcSize
|
87
133
|
|
88
134
|
# Forget all the configuration.
|
@@ -99,6 +145,7 @@ module Yabeda
|
|
99
145
|
collectors.clear
|
100
146
|
configurators.clear
|
101
147
|
instance_variable_set(:@configured_by, nil)
|
148
|
+
instance_variable_set(:@debug_was_enabled_by, nil)
|
102
149
|
end
|
103
150
|
# rubocop: enable Metrics/AbcSize
|
104
151
|
end
|
data/lib/yabeda/base_adapter.rb
CHANGED
@@ -35,5 +35,8 @@ module Yabeda
|
|
35
35
|
def perform_histogram_measure!(_metric, _tags, _value)
|
36
36
|
raise NotImplementedError, "#{self.class} doesn't support measuring histograms"
|
37
37
|
end
|
38
|
+
|
39
|
+
# Hook to enable debug mode in adapters when it is enabled in Yabeda itself
|
40
|
+
def debug!; end
|
38
41
|
end
|
39
42
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "anyway"
|
4
|
+
|
5
|
+
module Yabeda
|
6
|
+
# Runtime configuration for the main yabeda gem
|
7
|
+
class Config < ::Anyway::Config
|
8
|
+
config_name :yabeda
|
9
|
+
|
10
|
+
# Declare and collect metrics about Yabeda performance
|
11
|
+
attr_config debug: false
|
12
|
+
end
|
13
|
+
end
|
data/lib/yabeda/histogram.rb
CHANGED
@@ -6,7 +6,18 @@ module Yabeda
|
|
6
6
|
class Histogram < Metric
|
7
7
|
option :buckets
|
8
8
|
|
9
|
-
|
9
|
+
# rubocop: disable Metrics/MethodLength
|
10
|
+
def measure(tags, value = nil)
|
11
|
+
if value.nil? ^ block_given?
|
12
|
+
raise ArgumentError, "You must provide either numeric value or block for Yabeda::Histogram#measure!"
|
13
|
+
end
|
14
|
+
|
15
|
+
if block_given?
|
16
|
+
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
17
|
+
yield
|
18
|
+
value = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting)
|
19
|
+
end
|
20
|
+
|
10
21
|
all_tags = ::Yabeda::Tags.build(tags, group)
|
11
22
|
values[all_tags] = value
|
12
23
|
::Yabeda.adapters.each do |_, adapter|
|
@@ -14,5 +25,6 @@ module Yabeda
|
|
14
25
|
end
|
15
26
|
value
|
16
27
|
end
|
28
|
+
# rubocop: enable Metrics/MethodLength
|
17
29
|
end
|
18
30
|
end
|
data/lib/yabeda/version.rb
CHANGED
data/yabeda-logo.png
ADDED
Binary file
|
data/yabeda.gemspec
CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
|
28
|
+
spec.add_dependency "anyway_config", ">= 1.3", "< 3"
|
28
29
|
spec.add_dependency "concurrent-ruby"
|
29
30
|
spec.add_dependency "dry-initializer"
|
30
31
|
|
metadata
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yabeda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.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: 2021-
|
11
|
+
date: 2021-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: anyway_config
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3'
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: concurrent-ruby
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,6 +153,7 @@ files:
|
|
133
153
|
- bin/setup
|
134
154
|
- lib/yabeda.rb
|
135
155
|
- lib/yabeda/base_adapter.rb
|
156
|
+
- lib/yabeda/config.rb
|
136
157
|
- lib/yabeda/counter.rb
|
137
158
|
- lib/yabeda/dsl.rb
|
138
159
|
- lib/yabeda/dsl/class_methods.rb
|
@@ -147,6 +168,7 @@ files:
|
|
147
168
|
- lib/yabeda/railtie.rb
|
148
169
|
- lib/yabeda/tags.rb
|
149
170
|
- lib/yabeda/version.rb
|
171
|
+
- yabeda-logo.png
|
150
172
|
- yabeda.gemspec
|
151
173
|
homepage: https://github.com/yabeda-rb/yabeda
|
152
174
|
licenses:
|