fluent-plugin-influxdb-v2 1.9.0.pre.1209 → 1.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: b407d41fb5654f68fb0e20c644516d23ae03d8cd20ee1782d48915d464f21592
4
- data.tar.gz: 6e643a4848081996dea34367949a362da8ed96f65ebe82ecd28091f91e148729
3
+ metadata.gz: 7852d628e84fafe86b1e3e1890a1fd31a87508e89af9f7e86607ddce5e0c5489
4
+ data.tar.gz: 77981bcfec774bc114c95f80fd9c5e7a921b15d054693f9789d0ce788cfb1e9b
5
5
  SHA512:
6
- metadata.gz: 5458e096b8c9375095056f367451f4fb681a642776d622bd1e6536674c67bd9f8d823c007330d2806a0dd64be9f970014d9b01c59370ba3b4f3eaaa9e47a725f
7
- data.tar.gz: dadf7c323827adaac002f3d8f094150e92e6bb861e33299585d45f2b46704c91622e19ee31163ba6644c5e9d6cd9bacf1e11c50d1d4bd357e1c8d27596341110
6
+ metadata.gz: c635c6bdbe99637c7baa77e9f078391d148f06c5dac55694f970742f3d14dfe3e3eba3c4289d4cbd6569ded29efbf7753bd095fc9cc1062af8cdf59ef3fa9d4a
7
+ data.tar.gz: 364704ae7f9958a0965e7af45f1b2bc059644076cabde2ecb6c873c27b54292188b1cd1425935b9d928c9300fcb049ac537919f881d232b9c98a4dcf7bd55cbe
data/.circleci/config.yml CHANGED
@@ -41,9 +41,9 @@ commands:
41
41
  - restore_cache:
42
42
  name: Restoring Gem Cache
43
43
  keys:
44
- - &cache-key gem-cache-v2-{{ checksum "fluent-plugin-influxdb-v2.gemspec" }}-<< parameters.ruby-image >>
45
- - gem-cache-v2-{{ checksum "fluent-plugin-influxdb-v2.gemspec" }}
46
- - gem-cache-v2-
44
+ - &cache-key gem-cache-v3-{{ checksum "fluent-plugin-influxdb-v2.gemspec" }}-<< parameters.ruby-image >>
45
+ - gem-cache-v3-{{ checksum "fluent-plugin-influxdb-v2.gemspec" }}
46
+ - gem-cache-v3-
47
47
  - run:
48
48
  name: Install dependencies
49
49
  command: |
@@ -120,6 +120,9 @@ workflows:
120
120
  - tests-ruby:
121
121
  name: ruby-2.7
122
122
  ruby-image: "cimg/ruby:2.7"
123
+ - tests-ruby:
124
+ name: ruby-3.0
125
+ ruby-image: "cimg/ruby:3.0"
123
126
  - tests-ruby:
124
127
  name: ruby-2.6
125
128
  - tests-ruby:
@@ -13,4 +13,4 @@ _Briefly describe your proposed changes:_
13
13
  - [ ] A test has been added if appropriate
14
14
  - [ ] `rake test` completes successfully
15
15
  - [ ] Commit messages are in [semantic format](https://seesparkbox.com/foundry/semantic_commit_messages)
16
- - [ ] Sign [CLA](https://influxdata.com/community/cla/) (if not already signed)
16
+ - [ ] Sign [CLA](https://www.influxdata.com/legal/cla/) (if not already signed)
data/CHANGELOG.md CHANGED
@@ -1,7 +1,16 @@
1
- ## 1.9.0 [unreleased]
1
+ ## 1.9.0 [2021-11-26]
2
+
3
+ ### Features
4
+ 1. [#30](https://github.com/influxdata/influxdb-plugin-fluent/pull/30): Field value for `time_key` can be formatted date (`2021-11-05 09:15:49.487727165 +0000`, `2021-11-05T10:04:43.617216Z`)
5
+ 1. [#31](https://github.com/influxdata/influxdb-plugin-fluent/pull/31): Add possibility to use LineProtocol from Fluetd's record.
6
+
7
+ ### Dependencies
8
+ 1. [#30](https://github.com/influxdata/influxdb-plugin-fluent/pull/30): Update dependencies:
9
+ - influxdb-client to 2.1.0
2
10
 
3
11
  ### CI
4
12
  1. [#27](https://github.com/influxdata/influxdb-plugin-fluent/pull/27): Switch to next-gen CircleCI's convenience images
13
+ 1. [#30](https://github.com/influxdata/influxdb-plugin-fluent/pull/30): Add Ruby 3.0 into CI
5
14
 
6
15
  ## 1.8.0 [2021-08-20]
7
16
 
data/README.md CHANGED
@@ -19,7 +19,7 @@ This repository contains the reference Fluentd plugin for the InfluxDB 2.0.
19
19
  The plugin is bundled as a gem and is hosted on [Rubygems](https://rubygems.org/gems/fluent-plugin-influxdb-v2). You can install the gem as follows:
20
20
 
21
21
  ```
22
- fluent-gem install fluent-plugin-influxdb-v2 -v 1.8.0
22
+ fluent-gem install fluent-plugin-influxdb-v2 -v 1.9.0
23
23
  ```
24
24
 
25
25
  ## Plugins
@@ -45,6 +45,7 @@ Store Fluentd event to InfluxDB 2 database.
45
45
  | field_cast_to_float | Turn on/off auto casting Integer value to Float. Helper to avoid mismatch error: 'series type mismatch: already Integer but got Float'. | bool | false |
46
46
  | time_precision | The time precision of timestamp. You should specify either second (s), millisecond (ms), microsecond (us), or nanosecond (ns). | String | ns |
47
47
  | time_key | A name of the record key that used as a 'timestamp' instead of event timestamp. If a record key doesn't exists or hasn't value then is used event timestamp. | String | nil |
48
+ | line_protocol_key | A name of the record key that contains [LineProtocol](https://docs.influxdata.com/influxdb/v2.0/reference/syntax/line-protocol/). The value of this key is used for ingesting data into InfluxDB. If a record key doesn't exists or hasn't value then is used event timestamp. | String | nil |
48
49
 
49
50
  ##### Minimal configuration
50
51
 
@@ -47,7 +47,7 @@ Gem::Specification.new do |spec|
47
47
  spec.required_ruby_version = '>= 2.2.0'
48
48
 
49
49
  spec.add_runtime_dependency 'fluentd', '~> 1.8'
50
- spec.add_runtime_dependency 'influxdb-client', '1.12.0'
50
+ spec.add_runtime_dependency 'influxdb-client', '2.1.0'
51
51
 
52
52
  spec.add_development_dependency 'bundler', '~> 2.0'
53
53
  spec.add_development_dependency 'codecov', '~> 0.1.16'
@@ -73,6 +73,11 @@ class InfluxDBOutput < Fluent::Plugin::Output
73
73
  desc 'A name of the record key that used as a \'timestamp\' instead of event timestamp.' \
74
74
  'If a record key doesn\'t exists or hasn\'t value then is used event timestamp.'
75
75
 
76
+ config_param :line_protocol_key, :string, default: nil
77
+ desc 'A name of the record key that contains \'LineProtocol\'.' \
78
+ 'The value of this key is used for ingesting data into InfluxDB.' \
79
+ 'For more info see - https://docs.influxdata.com/influxdb/v2.0/reference/syntax/line-protocol/.'
80
+
76
81
  config_section :buffer do
77
82
  config_set_default :@type, DEFAULT_BUFFER_TYPE
78
83
  config_set_default :chunk_keys, ['tag']
@@ -121,28 +126,30 @@ class InfluxDBOutput < Fluent::Plugin::Output
121
126
  tag = chunk.metadata.tag
122
127
  bucket, measurement = expand_placeholders(chunk)
123
128
  chunk.msgpack_each do |time, record|
124
- if time.is_a?(Integer)
125
- time_formatted = time
129
+ if @line_protocol_key
130
+ points << record[@line_protocol_key] if record.include?(@line_protocol_key)
126
131
  else
127
- nano_seconds = time.sec * 1e9
128
- nano_seconds += time.nsec
129
- time_formatted = @precision_formatter.call(nano_seconds)
130
- end
131
- point = InfluxDB2::Point
132
- .new(name: measurement)
133
- record.each_pair do |k, v|
134
- if k.eql?(@time_key)
135
- time_formatted = v
136
- else
137
- _parse_field(k, v, point)
132
+ time_formatted = _format_time(time)
133
+ point = InfluxDB2::Point
134
+ .new(name: measurement)
135
+ record.each_pair do |k, v|
136
+ if k.eql?(@time_key)
137
+ time_formatted = _format_time(v)
138
+ else
139
+ _parse_field(k, v, point)
140
+ end
141
+ point.add_tag('fluentd', tag) if @tag_fluentd
138
142
  end
139
- point.add_tag('fluentd', tag) if @tag_fluentd
143
+ point.time(time_formatted, @precision)
144
+ points << point
140
145
  end
141
- point.time(time_formatted, @precision)
142
- points << point
143
146
  end
144
- @write_api.write(data: points, bucket: bucket)
145
- log.debug "Written points: #{points}"
147
+ if points.empty?
148
+ log.debug "Nothing to write for chunk: #{chunk.metadata}"
149
+ else
150
+ @write_api.write(data: points, bucket: bucket)
151
+ log.debug "Written points: #{points}"
152
+ end
146
153
  end
147
154
 
148
155
  private
@@ -157,6 +164,27 @@ class InfluxDBOutput < Fluent::Plugin::Output
157
164
  [bucket, measurement]
158
165
  end
159
166
 
167
+ def _format_time(time)
168
+ if time.is_a?(Integer)
169
+ time
170
+ elsif time.is_a?(Float)
171
+ time
172
+ elsif time.is_a?(Fluent::EventTime)
173
+ nano_seconds = time.sec * 1e9
174
+ nano_seconds += time.nsec
175
+ @precision_formatter.call(nano_seconds)
176
+ elsif time.is_a?(String)
177
+ begin
178
+ _format_time(Fluent::EventTime.parse(time))
179
+ rescue StandardError => e
180
+ log.debug "Cannot parse timestamp: #{time} due: #{e}"
181
+ time
182
+ end
183
+ else
184
+ time
185
+ end
186
+ end
187
+
160
188
  def _parse_field(key, value, point)
161
189
  if @tag_keys.include?(key)
162
190
  point.add_tag(key, value)
data/test/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ #
2
+ # The MIT License
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+
23
+ inherit_from: ../.rubocop.yml
24
+ Metrics/ClassLength:
25
+ Enabled: false
26
+
@@ -381,6 +381,82 @@ class InfluxDBOutputTest < Minitest::Test
381
381
  times: 1, body: 'h2o_tag,version=v.10 level=2i,location="europe" 1544897215000000000')
382
382
  end
383
383
 
384
+ def test_time_float
385
+ stub_request(:any, 'https://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
386
+ .to_return(status: 204)
387
+ driver = create_driver(%(
388
+ @type influxdb2
389
+ token my-token
390
+ bucket my-bucket
391
+ org my-org
392
+ tag_keys ["version"]
393
+ time_key time
394
+ ))
395
+ driver.run(default_tag: 'h2o_tag') do
396
+ emit_documents(driver, 'location' => 'europe', 'level' => 2, 'version' => 'v.10',
397
+ 'time' => 1_544_897_215_000_000_000.123)
398
+ end
399
+ assert_requested(:post, 'https://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
400
+ times: 1, body: 'h2o_tag,version=v.10 level=2i,location="europe" 1544897215000000000')
401
+ end
402
+
403
+ def test_time_key_rfc_3339_format
404
+ stub_request(:any, 'https://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
405
+ .to_return(status: 204)
406
+ driver = create_driver(%(
407
+ @type influxdb2
408
+ token my-token
409
+ bucket my-bucket
410
+ org my-org
411
+ tag_keys ["version"]
412
+ time_key time
413
+ ))
414
+ driver.run(default_tag: 'h2o_tag') do
415
+ emit_documents(driver, 'location' => 'europe', 'level' => 2, 'version' => 'v.10',
416
+ 'time' => '2021-11-05T10:04:43.617216Z')
417
+ end
418
+ assert_requested(:post, 'https://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
419
+ times: 1, body: 'h2o_tag,version=v.10 level=2i,location="europe" 1636106683617216000')
420
+ end
421
+
422
+ def test_time_key_log_format
423
+ stub_request(:any, 'https://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
424
+ .to_return(status: 204)
425
+ driver = create_driver(%(
426
+ @type influxdb2
427
+ token my-token
428
+ bucket my-bucket
429
+ org my-org
430
+ tag_keys ["version"]
431
+ time_key time
432
+ ))
433
+ driver.run(default_tag: 'h2o_tag') do
434
+ emit_documents(driver, 'location' => 'europe', 'level' => 2, 'version' => 'v.10',
435
+ 'time' => '2021-11-05 09:15:49.487727165 +0000')
436
+ end
437
+ assert_requested(:post, 'https://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
438
+ times: 1, body: 'h2o_tag,version=v.10 level=2i,location="europe" 1636103749487727104')
439
+ end
440
+
441
+ def test_time_key_not_parseable
442
+ stub_request(:any, 'https://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
443
+ .to_return(status: 204)
444
+ driver = create_driver(%(
445
+ @type influxdb2
446
+ token my-token
447
+ bucket my-bucket
448
+ org my-org
449
+ tag_keys ["version"]
450
+ time_key time
451
+ ))
452
+ driver.run(default_tag: 'h2o_tag') do
453
+ emit_documents(driver, 'location' => 'europe', 'level' => 2, 'version' => 'v.10',
454
+ 'time' => '1544897215000000000')
455
+ end
456
+ assert_requested(:post, 'https://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
457
+ times: 1, body: 'h2o_tag,version=v.10 level=2i,location="europe" 1544897215000000000')
458
+ end
459
+
384
460
  def test_field_cast_to_float
385
461
  stub_request(:any, 'https://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
386
462
  .to_return(status: 204)
@@ -510,4 +586,39 @@ class InfluxDBOutputTest < Minitest::Test
510
586
  assert_requested(:post, 'https://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
511
587
  times: 1, body: 'placeholder_h2o_tag level=2i,location="europe" 1444897215000000000')
512
588
  end
589
+
590
+ def test_line_protocol
591
+ stub_request(:any, 'https://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
592
+ .to_return(status: 204)
593
+ driver = create_driver(%(
594
+ @type influxdb2
595
+ token my-token
596
+ bucket my-bucket
597
+ org my-org
598
+ time_precision ns
599
+ line_protocol_key lp_key
600
+ ))
601
+ driver.run(default_tag: 'h2o_tag') do
602
+ emit_documents(driver, 'location' => 'europe', 'level' => 2, 'lp_key' => 'mem,tag=1 field=10 102030')
603
+ end
604
+ assert_requested(:post, 'https://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
605
+ times: 1, body: 'mem,tag=1 field=10 102030')
606
+ end
607
+
608
+ def test_line_protocol_not_defined
609
+ stub_request(:any, 'https://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
610
+ .to_return(status: 204)
611
+ driver = create_driver(%(
612
+ @type influxdb2
613
+ token my-token
614
+ bucket my-bucket
615
+ org my-org
616
+ time_precision ns
617
+ line_protocol_key lp_key
618
+ ))
619
+ driver.run(default_tag: 'h2o_tag') do
620
+ emit_documents(driver)
621
+ end
622
+ assert_requested(:post, 'https://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns', times: 0)
623
+ end
513
624
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-influxdb-v2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0.pre.1209
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Bednar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-13 00:00:00.000000000 Z
11
+ date: 2021-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.12.0
33
+ version: 2.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.12.0
40
+ version: 2.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -201,6 +201,7 @@ files:
201
201
  - lib/fluent/plugin/fluent.rb
202
202
  - lib/fluent/plugin/out_influxdb2.rb
203
203
  - lib/fluent/plugin/version.rb
204
+ - test/.rubocop.yml
204
205
  - test/influxdb/plugin/output_test.rb
205
206
  - test/influxdb/plugin/version_test.rb
206
207
  - test/test_helper.rb
@@ -222,15 +223,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
222
223
  version: 2.2.0
223
224
  required_rubygems_version: !ruby/object:Gem::Requirement
224
225
  requirements:
225
- - - ">"
226
+ - - ">="
226
227
  - !ruby/object:Gem::Version
227
- version: 1.3.1
228
+ version: '0'
228
229
  requirements: []
229
- rubygems_version: 3.2.22
230
+ rubygems_version: 3.0.3.1
230
231
  signing_key:
231
232
  specification_version: 4
232
233
  summary: InfluxDB 2 output plugin for Fluentd
233
234
  test_files:
235
+ - test/.rubocop.yml
234
236
  - test/influxdb/plugin/output_test.rb
235
237
  - test/influxdb/plugin/version_test.rb
236
238
  - test/test_helper.rb