yabeda-prometheus 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03ed652a9c06383f38442a04db2ed423b0bf5c2bad99a0e34da5d965ed988ced
4
- data.tar.gz: ec9f84a17b4f8b773a57985fe61cc4f6a0a4a67e4216f36683a0b8d5e6f95671
3
+ metadata.gz: 178705f128fcff8d9fc98c8b2db3a8b9a031d2b282f99cd522587389cd3f8001
4
+ data.tar.gz: c800d08198dcd1b62b94daabcbe0c7fdedd8c5cf5320992a63b4606475bb7f73
5
5
  SHA512:
6
- metadata.gz: 45f454d796db3b1202bc238aadb4bb744686ddffe4efbf328ac172d3eeea6c21614a643d21ae49b971ca43eee0ad29b5ebb636773ebce0cd643620b3f99646f6
7
- data.tar.gz: 1300508ed83ecefa768fb7ae6a8de08534eae83b2834fa9bf3577e77897ef7efb1a8ad5dfab88af92a1ba6c96caec9412dd14d48a1aa8938749bdfdaa17a5853
6
+ metadata.gz: e78322f06706eb11df51cfd56bcba9890c7da377437e67a1ce021a55377b616e950dceb983cb2f654fa3c501f4e14bf73ffe7d07f8ce108837c9c009694c595d
7
+ data.tar.gz: 0c8eb49c988fb20e4c4154a78f4e027f35c6d216ed2c832aecb503e188f253b9c3fa6ca345e0319893ad4497e1a9f29d2213f1642b792fd22113a3262de92db4
@@ -8,13 +8,18 @@ on:
8
8
  jobs:
9
9
  release:
10
10
  runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: write
13
+ id-token: write
14
+ packages: write
15
+
11
16
  steps:
12
- - uses: actions/checkout@v2
17
+ - uses: actions/checkout@v4
13
18
  with:
14
19
  fetch-depth: 0 # Fetch current tag as annotated. See https://github.com/actions/checkout/issues/290
15
20
  - uses: ruby/setup-ruby@v1
16
21
  with:
17
- ruby-version: 2.7
22
+ ruby-version: 3.2
18
23
  - name: "Extract data from tag: version, message, body"
19
24
  id: tag
20
25
  run: |
@@ -75,8 +80,8 @@ jobs:
75
80
  GEM_HOST_API_KEY: Bearer ${{ secrets.GITHUB_TOKEN }}
76
81
  run: |
77
82
  gem push yabeda-prometheus-${{ steps.tag.outputs.version }}.gem --host https://rubygems.pkg.github.com/${{ github.repository_owner }}
83
+ - name: Configure RubyGems Credentials
84
+ uses: rubygems/configure-rubygems-credentials@main
78
85
  - name: Publish to RubyGems
79
- env:
80
- GEM_HOST_API_KEY: "${{ secrets.RUBYGEMS_API_KEY }}"
81
86
  run: |
82
87
  gem push yabeda-prometheus-${{ steps.tag.outputs.version }}.gem
@@ -1,4 +1,4 @@
1
- name: Run tests
1
+ name: Tests
2
2
 
3
3
  on:
4
4
  pull_request:
@@ -10,36 +10,24 @@ on:
10
10
 
11
11
  jobs:
12
12
  test:
13
- name: "Run tests"
14
- if: "!contains(github.event.head_commit.message, '[ci skip]')"
13
+ # Skip running tests for local pull requests (use push event instead), run only for foreign ones
14
+ if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login != github.event.pull_request.base.repo.owner.login
15
+ name: 'Ruby ${{ matrix.ruby }}'
15
16
  runs-on: ubuntu-latest
16
17
  strategy:
17
18
  fail-fast: false
18
19
  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
20
+ ruby:
21
+ - '2.7'
22
+ - '3.0'
23
+ - '3.1'
24
+ - '3.2'
25
+ - '3.3'
28
26
  steps:
29
- - uses: actions/checkout@v2
30
- - uses: actions/cache@v2
27
+ - uses: actions/checkout@v4
28
+ - uses: ruby/setup-ruby@v1
31
29
  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
