fluent-plugin-prometheus 2.1.0 → 2.2.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: 366793cd93075c7e1d63cb2641d2654f5eef5304aaa1293bb9e1dabed7d93e2f
4
- data.tar.gz: 4db5c9fc80dcf10b013239bfdb6e098b53bf26c34a135f944850c70d2a36b7d9
3
+ metadata.gz: 98f287173d66fb76c109519b9b81e230e13a324dd1b1388b644b57d29aff872a
4
+ data.tar.gz: 8bf951166f0a76ebaf12bc55e67c774ee8788f69fd74c60ae9168ab0729424ef
5
5
  SHA512:
6
- metadata.gz: 47de7cabc21f0365b8629714dbd7044e95346d5fb9ce13f7c830a8aeab66bd078769792e6af2ddf52bfc41be3b052f1f1ef912dc71d34c3db0dc94b283832238
7
- data.tar.gz: 00c98825475166ae5f53e6bd85081766a38aa12b5ecddf079e0f1efcbb0eb729deacf996ee975893897aa2aeca84e35a741d23c2bf7e1f602c75876e08d317ee
6
+ metadata.gz: 4e7f3fae38dd44efa082be764b65d610649aa6d6449d159fffb380bfe71464c79bd7764c492c2518ea6a100105910e9ae38b2e37b6327754b442fc780f81d975
7
+ data.tar.gz: 7a5235458808bf4d9eb9b60994688171d45c455c703dcc55062432765b84d9e7e800043bde6e59d4507a45330461e2554b7631ca69fbaa4e2d8fd523ed664625
@@ -11,13 +11,13 @@ jobs:
11
11
  strategy:
12
12
  fail-fast: false
13
13
  matrix:
14
- ruby: [ '3.2', '3.1', '3.0', '2.7' ]
14
+ ruby: [ '3.4', '3.3', '3.2', '3.1', '3.0', '2.7' ]
15
15
  os:
16
16
  - ubuntu-latest
17
17
  experimental: [false]
18
18
  name: Ruby ${{ matrix.ruby }} unit testing on ${{ matrix.os }}
19
19
  steps:
20
- - uses: actions/checkout@v3
20
+ - uses: actions/checkout@v4
21
21
  - uses: ruby/setup-ruby@v1
22
22
  with:
23
23
  ruby-version: ${{ matrix.ruby }}
@@ -25,6 +25,5 @@ jobs:
25
25
  env:
26
26
  CI: true
27
27
  run: |
28
- gem install bundler rake
29
28
  bundle install --jobs 4 --retry 3
30
29
  bundle exec rake spec
