logstash-output-influxdb2 0.2.0 → 0.3.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: 7f1923cfcb3ce2d41a66adcd3be3d3226e9715e56046c15982555b8e96696406
4
- data.tar.gz: c06683b3e4dda36a47a71c6524c4293c221d85341a273d65ccaa42d13448455d
3
+ metadata.gz: 035f5cd14ba056bc64a0ebb7b72ec8105971a77c1e783999eddda344f2ad4484
4
+ data.tar.gz: 5cdefdfb6a6e97a61a8846966c8d107255180d07eabcdc6212c69493f55f76ca
5
5
  SHA512:
6
- metadata.gz: 57df12c97e4445ea07b765157fdf75809cba9fa5f7ce8cc386d713e051c17fbbfadf85c2e098962334e47570ffe749064e4a36c63804484a899aae86ea1497b6
7
- data.tar.gz: 8b7e1db0e716c92b45d6983a7cb722933222dd2faa482c605cb395eee1b18f52a57485b429c36dbb85e8faf34cf0b286f1777af68ca6e10c03591da6ed2c79ba
6
+ metadata.gz: 4b4b6dc6bc430e96604061857a124e2e333b89ea21ccab0a5c09d51462272a0fa872513cc89bcd1264c2e11c72f05e76bb5667e4a633316ef626d279c48bdc1e
7
+ data.tar.gz: f617a63ae417d5c778e0e569f9ac22a40f621011ea83f116889721604582ae45ae2537c61be4aa1ce9c5a4d7a0dc2682dd0755940fc3417f3984e8e4cebda3f8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.0
2
+ - Add guards for invalid event
3
+ - Remove include_tags and exclude_tags
4
+
1
5
  ## 0.2.0
2
6
  - Add a copyright notice
3
7
  - Update gemspec summary
@@ -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,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-influxdb2'
3
- s.version = '0.2.0'
3
+ s.version = '0.3.0'
4
4
  s.licenses = ['Apache-2.0']
5
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'
@@ -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.2.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-11-13 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