yabeda-rails 0.4.0 → 0.7.2

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: ac9beead9964f1586249a58f318146802587bfc75879535602276f8ad251266a
4
- data.tar.gz: 880a1219134f862512056785c5b6ed0bc03f50b8a688ca6489f1097a8986b42d
3
+ metadata.gz: e5a74f3febe6bcdda7d43527a9b9acb71434e58f2abc5518b2a68c609541bf89
4
+ data.tar.gz: f223f9a5df2d1a224e77cec0a9e09357eaeccf0532f5a6c4b8859c82ed4ab909
5
5
  SHA512:
6
- metadata.gz: 8e3866ea3c189ccd8c8387b004c93191146a404334a3b39dac8ae4a09e888acf240e8e938003689ab712c4a29c3d589d6f6d957fef0c2c93004cfd76a7c71150
7
- data.tar.gz: 9c1483ceb2c14d6f645678a2e73b0ae43a3a4d0eecf4c7c758586e0ca14999c5f4045fec1fb3bc6fe29c069846a9b96e5ccf068f1d511be1b9cecc77187ec23f
6
+ metadata.gz: 8d2cf3ed506addf2aabcd6bebeaf77fdc80d29ea091a2f8f4d9ef550e3bc74e33a9a4faad6e82ec3ea7f280311a80860f985a6f971fcaa1847b86e7d5907bc95
7
+ data.tar.gz: de1ebbcfbfc3e9423a9033b1080426dd0466e665a9485dd13bc5df4bc60b982c049f156ec8499b38cbca3e26a0ffec2dba571b7f252ee7e7daf299e1ff81070c
@@ -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-rails-${{ steps.tag.outputs.version }}.gem > SHA256SUM
42
+ - name: Check version
43
+ run: ls -l yabeda-rails-${{ 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-rails-${{ steps.tag.outputs.version }}.gem
62
+ asset_name: yabeda-rails-${{ 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-rails-${{ 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-rails-${{ steps.tag.outputs.version }}.gem
@@ -0,0 +1,47 @@
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
+ if: "! contains(toJSON(github.event.commits.latest.message), '[ci skip]')"
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ include:
20
+ - ruby: 3.0
21
+ - ruby: 2.7
22
+ - ruby: 2.6
23
+ - ruby: 2.5
24
+ container:
25
+ image: ruby:${{ matrix.ruby }}
26
+ env:
27
+ CI: true
28
+ steps:
29
+ - uses: actions/checkout@v2
30
+ - uses: actions/cache@v2
31
+ with:
32
+ path: vendor/bundle
33
+ key: bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
34
+ restore-keys: |
35
+ bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
36
+ bundle-${{ matrix.ruby }}-
37
+ - name: Upgrade Bundler to 2.0 (for older Rubies)
38
+ run: gem install bundler -v '~> 2.0'
39
+ - name: Bundle install
40
+ run: |
41
+ bundle config path vendor/bundle
42
+ bundle install
43
+ bundle update
44
+ - name: Run Rubocop
45
+ run: bundle exec rubocop
46
+ - name: Run RSpec
47
+ run: bundle exec rspec
data/.rubocop.yml CHANGED
@@ -3,16 +3,13 @@ require:
3
3
  - rubocop-rspec
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.3
6
+ TargetRubyVersion: 2.4
7
7
 
8
8
  Metrics/BlockLength:
9
9
  Exclude:
10
10
  - "Gemfile"
11
11
  - "spec/**/*"
12
12
 
13
- Style/BracesAroundHashParameters:
14
- EnforcedStyle: context_dependent
15
-
16
13
  Style/StringLiterals:
17
14
  EnforcedStyle: double_quotes
18
15
 
data/CHANGELOG.md CHANGED
@@ -5,6 +5,36 @@ 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.2 - 2021-03-15
9
+
10
+ ### Fixed
11
+
12
+ - Fix undesirable overwrite of metric tags when global `default_tag` is declared with one of tag names that are being used by yabeda-rails, like `controller`. [@liaden] in [#19](https://github.com/yabeda-rb/yabeda-rails/pull/19)
13
+
14
+ ## 0.7.1 - 2020-10-02
15
+
16
+ ### Changed
17
+
18
+ - Explicitly require previously removed railtie to fix case when it doesn't get required in `yabeda` gem (if `yabeda` is required before `rails`). See [yabeda-rb/yabeda#15](https://github.com/yabeda-rb/yabeda/issues/15). @Envek
19
+
20
+ ## 0.7.0 - 2020-08-21
21
+
22
+ ### Removed
23
+
24
+ - Railtie to configure Yabeda – it is moved into Yabeda itself. Increase required Yabeda version to keep behavior for users who require only `yabeda-rails` in their Gemfiles. @Envek
25
+
26
+ ## 0.6.0 - 2020-08-06
27
+
28
+ ### Added
29
+
30
+ - Ability to add default/custom tags to metrics from controllers. @raivil in [#13](https://github.com/yabeda-rb/yabeda-rails/pull/13)
31
+
32
+ ## 0.5.0 - 2020-03-27
33
+
34
+ ### Added
35
+
36
+ - Support for Unicorn application server. @vast in [#9](https://github.com/yabeda-rb/yabeda-rails/pull/9)
37
+
8
38
  ## 0.4.0 - 2020-01-28
9
39
 
10
40
  ### Changed
@@ -34,3 +64,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
34
64
  - Initial release of evil-metrics-rails gem. @Envek
35
65
 
36
66
  Basic metrics for request durations by controller, action, status, format, and method. ActiveRecord and ActionView timings.
67
+
68
+ [@liaden]: https://github.com/liaden "Joel Johnson"
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", "~> 1.8"
15
15
  gem "rubocop-rspec"
16
16
  end
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Yabeda::[Rails]
2
2
 
3
- Built-in metrics for out-of-the box [Rails] applications monitoring
3
+ Built-in metrics for out-of-the box [Rails] applications monitoring.
4
4
 
5
- if your monitoring system already collects Rails metrics (e.g. NewRelic) then you don't need this gem.
5
+ If your monitoring system already collects Rails metrics (e.g. NewRelic) then most probably you don't need this gem.
6
+
7
+ Sample Grafana dashboard ID: [11668](https://grafana.com/grafana/dashboards/11668)
6
8
 
7
9
  ## Installation
8
10
 
@@ -20,7 +22,7 @@ And then execute:
20
22
 
21
23
  ### Registering metrics on server process start
22
24
 
23
- Currently, yabeda-rails automatically registers rails metrics when a server is started via `rails server` or `puma -C config/puma.rb`. However, other application servers or launching via `rackup` aren't supported at the moment.
25
+ Currently, yabeda-rails automatically registers rails metrics when a server is started via `rails server`, `puma -C config/puma.rb` or `unicorn -c`. However, other application servers or launching via `rackup` aren't supported at the moment.
24
26
 
25
27
  A possible workaround is to detect server process and manually activate yabeda-rails in an initializer:
26
28
 
@@ -32,7 +34,7 @@ if your_app_server_process? # Your logic here
32
34
  end
33
35
  ```
34
36
 
35
- You always can add support for your app server to [lib/yabeda/rails/railtie.rb](). Pull Requests are always welcome!
37
+ You always can add support for your app server to [lib/yabeda/rails/railtie.rb](lib/yabeda/rails/railtie.rb). Pull Requests are always welcome!
36
38
 
37
39
 
38
40
  ## Metrics
@@ -55,12 +57,64 @@ You always can add support for your app server to [lib/yabeda/rails/railtie.rb](
55
57
  end
56
58
  ```
57
59
 
60
+ ## Custom tags
61
+
62
+ You can add additional tags to the existing metrics by adding custom payload to your controller.
63
+
64
+ ```ruby
65
+ # This block is optional but some adapters (like Prometheus) requires that all tags should be declared in advance
66
+ Yabeda.configure do
67
+ default_tag :importance, nil
68
+ end
69
+
70
+ class ApplicationController < ActionController::Base
71
+ def append_info_to_payload(payload)
72
+ super
73
+ payload[:importance] = extract_importance(params)
74
+ end
75
+ end
76
+ ```
77
+ `append_info_to_payload` is a method from [ActionController::Instrumentation](https://api.rubyonrails.org/classes/ActionController/Instrumentation.html#method-i-append_info_to_payload)
78
+
79
+
58
80
  ## Development
59
81
 
60
82
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
61
83
 
62
84
  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).
63
85
 
86
+ ### Releasing
87
+
88
+ 1. Bump version number in `lib/yabeda/rails/version.rb`
89
+
90
+ 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::Rails::VERSION).to_s`
91
+
92
+ 2. Fill `CHANGELOG.md` with missing changes, add header with version and date.
93
+
94
+ 3. Make a commit:
95
+
96
+ ```sh
97
+ git add lib/yabeda/rails/version.rb CHANGELOG.md
98
+ version=$(ruby -r ./lib/yabeda/rails/version.rb -e "puts Gem::Version.new(Yabeda::Rails::VERSION)")
99
+ git commit --message="${version}: " --edit
100
+ ```
101
+
102
+ 4. Create annotated tag:
103
+
104
+ ```sh
105
+ git tag v${version} --annotate --message="${version}: " --edit --sign
106
+ ```
107
+
108
+ 5. Fill version name into subject line and (optionally) some description (list of changes will be taken from changelog and appended automatically)
109
+
110
+ 6. Push it:
111
+
112
+ ```sh
113
+ git push --follow-tags
114
+ ```
115
+
116
+ 7. You're done!
117
+
64
118
  ## Contributing
65
119
 
66
120
  Bug reports and pull requests are welcome on GitHub at https://github.com/yabeda-rb/yabeda-rails.
data/lib/yabeda/rails.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "yabeda"
4
+ require "rails"
4
5
  require "yabeda/rails/railtie"
5
6
 
6
7
  module Yabeda
8
+ # Minimal set of Rails-specific metrics for using with Yabeda
7
9
  module Rails
8
10
  LONG_RUNNING_REQUEST_BUCKETS = [
9
11
  0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, # standard
@@ -19,6 +21,8 @@ module Yabeda
19
21
  controller_handlers << block
20
22
  end
21
23
 
24
+ # Declare metrics and install event handlers for collecting themya
25
+ # rubocop: disable Metrics/MethodLength, Metrics/BlockLength, Metrics/AbcSize
22
26
  def install!
23
27
  Yabeda.configure do
24
28
  group :rails
@@ -48,6 +52,7 @@ module Yabeda
48
52
  format: event.payload[:format],
49
53
  method: event.payload[:method].downcase,
50
54
  }
55
+ labels.merge!(event.payload.slice(*Yabeda.default_tags.keys - labels.keys))
51
56
 
52
57
  rails_requests_total.increment(labels)
53
58
  rails_request_duration.measure(labels, Yabeda::Rails.ms2s(event.duration))
@@ -60,9 +65,10 @@ module Yabeda
60
65
  end
61
66
  end
62
67
  end
68
+ # rubocop: enable Metrics/MethodLength, Metrics/BlockLength, Metrics/AbcSize
63
69
 
64
- def ms2s(ms)
65
- (ms.to_f / 1000).round(3)
70
+ def ms2s(milliseconds)
71
+ (milliseconds.to_f / 1000).round(3)
66
72
  end
67
73
  end
68
74
  end
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Explicitly require yabeda's railtie in case if its require was skipped there.
4
+ # See https://github.com/yabeda-rb/yabeda/issues/15
5
+ require "yabeda/railtie"
6
+
3
7
  module Yabeda
4
8
  module Rails
5
9
  class Railtie < ::Rails::Railtie # :nodoc:
@@ -8,12 +12,15 @@ module Yabeda
8
12
  end
9
13
 
10
14
  def puma_server?
11
- ::Rails.const_defined?('Puma::CLI')
15
+ ::Rails.const_defined?("Puma::CLI")
16
+ end
17
+
18
+ def unicorn_server?
19
+ ::Rails.const_defined?("Unicorn::Launcher")
12
20
  end
13
21
 
14
- config.after_initialize do
15
- ::Yabeda::Rails.install! if rails_server? || puma_server?
16
- Yabeda.configure! unless Yabeda.already_configured?
22
+ initializer "yabeda-rails.metrics" do
23
+ ::Yabeda::Rails.install! if rails_server? || puma_server? || unicorn_server?
17
24
  end
18
25
  end
19
26
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yabeda
4
4
  module Rails
5
- VERSION = "0.4.0"
5
+ VERSION = "0.7.2"
6
6
  end
7
7
  end
data/yabeda-rails.gemspec CHANGED
@@ -22,10 +22,12 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_dependency "yabeda", "~> 0.4"
25
+ spec.required_ruby_version = ">= 2.4"
26
+
26
27
  spec.add_dependency "rails"
28
+ spec.add_dependency "yabeda", "~> 0.8"
27
29
 
28
- spec.add_development_dependency "bundler", "~> 1.16"
29
- spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "bundler", "~> 2.0"
31
+ spec.add_development_dependency "rake", "~> 13.0"
30
32
  spec.add_development_dependency "rspec", "~> 3.0"
31
33
  end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yabeda-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.7.2
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: 2021-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: yabeda
14
+ name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.4'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0.4'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rails
28
+ name: yabeda
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '0.8'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '0.8'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.16'
47
+ version: '2.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.16'
54
+ version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -87,10 +87,11 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".github/workflows/build-release.yml"
91
+ - ".github/workflows/test.yml"
90
92
  - ".gitignore"
91
93
  - ".rspec"
92
94
  - ".rubocop.yml"
93
- - ".travis.yml"
94
95
  - CHANGELOG.md
95
96
  - Gemfile
96
97
  - LICENSE.txt
@@ -114,14 +115,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
115
  requirements:
115
116
  - - ">="
116
117
  - !ruby/object:Gem::Version
117
- version: '0'
118
+ version: '2.4'
118
119
  required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  requirements:
120
121
  - - ">="
121
122
  - !ruby/object:Gem::Version
122
123
  version: '0'
123
124
  requirements: []
124
- rubygems_version: 3.0.3
125
+ rubygems_version: 3.1.4
125
126
  signing_key:
126
127
  specification_version: 4
127
128
  summary: Extensible metrics for monitoring Ruby on Rails application
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.5.1
5
- before_install: gem install bundler -v 1.16.1