fluent-plugin-prometheus 2.2.1 → 2.3.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.
@@ -289,7 +289,12 @@ end
289
289
 
290
290
  shared_examples_for 'instruments record' do
291
291
  before do
292
- driver.run(default_tag: tag) { driver.feed(event_time, message) }
292
+ # Should not shut down driver because it will be used in subsequent tests.
293
+ driver.run(default_tag: tag, shutdown: false) { driver.feed(event_time, message) }
294
+ end
295
+
296
+ after do
297
+ driver.instance_shutdown
293
298
  end
294
299
 
295
300
  context 'full config' do
@@ -385,6 +390,113 @@ shared_examples_for 'instruments record' do
385
390
  end
386
391
  end
387
392
 
393
+ shared_examples_for 'limits label expansion' do
394
+ # the limit is enforced by the shared Metric class, but each plugin reaches
395
+ # it through its own path (instrument_single vs instrument), so both are run
396
+ # against these examples
397
+ def limited_config(options)
398
+ BASE_CONFIG + options + %[
399
+ <metric>
400
+ name limited
401
+ type counter
402
+ desc Something foo.
403
+ key foo
404
+ <labels>
405
+ path $.path
406
+ </labels>
407
+ </metric>
408
+ ]
409
+ end
410
+
411
+ def drop_logs
412
+ driver.logs.select { |log| log.include?('dropped a label set') }
413
+ end
414
+
415
+ def dropped_label_sets
416
+ registry.metrics.find { |metric| metric.name == :fluentd_prometheus_dropped_label_sets_total }
417
+ end
418
+
419
+ let(:counter) { registry.get(:limited) }
420
+
421
+ context 'without any limit configured' do
422
+ let(:config) { limited_config('') }
423
+
424
+ it 'is unlimited by default' do
425
+ expect(driver.instance.max_series_per_metric).to eq(0)
426
+ end
427
+
428
+ it 'keeps every label set' do
429
+ driver.run(default_tag: tag) do
430
+ driver.feed(event_time, {'foo' => 1, 'path' => '/a'})
431
+ driver.feed(event_time, {'foo' => 1, 'path' => '/b'})
432
+ end
433
+
434
+ expect(counter.values.keys).to eq([{path: '/a'}, {path: '/b'}])
435
+ expect(drop_logs).to be_empty
436
+ # nothing was dropped, so the counter is not even registered
437
+ expect(dropped_label_sets).to be_nil
438
+ end
439
+ end
440
+
441
+ context 'with max_series_per_metric' do
442
+ let(:config) { limited_config(%[max_series_per_metric 1\n]) }
443
+
444
+ it 'drops a new label set once the limit is reached' do
445
+ driver.run(default_tag: tag) do
446
+ driver.feed(event_time, {'foo' => 1, 'path' => '/a'})
447
+ driver.feed(event_time, {'foo' => 1, 'path' => '/b'})
448
+ end
449
+
450
+ expect(counter.values.keys).to eq([{path: '/a'}])
451
+ end
452
+
453
+ it 'keeps instrumenting a known label set after the limit is reached' do
454
+ driver.run(default_tag: tag) do
455
+ driver.feed(event_time, {'foo' => 1, 'path' => '/a'})
456
+ driver.feed(event_time, {'foo' => 1, 'path' => '/b'})
457
+ driver.feed(event_time, {'foo' => 1, 'path' => '/a'})
458
+ end
459
+
460
+ expect(counter.get(labels: {path: '/a'})).to eq(2)
461
+ end
462
+
463
+ it 'does not consume the limit by a label set which failed to be instrumented' do
464
+ driver.run(default_tag: tag) do
465
+ # a non numeric value is refused before the label set is reserved
466
+ driver.feed(event_time, {'foo' => 'not a number', 'path' => '/a'})
467
+ driver.feed(event_time, {'foo' => 1, 'path' => '/b'})
468
+ end
469
+
470
+ expect(driver.error_events.size).to eq(1)
471
+ expect(counter.values.keys).to eq([{path: '/b'}])
472
+ expect(drop_logs).to be_empty
473
+ end
474
+
475
+ it 'counts every dropped record, while the log is throttled' do
476
+ driver.run(default_tag: tag) do
477
+ driver.feed(event_time, {'foo' => 1, 'path' => '/a'})
478
+ driver.feed(event_time, {'foo' => 1, 'path' => '/b'})
479
+ driver.feed(event_time, {'foo' => 1, 'path' => '/c'})
480
+ end
481
+
482
+ expect(dropped_label_sets.values).to eq({{name: 'limited'} => 2.0})
483
+ expect(drop_logs.size).to eq(1)
484
+ end
485
+
486
+ # the same label set is refused again and again, and each record which
487
+ # brought it is lost
488
+ it 'counts a label set which is dropped more than once every time' do
489
+ driver.run(default_tag: tag) do
490
+ driver.feed(event_time, {'foo' => 1, 'path' => '/a'})
491
+ driver.feed(event_time, {'foo' => 1, 'path' => '/b'})
492
+ driver.feed(event_time, {'foo' => 1, 'path' => '/b'})
493
+ end
494
+
495
+ expect(dropped_label_sets.values).to eq({{name: 'limited'} => 2.0})
496
+ end
497
+ end
498
+ end
499
+
388
500
  shared_examples_for 'initalized metrics' do
389
501
  before do
390
502
  driver.run(default_tag: tag)
data/spec/spec_helper.rb CHANGED
@@ -8,3 +8,21 @@ Test::Unit::AutoRunner.need_auto_run = false
8
8
 
9
9
  Fluent::Test.setup
10
10
  include Fluent::Test::Helpers
11
+
12
+ def ipv6_enabled?
13
+ require 'socket'
14
+
15
+ begin
16
+ # Try to actually bind to an IPv6 address to verify it works
17
+ sock = Socket.new(Socket::AF_INET6, Socket::SOCK_STREAM, 0)
18
+ sock.bind(Socket.sockaddr_in(0, '::1'))
19
+ sock.close
20
+
21
+ # Also test that we can resolve IPv6 addresses
22
+ # This is needed because some systems can bind but can't connect
23
+ Socket.getaddrinfo('::1', nil, Socket::AF_INET6)
24
+ true
25
+ rescue Errno::EADDRNOTAVAIL, Errno::EAFNOSUPPORT, SocketError
26
+ false
27
+ end
28
+ end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-prometheus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro Sano
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-03-25 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: fluentd
@@ -107,7 +106,11 @@ executables: []
107
106
  extensions: []
108
107
  extra_rdoc_files: []
109
108
  files:
109
+ - ".github/ISSUE_TEMPLATE/bug_report.yaml"
110
+ - ".github/ISSUE_TEMPLATE/config.yml"
111
+ - ".github/ISSUE_TEMPLATE/feature_request.yaml"
110
112
  - ".github/dependabot.yml"
113
+ - ".github/workflows/add-to-project.yml"
111
114
  - ".github/workflows/linux.yml"
112
115
  - ".gitignore"
113
116
  - ".rspec"
@@ -125,6 +128,7 @@ files:
125
128
  - lib/fluent/plugin/in_prometheus_tail_monitor.rb
126
129
  - lib/fluent/plugin/out_prometheus.rb
127
130
  - lib/fluent/plugin/prometheus.rb
131
+ - lib/fluent/plugin/prometheus/log_throttle.rb
128
132
  - lib/fluent/plugin/prometheus/placeholder_expander.rb
129
133
  - lib/fluent/plugin/prometheus_metrics.rb
130
134
  - misc/fluentd_sample.conf
@@ -136,7 +140,9 @@ files:
136
140
  - spec/fluent/plugin/in_prometheus_spec.rb
137
141
  - spec/fluent/plugin/in_prometheus_tail_monitor_spec.rb
138
142
  - spec/fluent/plugin/out_prometheus_spec.rb
143
+ - spec/fluent/plugin/prometheus/log_throttle_spec.rb
139
144
  - spec/fluent/plugin/prometheus/placeholder_expander_spec.rb
145
+ - spec/fluent/plugin/prometheus/series_limit_spec.rb
140
146
  - spec/fluent/plugin/prometheus_metrics_spec.rb
141
147
  - spec/fluent/plugin/shared.rb
142
148
  - spec/spec_helper.rb
@@ -144,7 +150,6 @@ homepage: https://github.com/fluent/fluent-plugin-prometheus
144
150
  licenses:
145
151
  - Apache-2.0
146
152
  metadata: {}
147
- post_install_message:
148
153
  rdoc_options: []
149
154
  require_paths:
150
155
  - lib
@@ -159,8 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
164
  - !ruby/object:Gem::Version
160
165
  version: '0'
161
166
  requirements: []
162
- rubygems_version: 3.5.22
163
- signing_key:
167
+ rubygems_version: 3.6.9
164
168
  specification_version: 4
165
169
  summary: A fluent plugin that collects metrics and exposes for Prometheus.
166
170
  test_files:
@@ -169,7 +173,9 @@ test_files:
169
173
  - spec/fluent/plugin/in_prometheus_spec.rb
170
174
  - spec/fluent/plugin/in_prometheus_tail_monitor_spec.rb
171
175
  - spec/fluent/plugin/out_prometheus_spec.rb
176
+ - spec/fluent/plugin/prometheus/log_throttle_spec.rb
172
177
  - spec/fluent/plugin/prometheus/placeholder_expander_spec.rb
178
+ - spec/fluent/plugin/prometheus/series_limit_spec.rb
173
179
  - spec/fluent/plugin/prometheus_metrics_spec.rb
174
180
  - spec/fluent/plugin/shared.rb
175
181
  - spec/spec_helper.rb