yabeda-puma-plugin 0.6.0 → 0.7.1

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: 0e89900f2439ba78c8c813c423c1035133934fd7b727d355fe16be5416b40ef5
4
- data.tar.gz: 1b99f6bebac908ad72fd85522b41823a42593262057cea0abb3c2c6dd9768501
3
+ metadata.gz: f9b1df64591444d1f95959e4a18a2f84ddc0422da1a8aa7762b6da41cf0090ab
4
+ data.tar.gz: b0b6fd8696a7c35db5a2b31ddf462463a64038581dd9e414ed26d46a27eedbd0
5
5
  SHA512:
6
- metadata.gz: 2f586fcfa8cef7892afa68690c23cb6c73c70964bed54b0ce65d5434513490b91c133d2ef2e9709ad352dde50f6ebf1dea3c884e67b668737d8cfb0eb783c215
7
- data.tar.gz: 97c8662a33acdd7102d90faa8725ee86269587c8c3f104dc49ae0621793c66e6f9f5ddf8660f0dbec11598e700dc97db32dcb51073c96384f4273baa20946ac6
6
+ metadata.gz: 474080f9c29212326062d91f968cde58fdfb573edf571194d786dbd895ba6e8400e81d05a77ff50aa9847c8681c6af6852a1c3bbc40032ad8b9b70b10d70d0ba
7
+ data.tar.gz: d89bac196177c49be5ef55df912bf29fe2eb3c487c7495d6e36020ad071fba53b3aeac38d22b89ad0e6870f3aa10b866face96a40c3bcae09d9a1501ab3c607e
@@ -1,4 +1,4 @@
1
- name: Run tests
1
+ name: Tests
2
2
 
3
3
  on:
4
4
  pull_request:
@@ -10,24 +10,32 @@ on:
10
10
 
11
11
  jobs:
12
12
  test:
13
- name: "Run tests"
14
- if: "! contains(toJSON(github.event.commits.latest.message), '[ci skip]')"
13
+ name: 'Puma ${{ matrix.puma }} on Ruby ${{ matrix.ruby }}'
14
+ # Skip running tests for local pull requests (use push event instead), run only for foreign ones
15
+ if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login != github.event.pull_request.base.repo.owner.login
15
16
  runs-on: ubuntu-latest
16
17
  strategy:
17
18
  fail-fast: false
18
19
  matrix:
19
20
  include:
20
- - ruby: 3.0
21
- - ruby: 2.7
22
- - ruby: 2.6
23
- - ruby: 2.5
21
+ - ruby: "3.1"
22
+ puma: "6"
23
+ - ruby: "3.0"
24
+ puma: "5"
25
+ - ruby: "2.7"
26
+ puma: "5"
27
+ - ruby: "2.6"
28
+ puma: "4"
29
+ - ruby: "2.5"
30
+ puma: "4"
24
31
  container:
25
32
  image: ruby:${{ matrix.ruby }}
26
33
  env:
27
34
  CI: true
35
+ PUMA_VERSION: ${{ matrix.puma }}
28
36
  steps:
29
- - uses: actions/checkout@v2
30
- - uses: actions/cache@v2
37
+ - uses: actions/checkout@v3
38
+ - uses: actions/cache@v3
31
39
  with:
32
40
  path: vendor/bundle