30
+ ruby-version: ${{ matrix.ruby }}
31
+ bundler-cache: true
44
32
  - name: Run RSpec
45
33
  run: bundle exec rspec
data/CHANGELOG.md CHANGED
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ## 0.9.1 - 2024-01-04
11
+
12
+ ### Fixed
13
+
14
+ - Compatibility with Rack 3 and Rack 2. [#27](https://github.com/yabeda-rb/yabeda-prometheus/pull/27) by [@aroop][].
15
+
16
+ ## 0.9.0 - 2023-07-28
17
+
18
+ ### Added
19
+
20
+ - Support for summary metric type (Yabeda 0.12+ is required). [@Envek]
21
+ - Metrics endpoint response compression with Rack Deflater. [@etsenake], ([#23](https://github.com/yabeda-rb/yabeda-prometheus/pull/23)
22
+
23
+ ### Changed
24
+
25
+ - prometheus-client 3.x or 4.x is required. [@Envek]
26
+
10
27
  ## 0.8.0 - 2021-12-30
11
28
 
12
29
  ### Added
@@ -141,3 +158,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
141
158
  [@dsalahutdinov]: https://github.com/dsalahutdinov "Dmitry Salahutdinov"
142
159
  [@palkan]: https://github.com/palkan "Vladimir Dementyev"
143
160
  [@ollym]: https://github.com/ollym "Oliver Morgan"
161
+ [@etsenake]: https://github.com/etsenake "Josh Etsenake"
162
+ [@aroop]: https://github.com/aroop "Ajay Guthikonda"
data/Gemfile CHANGED
@@ -8,6 +8,8 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
8
8
  gemspec
9
9
 
10
10
  group :development, :test do
11
+ gem "yabeda", ">= 0.12", github: "yabeda-rb/yabeda", branch: "master"
12
+
11
13
  gem "pry"
12
14
  gem "pry-byebug", platform: :mri
13
15
 
data/README.md CHANGED
@@ -36,9 +36,17 @@ And then execute:
36
36
  use Yabeda::Prometheus::Exporter
37
37
  ```
38
38
 
39
- Metrics will be available on `/metrics` path (configured by `:path` option).
39
+ Metrics will be available on `/metrics` path (configured by `:path` option), additionally metrics can be served only on specific port with `:port` option.
40
40
 
41
- Also you can mount it in Rails application routes as standalone Rack application.
41
+ Alternatively you can mount it in Rails application routes as standalone Rack application:
42
+
43
+ ```ruby
44
+ Rails.application.routes.draw do
45
+ mount Yabeda::Prometheus::Exporter, at: "/metrics"
46
+ end
47
+ ```
48
+
49
+ Additional options (like `:port`) are also accepted and forwarded to [Prometheys Exporter](https://github.com/prometheus/client_ruby/blob/main/lib/prometheus/middleware/exporter.rb) middleware.
42
50
 
43
51
  2. Run web-server from long-running processes (delayed jobs, …):
44
52
 
@@ -73,6 +73,22 @@ module Yabeda
73
73
  raise UndeclaredMetricTags.new(build_name(metric), e)
74
74
  end
75
75
 
76
+ def register_summary!(metric)
77
+ validate_metric!(metric)
78
+ registry.summary(
79
+ build_name(metric),
80
+ docstring: metric.comment,
81
+ labels: Array(metric.tags),
82
+ store_settings: store_settings(metric),
83
+ )
84
+ end
85
+
86
+ def perform_summary_observe!(metric, tags, value)
87
+ registry.get(build_name(metric)).observe(value, labels: tags)
88
+ rescue ::Prometheus::Client::LabelSetValidator::InvalidLabelSetError => e
89
+ raise UndeclaredMetricTags.new(build_name(metric), e)
90
+ end
91
+
76
92
  def build_name(metric)
77
93
  [metric.group, metric.name, metric.unit].compact.join('_').to_sym
78
94
  end
@@ -14,14 +14,15 @@ module Yabeda
14
14
  class << self
15
15
  # Allows to use middleware as standalone rack application
16
16
  def call(env)
17
- @app ||= new(NOT_FOUND_HANDLER, path: "/")
17
+ options = env.fetch("action_dispatch.request.path_parameters", {})
18
+ @app ||= new(NOT_FOUND_HANDLER, path: "/", **options)
18
19
  @app.call(env)
19
20
  end
20
21
 
21
22
  def start_metrics_server!(**rack_app_options)
22
23
  Thread.new do
23
24
  default_port = ENV.fetch("PORT", 9394)
24
- ::Rack::Handler::WEBrick.run(
25
+ rack_handler.run(
25
26
  rack_app(**rack_app_options),
26
27
  Host: ENV["PROMETHEUS_EXPORTER_BIND"] || "0.0.0.0",
27
28
  Port: ENV.fetch("PROMETHEUS_EXPORTER_PORT", default_port),
@@ -30,14 +31,27 @@ module Yabeda
30
31
  end
31
32
  end
32
33
 
33
- def rack_app(exporter = self, path: "/metrics", logger: Logger.new(IO::NULL))
34
+ def rack_app(exporter = self, logger: Logger.new(IO::NULL), use_deflater: true, **exporter_options)
34
35
  ::Rack::Builder.new do
36
+ use ::Rack::Deflater if use_deflater
35
37
  use ::Rack::CommonLogger, logger
36
38
  use ::Rack::ShowExceptions
37
- use exporter, path: path
39
+ use exporter, **exporter_options
38
40
  run NOT_FOUND_HANDLER
39
41
  end
40
42
  end
43
+
44
+ def rack_handler
45
+ if Gem.loaded_specs['rack']&.version&.>= Gem::Version.new('3.0')
46
+ require 'rackup'
47
+ ::Rackup::Handler::WEBrick
48
+ else
49
+ ::Rack::Handler::WEBrick
50
+ end
51
+ rescue LoadError
52
+ warn 'Please add gems rackup and webrick to your Gemfile to expose Yabeda metrics from prometheus-mmap'
53
+ ::Rack::Handler::WEBrick
54
+ end
41
55
  end
42
56
 
43
57
  def initialize(app, options = {})
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yabeda
4
4
  module Prometheus
5
- VERSION = "0.8.0"
5
+ VERSION = "0.9.1"
6
6
  end
7
7
  end
@@ -15,17 +15,12 @@ module Yabeda
15
15
  end
16
16
 
17
17
  def push_gateway
18
- @push_gateway ||= begin
18
+ @push_gateway ||=
19
19
  ::Prometheus::Client::Push.new(
20
- ENV.fetch("PROMETHEUS_JOB_NAME", "yabeda"),
21
- ENV["PROMETHEUS_INSTANCE"],
22
- ENV.fetch("PROMETHEUS_PUSH_GATEWAY", "http://localhost:9091"),
23
- ).tap do |gateway|
24
- http = gateway.instance_variable_get(:@http)
25
- http.open_timeout = 5
26
- http.read_timeout = 5
27
- end
28
- end
20
+ job: ENV.fetch("PROMETHEUS_JOB_NAME", "yabeda"),
21
+ gateway: ENV.fetch("PROMETHEUS_PUSH_GATEWAY", "http://localhost:9091"),
22
+ open_timeout: 5, read_timeout: 30,
23
+ )
29
24
  end
30
25
  end
31
26
  end
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.required_ruby_version = ">= 2.3"
29
29
 
30
- spec.add_dependency "prometheus-client", ">= 0.10", "< 3.0" # Known to work with 1.x and 2.x
30
+ spec.add_dependency "prometheus-client", ">= 3.0", "< 5.0"
31
31
  spec.add_dependency "yabeda", "~> 0.10"
32
32
  spec.add_dependency "rack"
33
33
 
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.8.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Novikov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-30 00:00:00.000000000 Z
11
+ date: 2024-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prometheus-client
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.10'
19
+ version: '3.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '3.0'
22
+ version: '5.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '0.10'
29
+ version: '3.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '3.0'
32
+ version: '5.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: yabeda
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  - !ruby/object:Gem::Version
148
148
  version: '0'
149
149
  requirements: []
150
- rubygems_version: 3.1.6
150
+ rubygems_version: 3.4.10
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: Extensible Prometheus exporter for your application