logstash-output-influxdb2 0.1.0 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32cf6c3b489b3187d756694ebc95bd38958bd6015d52099636a30807dcf33057
4
- data.tar.gz: df4f9f1018b646ed2bcd1f8563fef4486250d6b8b3d9a4eb9d24e9fe5ab25520
3
+ metadata.gz: 035f5cd14ba056bc64a0ebb7b72ec8105971a77c1e783999eddda344f2ad4484
4
+ data.tar.gz: 5cdefdfb6a6e97a61a8846966c8d107255180d07eabcdc6212c69493f55f76ca
5
5
  SHA512:
6
- metadata.gz: 3c4cf17dbbb2e351f76fb90043c2c27130ad4f63e20080f3c5d482a8fd9160a624c6014524aad34a0884991f725b5d02e424bbd60be566df57d90dbe09fd1987
7
- data.tar.gz: 537a2034ea93b378442d9cac711f5688a40b6052d336631324e151a1a3f6202e709bdd16f735b2e0609cb456731cd3806ee16959c53f6523c7e4d5ed903d1c2f
6
+ metadata.gz: 4b4b6dc6bc430e96604061857a124e2e333b89ea21ccab0a5c09d51462272a0fa872513cc89bcd1264c2e11c72f05e76bb5667e4a633316ef626d279c48bdc1e
7
+ data.tar.gz: f617a63ae417d5c778e0e569f9ac22a40f621011ea83f116889721604582ae45ae2537c61be4aa1ce9c5a4d7a0dc2682dd0755940fc3417f3984e8e4cebda3f8
data/CHANGELOG.md CHANGED
@@ -1,2 +1,10 @@
1
+ ## 0.3.0
2
+ - Add guards for invalid event
3
+ - Remove include_tags and exclude_tags
4
+
5
+ ## 0.2.0
6
+ - Add a copyright notice
7
+ - Update gemspec summary
8
+
1
9
  ## 0.1.0
2
- - Plugin created with the logstash plugin generator
10
+ - First release
data/Gemfile CHANGED
@@ -7,4 +7,3 @@ if Dir.exist?(logstash_path)
7
7
  gem 'logstash-core', :path => "#{logstash_path}/logstash-core"
8
8
  gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api"
9
9
  end
10
-
data/LICENSE CHANGED
@@ -187,7 +187,7 @@
187
187
  same "printed page" as the copyright notice for easier
188
188
  identification within third-party archives.
189
189
 
190
- Copyright [yyyy] [name of copyright owner]
190
+ Copyright 2023 Issey Yamakoshi
191
191
 
192
192
  Licensed under the Apache License, Version 2.0 (the "License");
193
193
  you may not use this file except in compliance with the License.
data/NOTICE.TXT ADDED
@@ -0,0 +1,7 @@
1
+ logstash-output-influxdb2
2
+ Copyright 2023 Issey Yamakoshi
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
6
+
7
+ I will donate the source if Elastic wonts.
@@ -17,9 +17,6 @@ class LogStash::Outputs::InfluxDB2 < LogStash::Outputs::Base
17
17
  config :tags, :validate => :string, :required => true
18
18
  config :fields, :validate => :string, :required => true
19
19
 
20
- config :include_tags, :validate => :string, :list => true, :default => []
21
- config :exclude_tags, :validate => :string, :list => true, :default => []
22
-
23
20
  config :escape_value, :validate => :boolean, :default => false
24
21
 
25
22
  public
@@ -32,26 +29,24 @@ class LogStash::Outputs::InfluxDB2 < LogStash::Outputs::Base
32
29
 
33
30
  public
34
31
  def receive(event)
35
- begin
36
- tags = event.get(@tags)
37
- unless @include_tags.empty?
38
- tags = tags.select { |k,v| @include_tags.include?(k) }
39
- end
40
- unless @exclude_tags.empty?
41
- tags = tags.select { |k,v| ! @exclude_tags.include?(k) }
42
- end
43
- fields = event.get(@fields)
44
- unless @escape_value
45
- fields = fields.transform_values { |v| ToStr.new(v) }
46
- end
47
- @write_api.write(data: InfluxDB2::Point.new(
48
- name: event.sprintf(@measurement), tags: tags, fields: fields,
49
- time: event.timestamp.time, precision: @precision))
50
- rescue InfluxDB2::InfluxError => ie
51
- @logger.warn("HTTP communication error while writing to InfluxDB", :exception => ie)
52
- rescue Exception => e
53
- @logger.warn("Non recoverable exception while writing to InfluxDB", :exception => e)
32
+ fields = event.get(@fields)
33
+ return unless fields.is_a?(Hash) && fields.size > 0
34
+
35
+ tags = event.get(@tags)
36
+ return unless tags.nil? || tags.is_a?(Hash)
37
+
38
+ unless @escape_value
39
+ fields = fields.transform_values { |v| ToStr.new(v) }
54
40
  end