33
41
  key: bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}-${{ hashFiles('**/Gemfile') }}
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
+ ## 0.7.1 - 2022-11-28
9
+
10
+ ### Fixed
11
+
12
+ - Error if exporter is stopped before creation. [@ollym][], [#27](https://github.com/yabeda-rb/yabeda-puma-plugin/pull/27)
13
+
14
+ ## 0.7.0 - 2022-10-24
15
+
16
+ ### Added
17
+
18
+ - Puma 6.x support for `yabeda_prometheus` plugin. [@ollym][], [#25](https://github.com/yabeda-rb/yabeda-puma-plugin/pull/25)
19
+ - Support phased restarts with standalone Prometheus exporter. [@botimer][], [#23](https://github.com/yabeda-rb/yabeda-puma-plugin/pull/23)
20
+ - `on_prometheus_exporter_boot` hook in Puma config DSL. [@Envek][]
21
+
8
22
  ## 0.6.0 - 2021-02-05
9
23
 
10
24
  ### Changed
@@ -45,6 +59,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
45
59
 
46
60
  Initial release with basic metrics collection. [@dsalahutdinov]
47
61
 
62
+ [@ollym]: https://github.com/ollym "Oliver Morgan"
48
63
  [@botimer]: https://github.com/botimer "Noah Botimer"
49
64
  [@jwhitcraft]: https://github.com/jwhitcraft "Jon Whitcraft"
50
65
  [@Neznauy]: https://github.com/Neznauy "Aleksandr Shlyakov"
data/Gemfile CHANGED
@@ -1,6 +1,10 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'prometheus-client'
4
3
  gem 'yabeda-prometheus'
4
+
5
5
  # Specify your gem's dependencies in yabeda-puma.gemspec
6
6
  gemspec
7
+
8
+ puma_version = ENV.fetch("PUMA_VERSION", "~> 6.0")
9
+ puma_version = "~> #{puma_version}.0" if puma_version.match?(/^\d+$/)
10
+ gem "puma", puma_version
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  alt="Sponsored by Amplifr" src="https://amplifr-direct.s3-eu-west-1.amazonaws.com/social_images/image/37b580d9-3668-4005-8d5a-137de3a3e77c.png" />
4
4
  </a>
5
5
 
6
- # Yabeda::Puma::Plugin
6
+ # ![`Yabeda::Puma::Plugin`](./yabeda-puma-plugin-logo.png)
7
7
 
8
8
  Built-in metrics for [Puma](https://github.com/puma/puma) web server monitoring out of the box! Part of the [yabeda](https://github.com/yabeda-rb/yabeda) suite.
9
9
 
@@ -43,6 +43,17 @@ plugin :yabeda
43
43
  ```
44
44
  It will activate default puma control application working over the unix socket, and runs the `yabeda` puma plugin, for registering and collecting the metrics.
45
45
 
46
+ > **Note**
47
+ >
48
+ > In case if you're **not** using Rails, don't forget configure Yabeda manually either in your app initialization or in Puma configuration hook:
49
+ > ```ruby
50
+ > # config/puma.rb
51
+ > before_fork do
52
+ > Yabeda.configure!
53
+ > end
54
+ > ```
55
+ > See [yabeda usage](https://github.com/yabeda-rb/yabeda#usage) for more information.
56
+
46
57
  ### Exposing metrics
47
58
 
48
59
  Some monitoring system agents (like NewRelic or DataDog) will send metrics automatically in the background. But for some of monitoring systems (like Prometheus) you have to explicitly set up metrics export.
data/docker-compose.yml CHANGED
@@ -2,7 +2,7 @@ version: '3.4'
2
2
 
3
3
  services:
4
4
  app:
5
- image: ruby:2.6.0
5
+ image: ruby:3.1.0
6
6
  environment:
7
7
  - BUNDLE_PATH=/bundle
8
8
  - BUNDLE_CONFIG=/app/.bundle/config
@@ -14,6 +14,11 @@ module Puma
14
14
  def prometheus_exporter_url(uri)
15
15
  @options[:prometheus_exporter_url] = uri
16
16
  end
17
+
18
+ def on_prometheus_exporter_boot(&block)
19
+ @options[:prometheus_exporter_boot_hooks] ||= []
20
+ @options[:prometheus_exporter_boot_hooks] << block
21
+ end
17
22
  end
18
23
  end
19
24
 
@@ -27,23 +32,67 @@ Puma::Plugin.create do
27
32
  port = Integer(ENV.fetch('PROMETHEUS_EXPORTER_PORT', uri.port))
28
33
  path = ENV.fetch('PROMETHEUS_EXPORTER_PATH', uri.path)
29
34
 
30
- events.on_booted do
35
+ server = nil
36
+ logger = nil
37
+ banner = "Yabeda Prometheus metrics exporter on http://#{host}:#{port}#{path}"
38
+
39
+ create_server = -> {
31
40
  app = Yabeda::Prometheus::Exporter.rack_app(Yabeda::Prometheus::Exporter, path: path)
41
+ internal_events = Puma::Events.respond_to?(:null) ? Puma::Events.null : Puma::Events.new
42
+ server = Puma::Server.new app, internal_events, min_threads: 0, max_threads: 1
43
+ logger = server.respond_to?(:log_writer) ? server.log_writer : events
44
+
45
+ server.add_tcp_listener host, port
46
+ if server.respond_to?(:min_threads=)
47
+ server.min_threads = 0
48
+ server.max_threads = 1
49
+ end
32
50
 
33
- metrics = Puma::Server.new app, events
34
- metrics.min_threads = 0
35
- metrics.max_threads = 1
51
+ internal_events.register(:state) do |state|
52
+ next unless state == :running
53
+ hooks = launcher.options.fetch(:prometheus_exporter_boot_hooks, [])
54
+ hooks.each(&:call)
55
+ end
36
56
 
37
- events.log "* Starting Yabeda Prometheus metrics exporter on http://#{host}:#{port}#{path}"
38
- metrics.add_tcp_listener host, port
57
+ [server, logger]
58
+ }
39
59
 
40
- events.register(:state) do |state|
41
- if %i[halt restart stop].include?(state)
42
- metrics.stop(true) unless metrics.shutting_down?
60
+ events.on_booted do
61
+ unless server&.running
62
+ server, logger = create_server.call
63
+ logger.log "* Starting #{banner}"
64
+ server.run
65
+ end
66
+ end
67
+
68
+ # on_stopped and on_restart hooks were added in Puma 5.1 in https://github.com/puma/puma/commit/288a4cf756852a4837c77ee70d7fdcca1edb8e82
69
+ if events.respond_to?(:on_stopped) && events.respond_to?(:on_restart)
70
+
71
+ events.on_stopped do
72
+ if server && !server.shutting_down?
73
+ logger.log "* Stopping #{banner}"
74
+ server.stop(true)
43
75
  end
44
76
  end
45
77
 
46
- metrics.run
78
+ events.on_restart do
79
+ logger.log "* Restarting #{banner}"
80
+ server.stop(true)
81
+ server, logger = create_server.call
82
+ server.run
83
+ end
84
+
85
+ else
86
+
87
+ events.register(:state) do |state|
88
+ next unless %i[halt restart stop].include?(state)
89
+
90
+ metrics.stop(true) unless metrics.shutting_down?
91
+ next unless state == :restart
92
+
93
+ server, logger = create_server.call
94
+ server.run
95
+ end
47
96
  end
48
97
  end
49
98
  end
@@ -1,7 +1,7 @@
1
1
  module Yabeda
2
2
  module Puma
3
3
  module Plugin
4
- VERSION = "0.6.0"
4
+ VERSION = "0.7.1"
5
5
  end
6
6
  end
7
7
  end
Binary file
@@ -28,5 +28,6 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "bundler"
29
29
  spec.add_development_dependency "rake", "~> 13.0"
30
30
  spec.add_development_dependency "rspec", "~> 3.0"
31
- spec.add_development_dependency "rack"
31
+ spec.add_development_dependency "rack", "< 3"
32
+ spec.add_development_dependency "yabeda-prometheus", "~> 0.8"
32
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yabeda-puma-plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salahutdinov Dmitry
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-05 00:00:00.000000000 Z
11
+ date: 2022-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yabeda
@@ -98,16 +98,30 @@ dependencies:
98
98
  name: rack
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "<"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: '3'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "<"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: '3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yabeda-prometheus
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
111
125
  description: Extends Yabeda metrics with puma web server values by using puma plugin
112
126
  email:
113
127
  - dsalahutdinov@gmail.com
@@ -137,6 +151,7 @@ files:
137
151
  - lib/yabeda/puma/plugin/statistics/fetcher.rb
138
152
  - lib/yabeda/puma/plugin/statistics/parser.rb
139
153
  - lib/yabeda/puma/plugin/version.rb
154
+ - yabeda-puma-plugin-logo.png
140
155
  - yabeda-puma-plugin.gemspec
141
156
  homepage: http://github.com/yabeda-rb/yabeda-puma-plugin
142
157
  licenses:
@@ -157,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
172
  - !ruby/object:Gem::Version
158
173
  version: '0'
159
174
  requirements: []
160
- rubygems_version: 3.1.4
175
+ rubygems_version: 3.1.6
161
176
  signing_key:
162
177
  specification_version: 4
163
178
  summary: Puma web server plugin for collecting puma metrics with Yabeda framework.