fluent-plugin-prometheus 2.1.0 → 2.2.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: 366793cd93075c7e1d63cb2641d2654f5eef5304aaa1293bb9e1dabed7d93e2f
4
- data.tar.gz: 4db5c9fc80dcf10b013239bfdb6e098b53bf26c34a135f944850c70d2a36b7d9
3
+ metadata.gz: c42edc59b51fa5a911f51e5c174f71dc573c99068379d3ee8ba7d2d710dbcbb5
4
+ data.tar.gz: 32206e06e3c6a6a9b19f6b93583af0c416ae76dc707a1a2dbefe0b54975a936b
5
5
  SHA512:
6
- metadata.gz: 47de7cabc21f0365b8629714dbd7044e95346d5fb9ce13f7c830a8aeab66bd078769792e6af2ddf52bfc41be3b052f1f1ef912dc71d34c3db0dc94b283832238
7
- data.tar.gz: 00c98825475166ae5f53e6bd85081766a38aa12b5ecddf079e0f1efcbb0eb729deacf996ee975893897aa2aeca84e35a741d23c2bf7e1f602c75876e08d317ee
6
+ metadata.gz: 178009b03c28bf7dde6207cbf7f99c1bcdd8e787669630646f937eed5249b8d8fc17443ec08777620caafbc2498ceb13d753db45aea0a86d9b309a396078bf44
7
+ data.tar.gz: 3051330dbb989c965054f6171f9db9c00775d5642d7d4210da909c2501cca7c66a68b5e319385e81d579a0cdf389d7362873e95b6d5f4bc3fe84ed1004d70071
@@ -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.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,7 @@
1
+ Release 2.2.0 - 2024/08/02
2
+
3
+ * in_prometheus: Add gzip support (Add a new parameter `content_encoding gzip`)
4
+
1
5
  Release 2.1.0 - 2023/06/15
2
6
 
3
7
  * 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.
@@ -492,7 +493,7 @@ In this case, `message_foo_counter` has `tag`, `hostname`, `key` and `data_type`
492
493
  Checkout repository and setup.
493
494
 
494
495
  ```
495
- $ git clone git://github.com/fluent/fluent-plugin-prometheus
496
+ $ git clone git://github.com/fluent/fluent-plugin-prometheus.git
496
497
  $ cd fluent-plugin-prometheus
497
498
  $ bundle install --path vendor/bundle
498
499
  ```
@@ -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.0"
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,
@@ -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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro Sano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-15 00:00:00.000000000 Z
11
+ date: 2024-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd