logstash-output-influxdb2 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/logstash/outputs/influxdb2.rb +18 -23
- data/logstash-output-influxdb2.gemspec +1 -1
- data/spec/outputs/influxdb2_spec.rb +52 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dfd75d3189d4c6d414de1de45c4bc1cc238edab17b80c46f5854b69d40bf2a2
|
4
|
+
data.tar.gz: 016e508f44b388e632fa97a06fb8643691083b174495261305e48285d645da27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dc471f8845297d388f0cec6954da91b4d43149119df5bc5fa6c1a92fb3be740b523352728a95acf4f01159d95d0b21c0c3494dfacceb7219eed1593f9bf8abc
|
7
|
+
data.tar.gz: 3841350260e5bb965517caa45ce513a047dd6ec3046f0ff54c3e7703709158c3c5fd6eef4aef01297c9d22feeaaa7a963d15783941f93d43ac3eb9156f4e4b72
|
data/CHANGELOG.md
CHANGED
@@ -14,12 +14,9 @@ class LogStash::Outputs::InfluxDB2 < LogStash::Outputs::Base
|
|
14
14
|
config :write_options, :validate => :hash, :default => {}
|
15
15
|
|
16
16
|
config :measurement, :validate => :string, :required => true
|
17
|
-
config :tags, :validate => :string
|
17
|
+
config :tags, :validate => :string
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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.empty?
|
34
|
+
|
35
|
+
tags = @tags.nil? ? nil : 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.
|
3
|
+
s.version = '0.4.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'
|
@@ -14,7 +14,6 @@ describe LogStash::Outputs::InfluxDB2 do
|
|
14
14
|
"url" => "http://localhost:8086",
|
15
15
|
"token" => "token123",
|
16
16
|
"measurement" => "%{[kubernetes][labels][app]}",
|
17
|
-
"tags" => "[prometheus][labels]",
|
18
17
|
"fields" => "[prometheus][metrics]"
|
19
18
|
}
|
20
19
|
end
|
@@ -56,10 +55,8 @@ describe LogStash::Outputs::InfluxDB2 do
|
|
56
55
|
expect(write_options.batch_abort_on_exception).to be false
|
57
56
|
|
58
57
|
expect(subject.instance_variable_get(:@measurement)).to eq "%{[kubernetes][labels][app]}"
|
59
|
-
expect(subject.instance_variable_get(:@tags)).to
|
58
|
+
expect(subject.instance_variable_get(:@tags)).to be_nil
|
60
59
|
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
60
|
expect(subject.instance_variable_get(:@escape_value)).to be false
|
64
61
|
end
|
65
62
|
|
@@ -100,8 +97,6 @@ describe LogStash::Outputs::InfluxDB2 do
|
|
100
97
|
"measurement" => "%{[kubernetes][labels][app]}",
|
101
98
|
"tags" => "[prometheus][labels]",
|
102
99
|
"fields" => "[prometheus][metrics]",
|
103
|
-
"include_tags" => [ "foo", "abc" ],
|
104
|
-
"exclude_tags" => [ "bar", "xyz" ],
|
105
100
|
"escape_value" => true
|
106
101
|
}
|
107
102
|
end
|
@@ -145,8 +140,6 @@ describe LogStash::Outputs::InfluxDB2 do
|
|
145
140
|
expect(subject.instance_variable_get(:@measurement)).to eq "%{[kubernetes][labels][app]}"
|
146
141
|
expect(subject.instance_variable_get(:@tags)).to eq "[prometheus][labels]"
|
147
142
|
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
143
|
expect(subject.instance_variable_get(:@escape_value)).to be true
|
151
144
|
end
|
152
145
|
|
@@ -288,7 +281,7 @@ describe LogStash::Outputs::InfluxDB2 do
|
|
288
281
|
|
289
282
|
end
|
290
283
|
|
291
|
-
context "validate payload -
|
284
|
+
context "validate payload - invalid event" do
|
292
285
|
|
293
286
|
let(:config) do
|
294
287
|
{
|
@@ -297,10 +290,7 @@ describe LogStash::Outputs::InfluxDB2 do
|
|
297
290
|
"options" => { "bucket" => "test-bucket", "org" => "test-org", "precision" => "ms" },
|
298
291
|
"measurement" => "%{[kubernetes][labels][app]}",
|
299
292
|
"tags" => "[prometheus][labels]",
|
300
|
-
"fields" => "[prometheus][metrics]"
|
301
|
-
"include_tags" => [ "foo", "abc", "test" ],
|
302
|
-
"exclude_tags" => [ "bar", "xyz", "test" ],
|
303
|
-
"escape_value" => true
|
293
|
+
"fields" => "[prometheus][metrics]"
|
304
294
|
}
|
305
295
|
end
|
306
296
|
|
@@ -314,12 +304,53 @@ describe LogStash::Outputs::InfluxDB2 do
|
|
314
304
|
"@timestamp" => "2020-01-01T00:00:00Z",
|
315
305
|
"kubernetes" => { "labels" => { "app" => "dummy" } },
|
316
306
|
"prometheus" => {
|
317
|
-
"labels" => {
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
307
|
+
"labels" => { "foo" => "bar", "abc" => "xyz" }
|
308
|
+
# Invalid: no metrics!
|
309
|
+
}
|
310
|
+
))
|
311
|
+
|
312
|
+
subject.receive(LogStash::Event.new(
|
313
|
+
"@timestamp" => "2020-01-01T00:00:00Z",
|
314
|
+
"kubernetes" => { "labels" => { "app" => "dummy" } },
|
315
|
+
"prometheus" => {
|
316
|
+
"labels" => { "foo" => "bar", "abc" => "xyz" },
|
317
|
+
"metrics" => {} # Invalid: no metrics!
|
318
|
+
}
|
319
|
+
))
|
320
|
+
|
321
|
+
subject.receive(LogStash::Event.new(
|
322
|
+
"@timestamp" => "2020-01-01T00:00:00Z",
|
323
|
+
"kubernetes" => { "labels" => { "app" => "dummy" } },
|
324
|
+
"prometheus" => {
|
325
|
+
"labels" => { "foo" => "bar", "abc" => "xyz" },
|
326
|
+
"metrics" => 123.0 # Invalid: metrics are not a hash!
|
327
|
+
}
|
328
|
+
))
|
329
|
+
|
330
|
+
subject.receive(LogStash::Event.new(
|
331
|
+
"@timestamp" => "2020-01-01T00:00:00Z",
|
332
|
+
"kubernetes" => { "labels" => { "app" => "dummy" } },
|
333
|
+
"prometheus" => {
|
334
|
+
# Valid: no labels!
|
335
|
+
"metrics" => { "count" => 123.0 }
|
336
|
+
}
|
337
|
+
))
|
338
|
+
|
339
|
+
subject.receive(LogStash::Event.new(
|
340
|
+
"@timestamp" => "2020-01-01T00:00:00Z",
|
341
|
+
"kubernetes" => { "labels" => { "app" => "dummy" } },
|
342
|
+
"prometheus" => {
|
343
|
+
"labels" => {}, # Valid: no labels!
|
344
|
+
"metrics" => { "count" => 123.0 }
|
345
|
+
}
|
346
|
+
))
|
347
|
+
|
348
|
+
subject.receive(LogStash::Event.new(
|
349
|
+
"@timestamp" => "2020-01-01T00:00:00Z",
|
350
|
+
"kubernetes" => { "labels" => { "app" => "dummy" } },
|
351
|
+
"prometheus" => {
|
352
|
+
"labels" => "test", # Invalid: labels are not a hash!
|
353
|
+
"metrics" => { "count" => 123.0 }
|
323
354
|
}
|
324
355
|
))
|
325
356
|
|
@@ -330,8 +361,8 @@ describe LogStash::Outputs::InfluxDB2 do
|
|
330
361
|
write_api = subject.instance_variable_get(:@write_api)
|
331
362
|
|
332
363
|
expect(write_api).to have_received(:write_raw)
|
333
|
-
.with('dummy
|
334
|
-
{:bucket=>"test-bucket", :org=>"test-org", :precision=>"ms"})
|
364
|
+
.with('dummy count=123.0 1577836800000',
|
365
|
+
{:bucket=>"test-bucket", :org=>"test-org", :precision=>"ms"}).twice
|
335
366
|
end
|
336
367
|
|
337
368
|
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.
|
4
|
+
version: 0.4.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-
|
11
|
+
date: 2023-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstash-core-plugin-api
|