yabeda-prometheus 0.7.0 → 0.9.0

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: c36a4a73e4e698126e81bf8cb5069de6521ac396742a59dc13a906b2e6470f12
4
- data.tar.gz: 67b7b8d5d56cff197c47bbac7b27d9a3eefe3cbbc1f63a01d8d35d2d4cd97305
3
+ metadata.gz: 906db4d10bd83296b001ddaa09d01bb01adb55299f054cd484c52cb8e1168dd8
4
+ data.tar.gz: 870e978d2065aa4ef51904b34bdd6ea38cdd48e2a5ddb19ecab4792f3d5e0194
5
5
  SHA512:
6
- metadata.gz: 25eae376eda44fd094891a717efaf877bd629b7ae9fcb0867ecf146fd0ea70e1afc7df3d24f8e615c4be11081004719de67bbfd89cacdeb011e51d74a331f1b4
7
- data.tar.gz: 7184e70ea9a35daaf7b29e4fc8e2f9fd18e6b89679d1a4ebcb97722e359853e5723ace3a17cc3fb4a132947f758f2a4e88ccd6a8fe30bd7b48ff5d0872d46de4
6
+ metadata.gz: d25b3c9449c812c329f1f6fb3acd0dcebc93a73a5895d37e2d6b76a0b3a3d3ee5b7aa04d80111469de5b0f76dfcd6986f6f5b64c8e30b52aec9196116dbda478
7
+ data.tar.gz: 1506ce4596bf8aaef915a1b098f32a376e7d9ec7771f2a40b02c972e9dfc38ffbc7f49171387aa5c44766329a18d26705c24019296bc0cb543594d254ea216d3
data/CHANGELOG.md CHANGED
@@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ## 0.9.0 - 2023-07-28
11
+
12
+ ### Added
13
+
14
+ - Support for summary metric type (Yabeda 0.12+ is required). [@Envek]
15
+ - Metrics endpoint response compression with Rack Deflater. [@etsenake], ([#23](https://github.com/yabeda-rb/yabeda-prometheus/pull/23)
16
+
17
+ ### Changed
18
+
19
+ - prometheus-client 3.x or 4.x is required. [@Envek]
20
+
21
+ ## 0.8.0 - 2021-12-30
22
+
23
+ ### Added
24
+
25
+ - Ability to specify a logger instance for exporter web server. [@palkan], [#19](https://github.com/yabeda-rb/yabeda-prometheus/pull/19)
26
+ - Ability to specify Prometheus instance value for push gateway. [@ollym], [#20](https://github.com/yabeda-rb/yabeda-prometheus/pull/20)
27
+
28
+ ### Changed
29
+
30
+ - Logging is disabled by default for exporter web server. [@palkan], [#19](https://github.com/yabeda-rb/yabeda-prometheus/pull/19)
31
+
10
32
  ## 0.7.0 - 2021-07-21
11
33
 
12
34
  ### Added
@@ -128,3 +150,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
128
150
  [@alexander37137]: https://github.com/alexander37137 "Alexander Andreev"
129
151
  [@baarkerlounger]: https://github.com/baarkerlounger "Daniel Baark"
130
152
  [@dsalahutdinov]: https://github.com/dsalahutdinov "Dmitry Salahutdinov"
153
+ [@palkan]: https://github.com/palkan "Vladimir Dementyev"
154
+ [@ollym]: https://github.com/ollym "Oliver Morgan"
155
+ [@etsenake]: https://github.com/etsenake "Josh Etsenake"
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
 
@@ -94,6 +102,13 @@ end
94
102
 
95
103
  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
104
 
105
+ ## Exporter logs
106
+
107
+ By default, exporter web server logs are disabled. For example, you can plug in a Rails logger:
108
+
109
+ ```ruby
110
+ Yabeda::Prometheus::Exporter.start_metrics_server! logger: Rails.application.logger
111
+ ```
97
112
  ## Development
98
113
 
99
114
  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.
@@ -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,15 +14,16 @@ 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
- def start_metrics_server!
22
+ def start_metrics_server!(**rack_app_options)
22
23
  Thread.new do
23
24
  default_port = ENV.fetch("PORT", 9394)
24
25
  ::Rack::Handler::WEBrick.run(
25
- rack_app,
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),
28
29
  AccessLog: [],
@@ -30,11 +31,12 @@ module Yabeda
30
31
  end
31
32
  end
32
33
 
33
- def rack_app(exporter = self, path: "/metrics")
34
+ def rack_app(exporter = self, logger: Logger.new(IO::NULL), use_deflater: true, **exporter_options)
34
35
  ::Rack::Builder.new do
35
- use ::Rack::CommonLogger
36
+ use ::Rack::Deflater if use_deflater
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yabeda
4
4
  module Prometheus
5
- VERSION = "0.7.0"
5
+ VERSION = "0.9.0"
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
- nil,
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.7.0
4
+ version: 0.9.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: 2021-07-21 00:00:00.000000000 Z
11
+ date: 2023-07-28 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