yabeda-prometheus 0.5.0 → 0.7.0

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: 59af7a9f1de7593f49c9d58f1f9517c15182a7000d86d1076fa06297371013e2
4
- data.tar.gz: 470bb2054c3f3281754ba07c7fd3217c83213c139150c27dd52c0d5ee8577b02
3
+ metadata.gz: c36a4a73e4e698126e81bf8cb5069de6521ac396742a59dc13a906b2e6470f12
4
+ data.tar.gz: 67b7b8d5d56cff197c47bbac7b27d9a3eefe3cbbc1f63a01d8d35d2d4cd97305
5
5
  SHA512:
6
- metadata.gz: 1fef847b5af1e283109303d04b3b9df56b8439a120dcad11ab7934dc5102147cd5fca35ae2719e05dd5d06c6ff06b752bcd566a3e13dd6bf26e64b0dec83e37b
7
- data.tar.gz: 25e463b8f562504d21e856c99192ec516aec2dacf6faa75b20266d78421252a09ab57e57135f529189add2a8c78fafa9a7803b91949c0a3488a00030f92a7bfb
6
+ metadata.gz: 25eae376eda44fd094891a717efaf877bd629b7ae9fcb0867ecf146fd0ea70e1afc7df3d24f8e615c4be11081004719de67bbfd89cacdeb011e51d74a331f1b4
7
+ data.tar.gz: 7184e70ea9a35daaf7b29e4fc8e2f9fd18e6b89679d1a4ebcb97722e359853e5723ace3a17cc3fb4a132947f758f2a4e88ccd6a8fe30bd7b48ff5d0872d46de4
@@ -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-prometheus-${{ steps.tag.outputs.version }}.gem > SHA256SUM
42
+ - name: Check version
43
+ run: ls -l yabeda-prometheus-${{ 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-prometheus-${{ steps.tag.outputs.version }}.gem
62
+ asset_name: yabeda-prometheus-${{ 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-prometheus-${{ 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-prometheus-${{ steps.tag.outputs.version }}.gem
@@ -0,0 +1,45 @@
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(github.event.head_commit.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 RSpec
45
+ run: bundle exec rspec
data/CHANGELOG.md CHANGED
@@ -5,6 +5,37 @@ 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.7.0 - 2021-07-21
11
+
12
+ ### Added
13
+
14
+ - Debug mode with metric `yabeda_prometheus_render_duration` to measure how long takes to render response with already collected metrics for Prometheus. Requires Yabeda 0.10+. [@Envek], [@dsalahutdinov]
15
+
16
+ ### Changed
17
+
18
+ - Yabeda 0.10.0 or newer is required. [@Envek]
19
+
20
+ ## 0.6.2 - 2021-06-23
21
+
22
+ ### Fixed
23
+
24
+ - Fix `uninitialized constant Yabeda::Rack::Handler (NameError)` when using [yabeda-rack-attack](https://github.com/dsalahutdinov/yabeda-rack-attack). [@dsalahutdinov]
25
+
26
+ ## 0.6.1 - 2020-04-28
27
+
28
+ ### Changed
29
+
30
+ - Fixed issue with Push Gateway require. [#13](https://github.com/yabeda-rb/yabeda-prometheus/pull/13) by [@baarkerlounger].
31
+ - Fixed possible issue with rack absense in non-web applications. Declared it as a dependency. [@Envek]
32
+
33
+ ## 0.6.0 - 2020-04-15
34
+
35
+ ### Changed
36
+
37
+ - Relaxed version constraints for prometheus-client as [v2.0.0](https://github.com/prometheus/client_ruby/releases/tag/v2.0.0) doesn't break APIs. @Envek
38
+
8
39
  ## 0.5.0 - 2020-01-29
9
40
 
10
41
  ### Added
@@ -93,4 +124,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
93
124
 
94
125
  - Initial release of evil-metrics-prometheus gem. @Envek
95
126
 
127
+ [@Envek]: https://github.com/Envek "Andrey Novikov"
96
128
  [@alexander37137]: https://github.com/alexander37137 "Alexander Andreev"
129
+ [@baarkerlounger]: https://github.com/baarkerlounger "Daniel Baark"
130
+ [@dsalahutdinov]: https://github.com/dsalahutdinov "Dmitry Salahutdinov"
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Yabeda::[Prometheus]
1
+ # ![`Yabeda::Prometheus`](./yabeda-prometheus-logo.png)
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/yabeda-prometheus.svg)](https://rubygems.org/gems/yabeda-prometheus)
4
4
 
@@ -48,6 +48,8 @@ And then execute:
48
48
 
49
49
  WEBrick will be launched in separate thread and will serve metrics on `/metrics` path.
50
50
 
51
+ > **ATTENTION**: Starting from Ruby 3.0 WEBrick isn't included with Ruby by default. You should either add `gem "webrick"` into your Gemfile or launch `Yabeda::Prometheus::Exporter.rack_app` with application server of your choice.
52
+
51
53
  See [yabeda-sidekiq] for example.
52
54
 
53
55
  Listening address is configured via `PROMETHEUS_EXPORTER_BIND` env variable (default is `0.0.0.0`).
@@ -86,6 +88,12 @@ group :some do
86
88
  end
87
89
  ```
88
90
 
91
+ ## Debugging metrics
92
+
93
+ - Time of already collected metrics rendering in response for Prometheus: `yabeda_prometheus_render_duration`.
94
+
95
+ These are only enabled in debug mode. See [Yabeda debugging metrics](https://github.com/yabeda-rb/yabeda#debugging-metrics) on how to enable it (e.g. by specifying `YABEDA_DEBUG=true` in your environment variables).
96
+
89
97
  ## Development
90
98
 
91
99
  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.
@@ -96,6 +104,38 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
96
104
 
97
105
  Bug reports and pull requests are welcome on GitHub at https://github.com/yabeda-rb/yabeda-prometheus.
98
106
 
107
+ ### Releasing
108
+
109
+ 1. Bump version number in `lib/yabeda/prometheus/version.rb`
110
+
111
+ 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::Prometheus::VERSION).to_s`
112
+
113
+ 2. Fill `CHANGELOG.md` with missing changes, add header with version and date.
114
+
115
+ 3. Make a commit:
116
+
117
+ ```sh
118
+ git add lib/yabeda/prometheus/version.rb CHANGELOG.md
119
+ version=$(ruby -r ./lib/yabeda/prometheus/version.rb -e "puts Gem::Version.new(Yabeda::Prometheus::VERSION)")
120
+ git commit --message="${version}: " --edit
121
+ ```
122
+
123
+ 4. Create annotated tag:
124
+
125
+ ```sh
126
+ git tag v${version} --annotate --message="${version}: " --edit --sign
127
+ ```
128
+
129
+ 5. Fill version name into subject line and (optionally) some description (list of changes will be taken from changelog and appended automatically)
130
+
131
+ 6. Push it:
132
+
133
+ ```sh
134
+ git push --follow-tags
135
+ ```
136
+
137
+ 7. GitHub Actions will create a new release, build and push gem into RubyGems! You're done!
138
+
99
139
  ## License
100
140
 
101
141
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "yabeda"
4
4
  require "prometheus/client"
5
+ require "prometheus/client/push"
5
6
  require "yabeda/prometheus/version"
6
7
  require "yabeda/prometheus/adapter"
7
8
  require "yabeda/prometheus/exporter"
@@ -83,6 +83,17 @@ module Yabeda
83
83
  raise ArgumentError, 'Prometheus require metrics to have comments'
84
84
  end
85
85
 
86
+ def debug!
87
+ Yabeda.configure do
88
+ group :prometheus_exporter
89
+
90
+ histogram :render_duration,
91
+ tags: %i[], unit: :seconds,
92
+ buckets: [0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],
93
+ comment: "Time required to render all metrics in Prometheus format"
94
+ end
95
+ end
96
+
86
97
  private
87
98
 
88
99
  # @param metric [Yabeda::Metric]
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "prometheus/middleware/exporter"
4
+ require "rack"
4
5
 
5
6
  module Yabeda
6
7
  module Prometheus
@@ -20,7 +21,7 @@ module Yabeda
20
21
  def start_metrics_server!
21
22
  Thread.new do
22
23
  default_port = ENV.fetch("PORT", 9394)
23
- Rack::Handler::WEBrick.run(
24
+ ::Rack::Handler::WEBrick.run(
24
25
  rack_app,
25
26
  Host: ENV["PROMETHEUS_EXPORTER_BIND"] || "0.0.0.0",
26
27
  Port: ENV.fetch("PROMETHEUS_EXPORTER_PORT", default_port),
@@ -30,9 +31,9 @@ module Yabeda
30
31
  end
31
32
 
32
33
  def rack_app(exporter = self, path: "/metrics")
33
- Rack::Builder.new do
34
- use Rack::CommonLogger
35
- use Rack::ShowExceptions
34
+ ::Rack::Builder.new do
35
+ use ::Rack::CommonLogger
36
+ use ::Rack::ShowExceptions
36
37
  use exporter, path: path
37
38
  run NOT_FOUND_HANDLER
38
39
  end
@@ -44,8 +45,17 @@ module Yabeda
44
45
  end
45
46
 
46
47
  def call(env)
47
- Yabeda.collectors.each(&:call) if env["PATH_INFO"] == path
48
- super
48
+ ::Yabeda.collect! if env["PATH_INFO"] == path
49
+
50
+ if ::Yabeda.debug?
51
+ result = nil
52
+ ::Yabeda.prometheus_exporter.render_duration.measure({}) do
53
+ result = super
54
+ end
55
+ result
56
+ else
57
+ super
58
+ end
49
59
  end
50
60
  end
51
61
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yabeda
4
4
  module Prometheus
5
- VERSION = "0.5.0"
5
+ VERSION = "0.7.0"
6
6
  end
7
7
  end
Binary file
@@ -27,10 +27,11 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.required_ruby_version = ">= 2.3"
29
29
 
30
- spec.add_dependency "prometheus-client", "~> 1.0"
31
- spec.add_dependency "yabeda", "~> 0.5"
30
+ spec.add_dependency "prometheus-client", ">= 0.10", "< 3.0" # Known to work with 1.x and 2.x
31
+ spec.add_dependency "yabeda", "~> 0.10"
32
+ spec.add_dependency "rack"
32
33
 
33
- spec.add_development_dependency "bundler", "~> 1.17"
34
- spec.add_development_dependency "rake", "~> 12.0"
34
+ spec.add_development_dependency "bundler", "~> 2.0"
35
+ spec.add_development_dependency "rake", "~> 13.0"
35
36
  spec.add_development_dependency "rspec", "~> 3.0"
36
37
  end
metadata CHANGED
@@ -1,71 +1,91 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yabeda-prometheus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.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-29 00:00:00.000000000 Z
11
+ date: 2021-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prometheus-client
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.10'
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: '1.0'
22
+ version: '3.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '1.0'
29
+ version: '0.10'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: yabeda
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '0.5'
39
+ version: '0.10'
34
40
  type: :runtime
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
44
  - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: '0.5'
46
+ version: '0.10'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rack
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: bundler
43
63
  requirement: !ruby/object:Gem::Requirement
44
64
  requirements:
45
65
  - - "~>"
46
66
  - !ruby/object:Gem::Version
47
- version: '1.17'
67
+ version: '2.0'
48
68
  type: :development
49
69
  prerelease: false
50
70
  version_requirements: !ruby/object:Gem::Requirement
51
71
  requirements:
52
72
  - - "~>"
53
73
  - !ruby/object:Gem::Version
54
- version: '1.17'
74
+ version: '2.0'
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: rake
57
77
  requirement: !ruby/object:Gem::Requirement
58
78
  requirements:
59
79
  - - "~>"
60
80
  - !ruby/object:Gem::Version
61
- version: '12.0'
81
+ version: '13.0'
62
82
  type: :development
63
83
  prerelease: false
64
84
  version_requirements: !ruby/object:Gem::Requirement
65
85
  requirements:
66
86
  - - "~>"
67
87
  - !ruby/object:Gem::Version
68
- version: '12.0'
88
+ version: '13.0'
69
89
  - !ruby/object:Gem::Dependency
70
90
  name: rspec
71
91
  requirement: !ruby/object:Gem::Requirement
@@ -87,10 +107,11 @@ executables: []
87
107
  extensions: []
88
108
  extra_rdoc_files: []
89
109
  files:
110
+ - ".github/workflows/build-release.yml"
111
+ - ".github/workflows/test.yml"
90
112
  - ".gitignore"
91
113
  - ".rspec"
92
114
  - ".rubocop.yml"
93
- - ".travis.yml"
94
115
  - CHANGELOG.md
95
116
  - Gemfile
96
117
  - LICENSE.txt
@@ -102,6 +123,7 @@ files:
102
123
  - lib/yabeda/prometheus/adapter.rb
103
124
  - lib/yabeda/prometheus/exporter.rb
104
125
  - lib/yabeda/prometheus/version.rb
126
+ - yabeda-prometheus-logo.png
105
127
  - yabeda-prometheus.gemspec
106
128
  homepage: https://github.com/yabeda-rb/yabeda-prometheus
107
129
  licenses:
@@ -125,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
147
  - !ruby/object:Gem::Version
126
148
  version: '0'
127
149
  requirements: []
128
- rubygems_version: 3.0.3
150
+ rubygems_version: 3.1.6
129
151
  signing_key:
130
152
  specification_version: 4
131
153
  summary: Extensible Prometheus exporter for your 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