yabeda-prometheus 0.6.0 → 0.8.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: 91ea963e20dc59d762257269ec9b4646857f610d99d47836ab18f4873088f97a
4
- data.tar.gz: 01af29b75b3d3e2023643b9c67e22ea34662e87e4d6d78155a3f0b2262cf3240
3
+ metadata.gz: 03ed652a9c06383f38442a04db2ed423b0bf5c2bad99a0e34da5d965ed988ced
4
+ data.tar.gz: ec9f84a17b4f8b773a57985fe61cc4f6a0a4a67e4216f36683a0b8d5e6f95671
5
5
  SHA512:
6
- metadata.gz: a1f48ae1345bce39bf3341a6f9f1d6c282fc4389f8eeded65ce1d6f400887698130346e8a1872790e08a45ce781e7b3ec620779f9ce02c7155181b5d3fd5b5d2
7
- data.tar.gz: d77af840aa442ab415eab7eeb766331f84523ba1bea800fd4d71c1e5daa195953b28a01fa65b9f92f3dc1a4d8b4218dfb77e401c4994ae47baa179960836d6c8
6
+ metadata.gz: 45f454d796db3b1202bc238aadb4bb744686ddffe4efbf328ac172d3eeea6c21614a643d21ae49b971ca43eee0ad29b5ebb636773ebce0cd643620b3f99646f6
7
+ data.tar.gz: 1300508ed83ecefa768fb7ae6a8de08534eae83b2834fa9bf3577e77897ef7efb1a8ad5dfab88af92a1ba6c96caec9412dd14d48a1aa8938749bdfdaa17a5853
@@ -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,42 @@ 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.8.0 - 2021-12-30
11
+
12
+ ### Added
13
+
14
+ - Ability to specify a logger instance for exporter web server. [@palkan], [#19](https://github.com/yabeda-rb/yabeda-prometheus/pull/19)
15
+ - Ability to specify Prometheus instance value for push gateway. [@ollym], [#20](https://github.com/yabeda-rb/yabeda-prometheus/pull/20)
16
+
17
+ ### Changed
18
+
19
+ - Logging is disabled by default for exporter web server. [@palkan], [#19](https://github.com/yabeda-rb/yabeda-prometheus/pull/19)
20
+
21
+ ## 0.7.0 - 2021-07-21
22
+
23
+ ### Added
24
+
25
+ - 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]
26
+
27
+ ### Changed
28
+
29
+ - Yabeda 0.10.0 or newer is required. [@Envek]
30
+
31
+ ## 0.6.2 - 2021-06-23
32
+
33
+ ### Fixed
34
+
35
+ - Fix `uninitialized constant Yabeda::Rack::Handler (NameError)` when using [yabeda-rack-attack](https://github.com/dsalahutdinov/yabeda-rack-attack). [@dsalahutdinov]
36
+
37
+ ## 0.6.1 - 2020-04-28
38
+
39
+ ### Changed
40
+
41
+ - Fixed issue with Push Gateway require. [#13](https://github.com/yabeda-rb/yabeda-prometheus/pull/13) by [@baarkerlounger].
42
+ - Fixed possible issue with rack absense in non-web applications. Declared it as a dependency. [@Envek]
43
+
8
44
  ## 0.6.0 - 2020-04-15
9
45
 
10
46
  ### Changed
@@ -99,4 +135,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99
135
 
100
136
  - Initial release of evil-metrics-prometheus gem. @Envek
101
137
 
138
+ [@Envek]: https://github.com/Envek "Andrey Novikov"
102
139
  [@alexander37137]: https://github.com/alexander37137 "Alexander Andreev"
140
+ [@baarkerlounger]: https://github.com/baarkerlounger "Daniel Baark"
141
+ [@dsalahutdinov]: https://github.com/dsalahutdinov "Dmitry Salahutdinov"
142
+ [@palkan]: https://github.com/palkan "Vladimir Dementyev"
143
+ [@ollym]: https://github.com/ollym "Oliver Morgan"
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,19 @@ 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
+
97
+ ## Exporter logs
98
+
99
+ By default, exporter web server logs are disabled. For example, you can plug in a Rails logger:
100
+
101
+ ```ruby
102
+ Yabeda::Prometheus::Exporter.start_metrics_server! logger: Rails.application.logger
103
+ ```
89
104
  ## Development
90
105
 
91
106
  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 +111,38 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
96
111
 
97
112
  Bug reports and pull requests are welcome on GitHub at https://github.com/yabeda-rb/yabeda-prometheus.
98
113
 
114
+ ### Releasing
115
+
116
+ 1. Bump version number in `lib/yabeda/prometheus/version.rb`
117
+
118
+ 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`
119
+
120
+ 2. Fill `CHANGELOG.md` with missing changes, add header with version and date.
121
+
122
+ 3. Make a commit:
123
+
124
+ ```sh
125
+ git add lib/yabeda/prometheus/version.rb CHANGELOG.md
126
+ version=$(ruby -r ./lib/yabeda/prometheus/version.rb -e "puts Gem::Version.new(Yabeda::Prometheus::VERSION)")
127
+ git commit --message="${version}: " --edit
128
+ ```
129
+
130
+ 4. Create annotated tag:
131
+
132
+ ```sh
133
+ git tag v${version} --annotate --message="${version}: " --edit --sign
134
+ ```
135
+
136
+ 5. Fill version name into subject line and (optionally) some description (list of changes will be taken from changelog and appended automatically)
137
+
138
+ 6. Push it:
139
+
140
+ ```sh
141
+ git push --follow-tags
142
+ ```
143
+
144
+ 7. GitHub Actions will create a new release, build and push gem into RubyGems! You're done!
145
+
99
146
  ## License
100
147
 
101
148
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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
@@ -17,11 +18,11 @@ module Yabeda
17
18
  @app.call(env)
18
19
  end
19
20
 
20
- def start_metrics_server!
21
+ def start_metrics_server!(**rack_app_options)
21
22
  Thread.new do
22
23
  default_port = ENV.fetch("PORT", 9394)
23
- Rack::Handler::WEBrick.run(
24
- rack_app,
24
+ ::Rack::Handler::WEBrick.run(
25
+ rack_app(**rack_app_options),
25
26
  Host: ENV["PROMETHEUS_EXPORTER_BIND"] || "0.0.0.0",
26
27
  Port: ENV.fetch("PROMETHEUS_EXPORTER_PORT", default_port),
27
28
  AccessLog: [],
@@ -29,10 +30,10 @@ module Yabeda
29
30
  end
30
31
  end
31
32
 
32
- def rack_app(exporter = self, path: "/metrics")
33
- Rack::Builder.new do
34
- use Rack::CommonLogger
35
- use Rack::ShowExceptions
33
+ def rack_app(exporter = self, path: "/metrics", logger: Logger.new(IO::NULL))
34
+ ::Rack::Builder.new do
35
+ use ::Rack::CommonLogger, logger
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.6.0"
5
+ VERSION = "0.8.0"
6
6
  end
7
7
  end
@@ -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"
@@ -17,7 +18,7 @@ module Yabeda
17
18
  @push_gateway ||= begin
18
19
  ::Prometheus::Client::Push.new(
19
20
  ENV.fetch("PROMETHEUS_JOB_NAME", "yabeda"),
20
- nil,
21
+ ENV["PROMETHEUS_INSTANCE"],
21
22
  ENV.fetch("PROMETHEUS_PUSH_GATEWAY", "http://localhost:9091"),
22
23
  ).tap do |gateway|
23
24
  http = gateway.instance_variable_get(:@http)
Binary file
@@ -28,9 +28,10 @@ Gem::Specification.new do |spec|
28
28
  spec.required_ruby_version = ">= 2.3"
29
29
 
30
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.5"
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yabeda-prometheus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.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-04-15 00:00:00.000000000 Z
11
+ date: 2021-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prometheus-client
@@ -36,42 +36,56 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0.5'
39
+ version: '0.10'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- 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'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: bundler
49
63
  requirement: !ruby/object:Gem::Requirement
50
64
  requirements:
51
65
  - - "~>"
52
66
  - !ruby/object:Gem::Version
53
- version: '1.17'
67
+ version: '2.0'
54
68
  type: :development
55
69
  prerelease: false
56
70
  version_requirements: !ruby/object:Gem::Requirement
57
71
  requirements:
58
72
  - - "~>"
59
73
  - !ruby/object:Gem::Version
60
- version: '1.17'
74
+ version: '2.0'
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: rake
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
65
79
  - - "~>"
66
80
  - !ruby/object:Gem::Version
67
- version: '12.0'
81
+ version: '13.0'
68
82
  type: :development
69
83
  prerelease: false
70
84
  version_requirements: !ruby/object:Gem::Requirement
71
85
  requirements:
72
86
  - - "~>"
73
87
  - !ruby/object:Gem::Version
74
- version: '12.0'
88
+ version: '13.0'
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: rspec
77
91
  requirement: !ruby/object:Gem::Requirement
@@ -93,10 +107,11 @@ executables: []
93
107
  extensions: []
94
108
  extra_rdoc_files: []
95
109
  files:
110
+ - ".github/workflows/build-release.yml"
111
+ - ".github/workflows/test.yml"
96
112
  - ".gitignore"
97
113
  - ".rspec"
98
114
  - ".rubocop.yml"
99
- - ".travis.yml"
100
115
  - CHANGELOG.md
101
116
  - Gemfile
102
117
  - LICENSE.txt
@@ -108,6 +123,7 @@ files:
108
123
  - lib/yabeda/prometheus/adapter.rb
109
124
  - lib/yabeda/prometheus/exporter.rb
110
125
  - lib/yabeda/prometheus/version.rb
126
+ - yabeda-prometheus-logo.png
111
127
  - yabeda-prometheus.gemspec
112
128
  homepage: https://github.com/yabeda-rb/yabeda-prometheus
113
129
  licenses:
@@ -131,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
147
  - !ruby/object:Gem::Version
132
148
  version: '0'
133
149
  requirements: []
134
- rubygems_version: 3.0.3
150
+ rubygems_version: 3.1.6
135
151
  signing_key:
136
152
  specification_version: 4
137
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