yabeda 0.6.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build-release.yml +82 -0
- data/.github/workflows/test.yml +46 -0
- data/CHANGELOG.md +38 -1
- data/README.md +87 -6
- data/lib/yabeda.rb +11 -4
- data/lib/yabeda/counter.rb +1 -1
- data/lib/yabeda/dsl/class_methods.rb +16 -6
- data/lib/yabeda/gauge.rb +9 -1
- data/lib/yabeda/global_group.rb +13 -0
- data/lib/yabeda/group.rb +10 -0
- data/lib/yabeda/histogram.rb +1 -1
- data/lib/yabeda/metric.rb +4 -2
- data/lib/yabeda/railtie.rb +11 -0
- data/lib/yabeda/tags.rb +6 -2
- data/lib/yabeda/version.rb +1 -1
- metadata +10 -7
- data/.travis.yml +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a4867a0d04b93eebd708a3fcf4b21797194066c26e2a96809b85c2139926be9
|
4
|
+
data.tar.gz: 78a8e47cf194e30641c285505a199465518d5f6e0d1b73c07b4f4222bc2e5f31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f05aeeec7451c222ebe6713da7ddca289b1922ff294f3acd0ad8350647e996173ac5c2a642445011cf8549cfc3db4e9a8d804ab74da4cc946e536b14ffa773e
|
7
|
+
data.tar.gz: d8e3b98d6889f4af3af3273c9e8abfc876b778eeb2bddd94babf9489dcb421d4ab5412f58b293026e6ecffc066ea3eaa42b6965192a5fa22b928a246e9a75de2
|
@@ -0,0 +1,82 @@
|
|
1
|
+
name: Build and release gem to RubyGems
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags:
|
6
|
+
- v*
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
release:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
with:
|
14
|
+
fetch-depth: 0 # Fetch current tag as annotated. See https://github.com/actions/checkout/issues/290
|
15
|
+
- uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: 2.7
|
18
|
+
- name: "Extract data from tag: version, message, body"
|
19
|
+
id: tag
|
20
|
+
run: |
|
21
|
+
git fetch --tags --force # Really fetch annotated tag. See https://github.com/actions/checkout/issues/290#issuecomment-680260080
|
22
|
+
echo ::set-output name=version::${GITHUB_REF#refs/tags/v}
|
23
|
+
echo ::set-output name=subject::$(git for-each-ref $GITHUB_REF --format='%(contents:subject)')
|
24
|
+
BODY="$(git for-each-ref $GITHUB_REF --format='%(contents:body)')"
|
25
|
+
# Extract changelog entries between this and previous version headers
|
26
|
+
escaped_version=$(echo ${GITHUB_REF#refs/tags/v} | sed -e 's/[]\/$*.^[]/\\&/g')
|
27
|
+
changelog=$(awk "BEGIN{inrelease=0} /## ${escaped_version}/{inrelease=1;next} /## [0-9]+\.[0-9]+\.[0-9]+/{inrelease=0;exit} {if (inrelease) print}" CHANGELOG.md)
|
28
|
+
# Multiline body for release. See https://github.community/t/set-output-truncates-multiline-strings/16852/5
|
29
|
+
BODY="${BODY}"$'\n'"${changelog}"
|
30
|
+
BODY="${BODY//'%'/'%25'}"
|
31
|
+
BODY="${BODY//$'\n'/'%0A'}"
|
32
|
+
BODY="${BODY//$'\r'/'%0D'}"
|
33
|
+
echo "::set-output name=body::$BODY"
|
34
|
+
# Add pre-release option if tag name has any suffix after vMAJOR.MINOR.PATCH
|
35
|
+
if [[ ${GITHUB_REF#refs/tags/} =~ ^v[0-9]+\.[0-9]+\.[0-9]+.+ ]]; then
|
36
|
+
echo ::set-output name=prerelease::true
|
37
|
+
fi
|
38
|
+
- name: Build gem
|
39
|
+
run: gem build
|
40
|
+
- name: Calculate checksums
|
41
|
+
run: sha256sum yabeda-${{ steps.tag.outputs.version }}.gem > SHA256SUM
|
42
|
+
- name: Check version
|
43
|
+
run: ls -l yabeda-${{ steps.tag.outputs.version }}.gem
|
44
|
+
- name: Create Release
|
45
|
+
id: create_release
|
46
|
+
uses: actions/create-release@v1
|
47
|
+
env:
|
48
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
49
|
+
with:
|
50
|
+
tag_name: ${{ github.ref }}
|
51
|
+
release_name: ${{ steps.tag.outputs.subject }}
|
52
|
+
body: ${{ steps.tag.outputs.body }}
|
53
|
+
draft: false
|
54
|
+
prerelease: ${{ steps.tag.outputs.prerelease }}
|
55
|
+
- name: Upload built gem as release asset
|
56
|
+
uses: actions/upload-release-asset@v1
|
57
|
+
env:
|
58
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
59
|
+
with:
|
60
|
+
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
61
|
+
asset_path: yabeda-${{ steps.tag.outputs.version }}.gem
|
62
|
+
asset_name: yabeda-${{ steps.tag.outputs.version }}.gem
|
63
|
+
asset_content_type: application/x-tar
|
64
|
+
- name: Upload checksums as release asset
|
65
|
+
uses: actions/upload-release-asset@v1
|
66
|
+
env:
|
67
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
68
|
+
with:
|
69
|
+
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
70
|
+
asset_path: SHA256SUM
|
71
|
+
asset_name: SHA256SUM
|
72
|
+
asset_content_type: text/plain
|
73
|
+
- name: Publish to GitHub packages
|
74
|
+
env:
|
75
|
+
GEM_HOST_API_KEY: Bearer ${{ secrets.GITHUB_TOKEN }}
|
76
|
+
run: |
|
77
|
+
gem push yabeda-${{ steps.tag.outputs.version }}.gem --host https://rubygems.pkg.github.com/${{ github.repository_owner }}
|
78
|
+
- name: Publish to RubyGems
|
79
|
+
env:
|
80
|
+
GEM_HOST_API_KEY: "${{ secrets.RUBYGEMS_API_KEY }}"
|
81
|
+
run: |
|
82
|
+
gem push yabeda-${{ steps.tag.outputs.version }}.gem
|
@@ -0,0 +1,46 @@
|
|
1
|
+
name: Run tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
push:
|
6
|
+
branches:
|
7
|
+
- '**'
|
8
|
+
tags-ignore:
|
9
|
+
- 'v*'
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
test:
|
13
|
+
name: "Run tests"
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
strategy:
|
16
|
+
fail-fast: false
|
17
|
+
matrix:
|
18
|
+
include:
|
19
|
+
- ruby: 3.0
|
20
|
+
- ruby: 2.7
|
21
|
+
- ruby: 2.6
|
22
|
+
- ruby: 2.5
|
23
|
+
container:
|
24
|
+
image: ruby:${{ matrix.ruby }}
|
25
|
+
env:
|
26
|
+
CI: true
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v2
|
29
|
+
- uses: actions/cache@v2
|
30
|
+
with:
|
31
|
+
path: vendor/bundle
|
32
|
+
key: bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
|
33
|
+
restore-keys: |
|
34
|
+
bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
|
35
|
+
bundle-${{ matrix.ruby }}-
|
36
|
+
- name: Upgrade Bundler to 2.0 (for older Rubies)
|
37
|
+
run: gem install bundler -v '~> 2.0'
|
38
|
+
- name: Bundle install
|
39
|
+
run: |
|
40
|
+
bundle config path vendor/bundle
|
41
|
+
bundle install
|
42
|
+
bundle update
|
43
|
+
- name: Run Rubocop
|
44
|
+
run: bundle exec rubocop
|
45
|
+
- name: Run RSpec
|
46
|
+
run: bundle exec rspec
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,41 @@ 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.9.0 - 2021-05-07
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Ability to set global metric tags only for a specific group [#19](https://github.com/yabeda-rb/yabeda/pull/19) by [@liaden]
|
13
|
+
|
14
|
+
## 0.8.0 - 2020-08-21
|
15
|
+
|
16
|
+
### Added
|
17
|
+
|
18
|
+
- Added railtie to automatically configure Yabeda on Rails: moved from [yabeda-rails](https://github.com/yabeda-rb/yabeda-rails) gem. [@Envek]
|
19
|
+
|
20
|
+
## 0.7.0 - 2020-08-07
|
21
|
+
|
22
|
+
### Added
|
23
|
+
|
24
|
+
- `#increment` and `#decrement` convenience methods for `Yabeda::Gauge`. [#13](https://github.com/yabeda-rb/yabeda/pull/13) by [@dsalahutdinov]
|
25
|
+
- Ability to use custom step in `#increment` and `#decrement` for gauges. [@Envek]
|
26
|
+
|
27
|
+
### Fixed
|
28
|
+
|
29
|
+
- Account for default tags in `Yabeda::Metric#get`. [@Envek]
|
30
|
+
|
31
|
+
## 0.6.2 - 2020-08-04
|
32
|
+
|
33
|
+
### Fixed
|
34
|
+
|
35
|
+
- 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]
|
36
|
+
|
37
|
+
## 0.6.1 - 2020-07-16
|
38
|
+
|
39
|
+
### Fixed
|
40
|
+
|
41
|
+
- 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]
|
42
|
+
|
8
43
|
## 0.6.0 - 2020-07-15
|
9
44
|
|
10
45
|
### Added
|
@@ -55,7 +90,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
55
90
|
|
56
91
|
### Fixed
|
57
92
|
|
58
|
-
- Removed accidental dependency from Rails. @dsalahutdinov
|
93
|
+
- Removed accidental dependency from Rails. [@dsalahutdinov]
|
59
94
|
|
60
95
|
## 0.1.1 - 2018-10-17
|
61
96
|
|
@@ -68,4 +103,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
68
103
|
- Initial release of evil-metrics gem. @Envek
|
69
104
|
|
70
105
|
[@Envek]: https://github.com/Envek "Andrey Novikov"
|
106
|
+
[@dsalahutdinov]: https://github.com/dsalahutdinov "Dmitry Salahutdinov"
|
71
107
|
[@asusikov]: https://github.com/asusikov "Alexander Susikov"
|
108
|
+
[@liaden]: https://github.com/liaden "Joel Johnson"
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Yabeda
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/yabeda.svg)](https://rubygems.org/gems/yabeda)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/yabeda.svg)](https://rubygems.org/gems/yabeda)
|
4
4
|
|
5
5
|
**This software is Work in Progress: features will appear and disappear, API will be changed, your feedback is always welcome!**
|
6
6
|
|
@@ -49,7 +49,7 @@ And then execute:
|
|
49
49
|
Yabeda.configure!
|
50
50
|
```
|
51
51
|
|
52
|
-
|
52
|
+
_If you're using Ruby on Rails then it will be configured automatically!_
|
53
53
|
|
54
54
|
3. Access metric in your app and use it!
|
55
55
|
|
@@ -79,10 +79,14 @@ And then execute:
|
|
79
79
|
end
|
80
80
|
```
|
81
81
|
|
82
|
-
5. _Optionally_ setup default tags
|
82
|
+
5. _Optionally_ setup default tags for all appropriate metrics
|
83
83
|
```ruby
|
84
84
|
Yabeda.configure do
|
85
|
+
# matches all metrics in all groups
|
85
86
|
default_tag :rails_environment, 'production'
|
87
|
+
|
88
|
+
# matches all metrics in the :your_app group
|
89
|
+
default_tag :tag_name, 'override', group: :your_app
|
86
90
|
end
|
87
91
|
|
88
92
|
# You can redefine them for limited amount of time
|
@@ -91,17 +95,58 @@ And then execute:
|
|
91
95
|
end
|
92
96
|
```
|
93
97
|
|
94
|
-
|
95
|
-
|
98
|
+
**Note**: any usage of `with_tags` **must** have all those tags defined on all metrics that are generated in the block.
|
99
|
+
|
100
|
+
6. _Optionally_ override default tags using precedence:
|
101
|
+
|
102
|
+
The tag precedence from high to low is:
|
103
|
+
|
104
|
+
* Manually specified tags
|
105
|
+
* Thread local tags (specified by `Yabeda.with_tags`)
|
106
|
+
* Group specific tags
|
107
|
+
* Global tags
|
108
|
+
|
109
|
+
7. See the docs for the adapter you're using
|
110
|
+
8. Enjoy!
|
96
111
|
|
97
112
|
## Available monitoring system adapters
|
98
113
|
|
99
|
-
|
114
|
+
### Maintained by Yabeda
|
115
|
+
|
116
|
+
- Prometheus:
|
117
|
+
- [yabeda-prometheus](https://github.com/yabeda-rb/yabeda-prometheus) — wraps [official Ruby client for Prometheus](https://github.com/prometheus/client_ruby).
|
118
|
+
- [yabeda-prometheus-mmap](https://github.com/yabeda-rb/yabeda-prometheus-mmap) — wraps [GitLab's fork of Prometheus Ruby client](https://gitlab.com/gitlab-org/prometheus-client-mmap) which may work better for multi-process application servers.
|
100
119
|
- [Datadog](https://github.com/yabeda-rb/yabeda-datadog)
|
101
120
|
- [NewRelic](https://github.com/yabeda-rb/yabeda-newrelic)
|
121
|
+
|
122
|
+
### Third-party adapters
|
123
|
+
|
124
|
+
These are developed and maintained by other awesome folks:
|
125
|
+
|
102
126
|
- [Statsd](https://github.com/asusikov/yabeda-statsd)
|
103
127
|
- _…and more! You can write your own adapter and open a pull request to add it into this list._
|
104
128
|
|
129
|
+
## Available plugins to collect metrics
|
130
|
+
|
131
|
+
### Maintained by Yabeda
|
132
|
+
|
133
|
+
- [yabeda-rails] — basic request metrics for [Ruby on Rails](https://rubyonrails.org/) applications.
|
134
|
+
- [yabeda-sidekiq] — comprehensive set of metrics for monitoring [Sidekiq](https://sidekiq.org/) jobs execution and queues.
|
135
|
+
- [yabeda-faktory] — metrics for monitoring jobs execution by Ruby workers of [Faktory](https://contribsys.com/faktory/).
|
136
|
+
- [yabeda-graphql] — metrics to query and field-level monitoring for apps using [GraphQL-Ruby](https://graphql-ruby.org/).
|
137
|
+
- [yabeda-puma-plugin] — metrics for internal state and performance of [Puma](https://puma.io/) application server.
|
138
|
+
- [yabeda-http_requests] — monitor how many outgoing HTTP calls your application does (uses [Sniffer](https://github.com/aderyabin/sniffer)).
|
139
|
+
- [yabeda-schked] — monitor number and duration of Cron jobs executed by [Schked](https://github.com/bibendi/schked).
|
140
|
+
|
141
|
+
### Third-party plugins
|
142
|
+
|
143
|
+
These are developed and maintained by other awesome folks:
|
144
|
+
|
145
|
+
- [yabeda-grape](https://github.com/efigence/yabeda-grape) — metrics for [Grape](https://github.com/ruby-grape/grape) framework.
|
146
|
+
- [yabeda-gruf](https://github.com/Placewise/yabeda-gruf) — metrics for [gRPC Ruby Framework](https://github.com/bigcommerce/gruf)
|
147
|
+
- [yabeda-gc](https://github.com/ianks/yabeda-gc) — metrics for Ruby garbage collection.
|
148
|
+
- _…and more! You can write your own adapter and open a pull request to add it into this list._
|
149
|
+
|
105
150
|
## Roadmap (aka TODO or Help wanted)
|
106
151
|
|
107
152
|
- Ability to change metric settings for individual adapters
|
@@ -130,6 +175,36 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
130
175
|
|
131
176
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
132
177
|
|
178
|
+
### Releasing
|
179
|
+
|
180
|
+
1. Bump version number in `lib/yabeda/version.rb`
|
181
|
+
|
182
|
+
In case of pre-releases keep in mind [rubygems/rubygems#3086](https://github.com/rubygems/rubygems/issues/3086) and check version with command like `Gem::Version.new(Yabeda::VERSION).to_s`
|
183
|
+
|
184
|
+
2. Fill `CHANGELOG.md` with missing changes, add header with version and date.
|
185
|
+
|
186
|
+
3. Make a commit:
|
187
|
+
|
188
|
+
```sh
|
189
|
+
git add lib/yabeda/version.rb CHANGELOG.md
|
190
|
+
version=$(ruby -r ./lib/yabeda/version.rb -e "puts Gem::Version.new(Yabeda::VERSION)")
|
191
|
+
git commit --message="${version}: " --edit
|
192
|
+
```
|
193
|
+
|
194
|
+
3. Create annotated tag:
|
195
|
+
|
196
|
+
```sh
|
197
|
+
git tag v${version} --annotate --message="${version}: " --edit --sign
|
198
|
+
```
|
199
|
+
|
200
|
+
4. Fill version name into subject line and (optionally) some description (changes will be taken from changelog and appended automatically)
|
201
|
+
|
202
|
+
5. Push it:
|
203
|
+
|
204
|
+
```sh
|
205
|
+
git push --follow-tags
|
206
|
+
```
|
207
|
+
|
133
208
|
## Contributing
|
134
209
|
|
135
210
|
Bug reports and pull requests are welcome on GitHub at https://github.com/yabeda-rb/yabeda.
|
@@ -139,3 +214,9 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/yabeda
|
|
139
214
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
140
215
|
|
141
216
|
[yabeda-rails]: https://github.com/yabeda-rb/yabeda-rails/ "Yabeda plugin for collecting and exporting basic metrics for Rails applications"
|
217
|
+
[yabeda-sidekiq]: https://github.com/yabeda-rb/yabeda-sidekiq/ "Yabeda plugin for complete monitoring of Sidekiq metrics"
|
218
|
+
[yabeda-faktory]: https://github.com/yabeda-rb/yabeda-faktory/ "Yabeda plugin for complete monitoring of Faktory Ruby Workers"
|
219
|
+
[yabeda-graphql]: https://github.com/yabeda-rb/yabeda-graphql/ "Measure and understand how good your GraphQL-Ruby application works"
|
220
|
+
[yabeda-puma-plugin]: https://github.com/yabeda-rb/yabeda-puma-plugin/ "Collects Puma web-server metrics from puma control application"
|
221
|
+
[yabeda-http_requests]: https://github.com/yabeda-rb/yabeda-http_requests/ "Builtin metrics to monitor external HTTP requests"
|
222
|
+
[yabeda-schked]: https://github.com/yabeda-rb/yabeda-schked/ "Built-in metrics for monitoring Schked recurring jobs out of the box"
|
data/lib/yabeda.rb
CHANGED
@@ -6,6 +6,7 @@ require "yabeda/version"
|
|
6
6
|
require "yabeda/dsl"
|
7
7
|
require "yabeda/tags"
|
8
8
|
require "yabeda/errors"
|
9
|
+
require "yabeda/railtie" if defined?(Rails)
|
9
10
|
|
10
11
|
# Extendable framework for collecting and exporting metrics from Ruby apps
|
11
12
|
module Yabeda
|
@@ -19,7 +20,9 @@ module Yabeda
|
|
19
20
|
|
20
21
|
# @return [Hash<String, Yabeda::Group>] All registered metrics
|
21
22
|
def groups
|
22
|
-
@groups ||= Concurrent::Hash.new
|
23
|
+
@groups ||= Concurrent::Hash.new.tap do |hash|
|
24
|
+
hash[nil] = Yabeda::GlobalGroup.new(nil)
|
25
|
+
end
|
23
26
|
end
|
24
27
|
|
25
28
|
# @return [Hash<String, Yabeda::BaseAdapter>] All loaded adapters
|
@@ -32,7 +35,7 @@ module Yabeda
|
|
32
35
|
@collectors ||= Concurrent::Array.new
|
33
36
|
end
|
34
37
|
|
35
|
-
# @return [Hash<Symbol, Symbol>] All added default tags
|
38
|
+
# @return [Hash<Symbol, Symbol>] All added global default tags
|
36
39
|
def default_tags
|
37
40
|
@default_tags ||= Concurrent::Hash.new
|
38
41
|
end
|
@@ -85,14 +88,18 @@ module Yabeda
|
|
85
88
|
# Forget all the configuration.
|
86
89
|
# For testing purposes as it doesn't rollback changes in adapters.
|
87
90
|
# @api private
|
91
|
+
# rubocop: disable Metrics/AbcSize
|
88
92
|
def reset!
|
89
93
|
default_tags.clear
|
90
94
|
adapters.clear
|
91
|
-
groups.
|
92
|
-
|
95
|
+
groups.each_key { |group| singleton_class.send(:remove_method, group) if group && respond_to?(group) }
|
96
|
+
@groups = nil
|
97
|
+
metrics.each_key { |metric| singleton_class.send(:remove_method, metric) if respond_to?(metric) }
|
98
|
+
@metrics = nil
|
93
99
|
collectors.clear
|
94
100
|
configurators.clear
|
95
101
|
instance_variable_set(:@configured_by, nil)
|
96
102
|
end
|
103
|
+
# rubocop: enable Metrics/AbcSize
|
97
104
|
end
|
98
105
|
end
|
data/lib/yabeda/counter.rb
CHANGED
@@ -4,7 +4,7 @@ module Yabeda
|
|
4
4
|
# Growing-only counter
|
5
5
|
class Counter < Metric
|
6
6
|
def increment(tags, by: 1)
|
7
|
-
all_tags = ::Yabeda::Tags.build(tags)
|
7
|
+
all_tags = ::Yabeda::Tags.build(tags, group)
|
8
8
|
values[all_tags] += by
|
9
9
|
::Yabeda.adapters.each do |_, adapter|
|
10
10
|
adapter.perform_counter_increment!(self, all_tags, by)
|
@@ -5,6 +5,7 @@ require "yabeda/counter"
|
|
5
5
|
require "yabeda/gauge"
|
6
6
|
require "yabeda/histogram"
|
7
7
|
require "yabeda/group"
|
8
|
+
require "yabeda/global_group"
|
8
9
|
require "yabeda/dsl/metric_builder"
|
9
10
|
|
10
11
|
module Yabeda
|
@@ -30,6 +31,7 @@ module Yabeda
|
|
30
31
|
# (like NewRelic) it is treated individually and has a special meaning.
|
31
32
|
def group(group_name)
|
32
33
|
@group = group_name
|
34
|
+
Yabeda.groups[@group] ||= Yabeda::Group.new(@group)
|
33
35
|
return unless block_given?
|
34
36
|
|
35
37
|
yield
|
@@ -58,24 +60,30 @@ module Yabeda
|
|
58
60
|
#
|
59
61
|
# @param name [Symbol] Name of default tag
|
60
62
|
# @param value [String] Value of default tag
|
61
|
-
def default_tag(name, value)
|
62
|
-
|
63
|
+
def default_tag(name, value, group: @group)
|
64
|
+
if group
|
65
|
+
Yabeda.groups[group] ||= Yabeda::Group.new(group)
|
66
|
+
Yabeda.groups[group].default_tag(name, value)
|
67
|
+
else
|
68
|
+
Yabeda.default_tags[name] = value
|
69
|
+
end
|
63
70
|
end
|
64
71
|
|
65
72
|
# Redefine default tags for a limited amount of time
|
66
73
|
# @param tags Hash{Symbol=>#to_s}
|
67
74
|
def with_tags(**tags)
|
68
|
-
|
75
|
+
previous_temp_tags = temporary_tags
|
76
|
+
Thread.current[:yabeda_temporary_tags] = Thread.current[:yabeda_temporary_tags].merge(tags)
|
69
77
|
yield
|
70
78
|
ensure
|
71
|
-
Thread.current[:yabeda_temporary_tags] =
|
79
|
+
Thread.current[:yabeda_temporary_tags] = previous_temp_tags
|
72
80
|
end
|
73
81
|
|
74
82
|
# Get tags set by +with_tags+
|
75
83
|
# @api private
|
76
84
|
# @return Hash
|
77
85
|
def temporary_tags
|
78
|
-
Thread.current[:yabeda_temporary_tags]
|
86
|
+
Thread.current[:yabeda_temporary_tags] ||= {}
|
79
87
|
end
|
80
88
|
|
81
89
|
private
|
@@ -85,6 +93,7 @@ module Yabeda
|
|
85
93
|
::Yabeda.define_singleton_method(name) { metric }
|
86
94
|
::Yabeda.metrics[name] = metric
|
87
95
|
register_group_for(metric) if metric.group
|
96
|
+
::Yabeda.adapters.each_value { |adapter| adapter.register!(metric) } if ::Yabeda.configured?
|
88
97
|
metric
|
89
98
|
end
|
90
99
|
|
@@ -94,9 +103,10 @@ module Yabeda
|
|
94
103
|
if group.nil?
|
95
104
|
group = Group.new(metric.group)
|
96
105
|
::Yabeda.groups[metric.group] = group
|
97
|
-
::Yabeda.define_singleton_method(metric.group) { group }
|
98
106
|
end
|
99
107
|
|
108
|
+
::Yabeda.define_singleton_method(metric.group) { group } unless ::Yabeda.respond_to?(metric.group)
|
109
|
+
|
100
110
|
group.register_metric(metric)
|
101
111
|
end
|
102
112
|
end
|
data/lib/yabeda/gauge.rb
CHANGED
@@ -4,12 +4,20 @@ module Yabeda
|
|
4
4
|
# Arbitrary value, can be changed in both sides
|
5
5
|
class Gauge < Metric
|
6
6
|
def set(tags, value)
|
7
|
-
all_tags = ::Yabeda::Tags.build(tags)
|
7
|
+
all_tags = ::Yabeda::Tags.build(tags, group)
|
8
8
|
values[all_tags] = value
|
9
9
|
::Yabeda.adapters.each do |_, adapter|
|
10
10
|
adapter.perform_gauge_set!(self, all_tags, value)
|
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
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "forwardable"
|
4
|
+
require_relative "./group"
|
5
|
+
|
6
|
+
module Yabeda
|
7
|
+
# Represents implicit global group
|
8
|
+
class GlobalGroup < Group
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
def_delegators ::Yabeda, :default_tags, :default_tag
|
12
|
+
end
|
13
|
+
end
|
data/lib/yabeda/group.rb
CHANGED
@@ -9,6 +9,16 @@ module Yabeda
|
|
9
9
|
|
10
10
|
param :name
|
11
11
|
|
12
|
+
def default_tags
|
13
|
+
@default_tags ||= Concurrent::Hash.new
|
14
|
+
::Yabeda.default_tags.merge(@default_tags)
|
15
|
+
end
|
16
|
+
|
17
|
+
def default_tag(key, value)
|
18
|
+
@default_tags ||= Concurrent::Hash.new
|
19
|
+
@default_tags[key] = value
|
20
|
+
end
|
21
|
+
|
12
22
|
def register_metric(metric)
|
13
23
|
define_singleton_method(metric.name) { metric }
|
14
24
|
end
|
data/lib/yabeda/histogram.rb
CHANGED
@@ -7,7 +7,7 @@ module Yabeda
|
|
7
7
|
option :buckets
|
8
8
|
|
9
9
|
def measure(tags, value)
|
10
|
-
all_tags = ::Yabeda::Tags.build(tags)
|
10
|
+
all_tags = ::Yabeda::Tags.build(tags, group)
|
11
11
|
values[all_tags] = value
|
12
12
|
::Yabeda.adapters.each do |_, adapter|
|
13
13
|
adapter.perform_histogram_measure!(self, all_tags, value)
|
data/lib/yabeda/metric.rb
CHANGED
@@ -17,15 +17,17 @@ module Yabeda
|
|
17
17
|
|
18
18
|
# Returns the value for the given label set
|
19
19
|
def get(labels = {})
|
20
|
-
values[labels]
|
20
|
+
values[::Yabeda::Tags.build(labels, group)]
|
21
21
|
end
|
22
22
|
|
23
23
|
def values
|
24
24
|
@values ||= Concurrent::Hash.new
|
25
25
|
end
|
26
26
|
|
27
|
+
# Returns allowed tags for metric (with account for global and group-level +default_tags+)
|
28
|
+
# @return Array<Symbol>
|
27
29
|
def tags
|
28
|
-
(Yabeda.default_tags.keys + Array(super)).uniq
|
30
|
+
(Yabeda.groups[group].default_tags.keys + Array(super)).uniq
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
data/lib/yabeda/tags.rb
CHANGED
@@ -3,8 +3,12 @@
|
|
3
3
|
module Yabeda
|
4
4
|
# Class to merge tags
|
5
5
|
class Tags
|
6
|
-
def self.build(tags)
|
7
|
-
|
6
|
+
def self.build(tags, group_name = nil)
|
7
|
+
Yabeda.default_tags.dup.tap do |result|
|
8
|
+
result.merge!(Yabeda.groups[group_name].default_tags) if group_name
|
9
|
+
result.merge!(Yabeda.temporary_tags)
|
10
|
+
result.merge!(tags)
|
11
|
+
end
|
8
12
|
end
|
9
13
|
end
|
10
14
|
end
|
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.9.0
|
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:
|
11
|
+
date: 2021-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -118,10 +118,11 @@ executables: []
|
|
118
118
|
extensions: []
|
119
119
|
extra_rdoc_files: []
|
120
120
|
files:
|
121
|
+
- ".github/workflows/build-release.yml"
|
122
|
+
- ".github/workflows/test.yml"
|
121
123
|
- ".gitignore"
|
122
124
|
- ".rspec"
|
123
125
|
- ".rubocop.yml"
|
124
|
-
- ".travis.yml"
|
125
126
|
- ".yardopts"
|
126
127
|
- CHANGELOG.md
|
127
128
|
- Gemfile
|
@@ -139,9 +140,11 @@ files:
|
|
139
140
|
- lib/yabeda/dsl/option_builder.rb
|
140
141
|
- lib/yabeda/errors.rb
|
141
142
|
- lib/yabeda/gauge.rb
|
143
|
+
- lib/yabeda/global_group.rb
|
142
144
|
- lib/yabeda/group.rb
|
143
145
|
- lib/yabeda/histogram.rb
|
144
146
|
- lib/yabeda/metric.rb
|
147
|
+
- lib/yabeda/railtie.rb
|
145
148
|
- lib/yabeda/tags.rb
|
146
149
|
- lib/yabeda/version.rb
|
147
150
|
- yabeda.gemspec
|
@@ -149,7 +152,7 @@ homepage: https://github.com/yabeda-rb/yabeda
|
|
149
152
|
licenses:
|
150
153
|
- MIT
|
151
154
|
metadata: {}
|
152
|
-
post_install_message:
|
155
|
+
post_install_message:
|
153
156
|
rdoc_options: []
|
154
157
|
require_paths:
|
155
158
|
- lib
|
@@ -164,8 +167,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
167
|
- !ruby/object:Gem::Version
|
165
168
|
version: '0'
|
166
169
|
requirements: []
|
167
|
-
rubygems_version: 3.1.
|
168
|
-
signing_key:
|
170
|
+
rubygems_version: 3.1.6
|
171
|
+
signing_key:
|
169
172
|
specification_version: 4
|
170
173
|
summary: Extensible framework for collecting metric for your Ruby application
|
171
174
|
test_files: []
|