data/ChangeLog CHANGED
@@ -1,3 +1,11 @@
1
+ Release 2.2.1 - 2025/03/24
2
+
3
+ * in_prometheus_tail_monitor: Add throttling metrics as `fluentd_tail_file_throttled`. (GitHub#227)
4
+
5
+ Release 2.2.0 - 2024/08/02
6
+
7
+ * in_prometheus: Add gzip support (Add a new parameter `content_encoding gzip`)
8
+
1
9
  Release 2.1.0 - 2023/06/15
2
10
 
3
11
  * Add `initialized` and `initlabels` parameters to `<metric>` element
data/README.md CHANGED
@@ -63,6 +63,7 @@ More configuration parameters:
63
63
  - `port`: listen port (default: 24231)
64
64
  - `metrics_path`: metrics HTTP endpoint (default: /metrics)
65
65
  - `aggregated_metrics_path`: metrics HTTP endpoint (default: /aggregated_metrics)
66
+ - `content_encoding`: encoding format for the exposed metrics (default: identity). Supported formats are {identity, gzip}
66
67
 
67
68
  When using multiple workers, each worker binds to port + `fluent_worker_id`.
68
69
  To scrape metrics from all workers at once, you can access http://localhost:24231/aggregated_metrics.
@@ -167,6 +168,7 @@ This plugin uses internal class of Fluentd, so it's easy to break.
167
168
  - `fluentd_tail_file_closed`: Number of closed files
168
169
  - `fluentd_tail_file_opened`: Number of opened files
169
170
  - `fluentd_tail_file_rotated`: Number of rotated files
171
+ - `fluentd_tail_file_throttled`: Number of times files got throttled (only with fluentd version > 1.17)
170
172
 
171
173
  Default labels:
172
174
 
@@ -492,7 +494,7 @@ In this case, `message_foo_counter` has `tag`, `hostname`, `key` and `data_type`
492
494
  Checkout repository and setup.
493
495
 
494
496
  ```
495
- $ git clone git://github.com/fluent/fluent-plugin-prometheus
497
+ $ git clone git://github.com/fluent/fluent-plugin-prometheus.git
496
498
  $ cd fluent-plugin-prometheus
497
499
  $ bundle install --path vendor/bundle
498
500
  ```
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "fluent-plugin-prometheus"
3
- spec.version = "2.1.0"
3
+ spec.version = "2.2.1"
4
4
  spec.authors = ["Masahiro Sano"]
5
5
  spec.email = ["sabottenda@gmail.com"]
6
6
  spec.summary = %q{A fluent plugin that collects metrics and exposes for Prometheus.}
@@ -3,6 +3,7 @@ require 'fluent/plugin/prometheus'
3
3
  require 'fluent/plugin/prometheus_metrics'
4
4
  require 'net/http'
5
5
  require 'openssl'
6
+ require 'zlib'
6
7
 
7
8
  module Fluent::Plugin
8
9
  class PrometheusInput < Fluent::Plugin::Input
@@ -32,6 +33,9 @@ module Fluent::Plugin
32
33
  config_param :extra_conf, :hash, default: nil, symbolize_keys: true, deprecated: 'See http helper config'
33
34
  end
34
35
 
36
+ desc 'Content encoding of the exposed metrics, Currently supported encoding is identity, gzip. Ref: https://prometheus.io/docs/instrumenting/exposition_formats/#basic-info'
37
+ config_param :content_encoding, :enum, list: [:identity, :gzip], default: :identity
38
+
35
39
  def initialize
36
40
  super
37
41
  @registry = ::Prometheus::Client.registry
@@ -184,7 +188,7 @@ module Fluent::Plugin
184
188
  end
185
189
 
186
190
  def all_metrics
187
- [200, { 'Content-Type' => ::Prometheus::Client::Formats::Text::CONTENT_TYPE }, ::Prometheus::Client::Formats::Text.marshal(@registry)]
191
+ response(::Prometheus::Client::Formats::Text.marshal(@registry))
188
192
  rescue => e
189
193
  [500, { 'Content-Type' => 'text/plain' }, e.to_s]
190
194
  end
@@ -197,8 +201,7 @@ module Fluent::Plugin
197
201
  full_result.add_metrics(resp.body)
198
202
  end
199
203
  end
200
-
201
- [200, { 'Content-Type' => ::Prometheus::Client::Formats::Text::CONTENT_TYPE }, full_result.get_metrics]
204
+ response(full_result.get_metrics)
202
205
  rescue => e
203
206
  [500, { 'Content-Type' => 'text/plain' }, e.to_s]
204
207
  end
@@ -226,5 +229,18 @@ module Fluent::Plugin
226
229
  yield(http)
227
230
  end
228
231
  end
232
+
233
+ def response(metrics)
234
+ body = nil
235
+ case @content_encoding
236
+ when :gzip
237
+ gzip = Zlib::GzipWriter.new(StringIO.new)
238
+ gzip << metrics
239
+ body = gzip.close.string
240
+ when :identity
241
+ body = metrics
242
+ end
243
+ [200, { 'Content-Type' => ::Prometheus::Client::Formats::Text::CONTENT_TYPE, 'Content-Encoding' => @content_encoding.to_s }, body]
244
+ end
229
245
  end
230
246
  end
@@ -77,7 +77,7 @@ module Fluent::Plugin
77
77
  :fluentd_output_status_buffer_queue_length,
78
78
  'Current length of queue buffers.'),
79
79
  buffer_queue_byte_size: get_gauge(
80
- :fluentd_output_status_queue_byte_size,
80
+ :fluentd_output_status_buffer_queue_byte_size,
81
81
  'Current total size of queue buffers.'),
82
82
  buffer_available_buffer_space_ratios: get_gauge(
83
83
  :fluentd_output_status_buffer_available_space_ratio,
@@ -60,6 +60,9 @@ module Fluent::Plugin
60
60
  rotated_file_metrics: get_gauge(
61
61
  :fluentd_tail_file_rotated,
62
62
  'Number of files rotated.'),
63
+ throttled_file_metrics: get_gauge(
64
+ :fluentd_tail_file_throttled,
65
+ 'Number of times files got throttled.'),
63
66
  }
