fluent-plugin-influxdb-v2 1.9.0.pre.1328 → 1.9.0.pre.1341

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: a162e715eaf1dee93dc05d613df4da916d5f81ef6321eefbf6e723961113e520
4
- data.tar.gz: b79ade354978657ab2c2ef3c91e45101ce382a8b62a6a53fb39c0614a158df4b
3
+ metadata.gz: e01f201d71085c9b0a82def242dd80df362cf783cc4bd22cdd280748bb2fea8f
4
+ data.tar.gz: fd52d6977a87054dd6805f3c0a8e825f11a0d680119445a48d38d436e32dbf11
5
5
  SHA512:
6
- metadata.gz: 4013c2885ae49e89fdaa5c0f70a75dc60773a8a28e4496a575c1b659e6248d81facd6e7b445902775a003468c9ff4f29847f7103c6d2fae4fd1e7d8335c53af6
7
- data.tar.gz: b730665dd393f67da8eba3ad5553093593ddec5325c3e7316d4af14afe640e04045b1d6b34983879fbe4e72bed6ee2d7a74dc9ed1610cc52746740f412ded8e2
6
+ metadata.gz: 8ef6bb9981eaac83e2394892838edf29286672e98adf72a9183f2d088403cc24ee07c01a87726b3647a727ba5eb4e51f139b3814960c3541a9ab2535b0cf00dd
7
+ data.tar.gz: 52486af50894534c7d05f42c97c736a7d748e7103edc20505164a6ba6822fa13fb25de6e714df4d06f296c7e65b9b9f6c06f01b6cab1a1b58ea47a6cdbf9bd94
data/CHANGELOG.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  ### Features
4
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.
5
6
 
6
7
  ### Dependencies
7
8
  1. [#30](https://github.com/influxdata/influxdb-plugin-fluent/pull/30): Update dependencies:
data/README.md CHANGED
@@ -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
 
@@ -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,22 +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
- time_formatted = _format_time(time)
125
- point = InfluxDB2::Point
126
- .new(name: measurement)
127
- record.each_pair do |k, v|
128
- if k.eql?(@time_key)
129
- time_formatted = _format_time(v)
130
- else
131
- _parse_field(k, v, point)
129
+ if @line_protocol_key
130
+ points << record[@line_protocol_key] if record.include?(@line_protocol_key)
131
+ else
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
132
142
  end
133
- point.add_tag('fluentd', tag) if @tag_fluentd
143
+ point.time(time_formatted, @precision)
144
+ points << point
134
145
  end
135
- point.time(time_formatted, @precision)
136
- points << point
137
146
  end
138
- @write_api.write(data: points, bucket: bucket)
139
- 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
140
153
  end
141
154
 
142
155
  private
@@ -586,4 +586,39 @@ class InfluxDBOutputTest < Minitest::Test
586
586
  assert_requested(:post, 'https://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
587
587
  times: 1, body: 'placeholder_h2o_tag level=2i,location="europe" 1444897215000000000')
588
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
589
624
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.1328
4
+ version: 1.9.0.pre.1341
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Bednar