41
+
42
+ @write_api.write(data: InfluxDB2::Point.new(
43
+ name: event.sprintf(@measurement), tags: tags, fields: fields,
44
+ time: event.timestamp.time, precision: @precision))
45
+
46
+ rescue InfluxDB2::InfluxError => ie
47
+ @logger.warn("HTTP communication error while writing to InfluxDB", :exception => ie)
48
+ rescue Exception => e
49
+ @logger.warn("Non recoverable exception while writing to InfluxDB", :exception => e)
55
50
  end # def event
56
51
 
57
52
  def close
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-influxdb2'
3
- s.version = '0.1.0'
3
+ s.version = '0.3.0'
4
4
  s.licenses = ['Apache-2.0']
5
- s.summary = 'Logstash Output Plugin for InfluxDB2'
5
+ s.summary = 'Writes metrics to InfluxDB 2.x'
6
6
  s.description = 'This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program'
7
7
  s.homepage = 'https://github.com/r16turbo/logstash-output-influxdb2'
8
8
  s.authors = ['Issey Yamakoshi']
@@ -11,7 +11,8 @@ Gem::Specification.new do |s|
11
11
 
12
12
  # Files
13
13
  s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
- # Tests
14
+
15
+ # Tests
15
16
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
17
 
17
18
  # Special flag to let us know this is actually a logstash plugin
@@ -58,8 +58,6 @@ describe LogStash::Outputs::InfluxDB2 do
58
58
  expect(subject.instance_variable_get(:@measurement)).to eq "%{[kubernetes][labels][app]}"
59
59
  expect(subject.instance_variable_get(:@tags)).to eq "[prometheus][labels]"
60
60
  expect(subject.instance_variable_get(:@fields)).to eq "[prometheus][metrics]"
61
- expect(subject.instance_variable_get(:@include_tags)).to eq []
62
- expect(subject.instance_variable_get(:@exclude_tags)).to eq []
63
61
  expect(subject.instance_variable_get(:@escape_value)).to be false
64
62
  end
65
63
 
@@ -100,8 +98,6 @@ describe LogStash::Outputs::InfluxDB2 do
100
98
  "measurement" => "%{[kubernetes][labels][app]}",
101
99
  "tags" => "[prometheus][labels]",
102
100
  "fields" => "[prometheus][metrics]",
103
- "include_tags" => [ "foo", "abc" ],
104
- "exclude_tags" => [ "bar", "xyz" ],
105
101
  "escape_value" => true
106
102
  }
107
103
  end
@@ -145,8 +141,6 @@ describe LogStash::Outputs::InfluxDB2 do
145
141
  expect(subject.instance_variable_get(:@measurement)).to eq "%{[kubernetes][labels][app]}"
146
142
  expect(subject.instance_variable_get(:@tags)).to eq "[prometheus][labels]"
147
143
  expect(subject.instance_variable_get(:@fields)).to eq "[prometheus][metrics]"
148
- expect(subject.instance_variable_get(:@include_tags)).to eq [ "foo", "abc" ]
149
- expect(subject.instance_variable_get(:@exclude_tags)).to eq [ "bar", "xyz" ]
150
144
  expect(subject.instance_variable_get(:@escape_value)).to be true
151
145
  end
152
146
 
@@ -288,7 +282,7 @@ describe LogStash::Outputs::InfluxDB2 do
288
282
 
289
283
  end
290
284
 
291
- context "validate payload - tag filter" do
285
+ context "validate payload - invalid event" do
292
286
 
293
287
  let(:config) do
294
288
  {
@@ -297,10 +291,7 @@ describe LogStash::Outputs::InfluxDB2 do
297
291
  "options" => { "bucket" => "test-bucket", "org" => "test-org", "precision" => "ms" },
298
292
  "measurement" => "%{[kubernetes][labels][app]}",
299
293
  "tags" => "[prometheus][labels]",
300
- "fields" => "[prometheus][metrics]",
301
- "include_tags" => [ "foo", "abc", "test" ],
302
- "exclude_tags" => [ "bar", "xyz", "test" ],
303
- "escape_value" => true
294
+ "fields" => "[prometheus][metrics]"
304
295
  }
305
296
  end
306
297
 
@@ -314,12 +305,53 @@ describe LogStash::Outputs::InfluxDB2 do
314
305
  "@timestamp" => "2020-01-01T00:00:00Z",
315
306
  "kubernetes" => { "labels" => { "app" => "dummy" } },
316
307
  "prometheus" => {
317
- "labels" => {
318
- "foo" => "bar", "abc" => "xyz",
319
- "bar" => "foo", "xyz" => "abc",
320
- "test" => "123"
321
- },
322
- "metrics" => { "message" => "Hello World!" }
308
+ "labels" => { "foo" => "bar", "abc" => "xyz" }
309
+ # Invalid: no metrics!
310
+ }
311
+ ))
312
+
313
+ subject.receive(LogStash::Event.new(
314
+ "@timestamp" => "2020-01-01T00:00:00Z",
315
+ "kubernetes" => { "labels" => { "app" => "dummy" } },
316
+ "prometheus" => {
317
+ "labels" => { "foo" => "bar", "abc" => "xyz" },
318
+ "metrics" => {} # Invalid: no metrics!
319
+ }
320
+ ))
321
+
322
+ subject.receive(LogStash::Event.new(
323
+ "@timestamp" => "2020-01-01T00:00:00Z",
324
+ "kubernetes" => { "labels" => { "app" => "dummy" } },
325
+ "prometheus" => {
326
+ "labels" => { "foo" => "bar", "abc" => "xyz" },
327
+ "metrics" => 123.0 # Invalid: metrics are not a hash!
328
+ }
329
+ ))
330
+
331
+ subject.receive(LogStash::Event.new(
332
+ "@timestamp" => "2020-01-01T00:00:00Z",
333
+ "kubernetes" => { "labels" => { "app" => "dummy" } },
334
+ "prometheus" => {
335
+ "metrics" => { "count" => 123.0 }
336
+ # Valid: no labels!
337
+ }
338
+ ))
339
+
340
+ subject.receive(LogStash::Event.new(
341
+ "@timestamp" => "2020-01-01T00:00:00Z",
342
+ "kubernetes" => { "labels" => { "app" => "dummy" } },
343
+ "prometheus" => {
344
+ "labels" => {}, # Valid: no labels!
345
+ "metrics" => { "count" => 123.0 }
346
+ }
347
+ ))
348
+
349
+ subject.receive(LogStash::Event.new(
350
+ "@timestamp" => "2020-01-01T00:00:00Z",
351
+ "kubernetes" => { "labels" => { "app" => "dummy" } },
352
+ "prometheus" => {
353
+ "labels" => "test", # Invalid: labels are not a hash!
354
+ "metrics" => { "count" => 123.0 }
323
355
  }
324
356
  ))
325
357
 
@@ -330,8 +362,8 @@ describe LogStash::Outputs::InfluxDB2 do
330
362
  write_api = subject.instance_variable_get(:@write_api)
331
363
 
332
364
  expect(write_api).to have_received(:write_raw)
333
- .with('dummy,abc=xyz,foo=bar message="Hello World!" 1577836800000',
334
- {:bucket=>"test-bucket", :org=>"test-org", :precision=>"ms"})
365
+ .with('dummy count=123.0 1577836800000',
366
+ {:bucket=>"test-bucket", :org=>"test-org", :precision=>"ms"}).twice
335
367
  end
336
368
 
337
369
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-influxdb2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Issey Yamakoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-30 00:00:00.000000000 Z
11
+ date: 2023-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core-plugin-api
@@ -62,9 +62,9 @@ extra_rdoc_files: []
62
62
  files:
63
63
  - CHANGELOG.md
64
64
  - CONTRIBUTORS
65
- - DEVELOPER.md
66
65
  - Gemfile
67
66
  - LICENSE
67
+ - NOTICE.TXT
68
68
  - README.md
69
69
  - lib/logstash/outputs/influxdb2.rb
70
70
  - logstash-output-influxdb2.gemspec
@@ -93,6 +93,6 @@ requirements: []
93
93
  rubygems_version: 3.3.5
94
94
  signing_key:
95
95
  specification_version: 4
96
- summary: Logstash Output Plugin for InfluxDB2
96
+ summary: Writes metrics to InfluxDB 2.x
97
97
  test_files:
98
98
  - spec/outputs/influxdb2_spec.rb
data/DEVELOPER.md DELETED
@@ -1,2 +0,0 @@
1
- # logstash-output-influxdb2
2
- Example output plugin. This should help bootstrap your effort to write your own output plugin!