64
67
  timer_execute(:in_prometheus_tail_monitor, @interval, &method(:update_monitor_info))
65
68
  end
@@ -89,6 +92,7 @@ module Fluent::Plugin
89
92
  @metrics[:closed_file_metrics].set(monitor_info.closed.get, labels: label)
90
93
  @metrics[:opened_file_metrics].set(monitor_info.opened.get, labels: label)
91
94
  @metrics[:rotated_file_metrics].set(monitor_info.rotated.get, labels: label)
95
+ @metrics[:throttled_file_metrics].set(monitor_info.throttled.get, labels: label) if monitor_info.members.include?(:throttled)
92
96
  end
93
97
  end
94
98
  end
@@ -3,6 +3,7 @@ require 'fluent/plugin/in_prometheus'
3
3
  require 'fluent/test/driver/input'
4
4
 
5
5
  require 'net/http'
6
+ require 'zlib'
6
7
 
7
8
  describe Fluent::Plugin::PrometheusInput do
8
9
  CONFIG = %[
@@ -45,6 +46,24 @@ describe Fluent::Plugin::PrometheusInput do
45
46
  expect(driver.instance.metrics_path).to eq('/_test')
46
47
  end
47
48
  end
49
+
50
+ describe 'content_encoding_identity' do
51
+ let(:config) { CONFIG + %[
52
+ content_encoding identity
53
+ ] }
54
+ it 'should be configurable' do
55
+ expect(driver.instance.content_encoding).to eq(:identity)
56
+ end
57
+ end
58
+
59
+ describe 'content_encoding_gzip' do
60
+ let(:config) { CONFIG + %[
61
+ content_encoding gzip
62
+ ] }
63
+ it 'should be configurable' do
64
+ expect(driver.instance.content_encoding).to eq(:gzip)
65
+ end
66
+ end
48
67
  end
49
68
 
50
69
  describe '#start' do
@@ -197,6 +216,43 @@ describe Fluent::Plugin::PrometheusInput do
197
216
  end
198
217
  end
199
218
  end
219
+
220
+ context 'response content_encoding identity' do
221
+ let(:config) { LOCAL_CONFIG + %[
222
+ content_encoding identity
223
+ ] }
224
+ it 'exposes metric' do
225
+ driver.run(timeout: 1) do
226
+ registry = driver.instance.instance_variable_get(:@registry)
227
+ registry.counter(:test,docstring: "Testing metrics") unless registry.exist?(:test)
228
+ Net::HTTP.start("127.0.0.1", port) do |http|
229
+ req = Net::HTTP::Get.new("/metrics")
230
+ req['accept-encoding'] = nil
231
+ res = http.request(req)
232
+ expect(res.body).to include("test Testing metrics")
233
+ end
234
+ end
235
+ end
236
+ end
237
+
238
+ context 'response content_encoding gzip' do
239
+ let(:config) { LOCAL_CONFIG + %[
240
+ content_encoding gzip
241
+ ] }
242
+ it 'exposes metric' do
243
+ driver.run(timeout: 1) do
244
+ registry = driver.instance.instance_variable_get(:@registry)
245
+ registry.counter(:test,docstring: "Testing metrics") unless registry.exist?(:test)
246
+ Net::HTTP.start("127.0.0.1", port) do |http|
247
+ req = Net::HTTP::Get.new("/metrics")
248
+ req['accept-encoding'] = nil
249
+ res = http.request(req)
250
+ gzip = Zlib::GzipReader.new(StringIO.new(res.body.to_s))
251
+ expect(gzip.read).to include("test Testing metrics")
252
+ end
253
+ end
254
+ end
255
+ end
200
256
  end
201
257
 
202
258
  describe '#run_multi_workers' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-prometheus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro Sano
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-15 00:00:00.000000000 Z
11
+ date: 2025-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -144,7 +144,7 @@ homepage: https://github.com/fluent/fluent-plugin-prometheus
144
144
  licenses:
145
145
  - Apache-2.0
146
146
  metadata: {}
147
- post_install_message:
147
+ post_install_message:
148
148
  rdoc_options: []
149
149
  require_paths:
150
150
  - lib
@@ -159,8 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  requirements: []
162
- rubygems_version: 3.3.7
163
- signing_key:
162
+ rubygems_version: 3.5.22
163
+ signing_key:
164
164
  specification_version: 4
165
165
  summary: A fluent plugin that collects metrics and exposes for Prometheus.
166
166
  test_files: