logstash-filter-mutate 3.3.1 → 3.3.2
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 +4 -4
- data/CHANGELOG.md +3 -0
- data/docs/index.asciidoc +27 -20
- data/lib/logstash/filters/mutate.rb +13 -6
- data/logstash-filter-mutate.gemspec +1 -1
- data/spec/filters/mutate_spec.rb +146 -0
- 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: 7e984a5018bec5903f3731c447c9e1fffe4b149c0c2e27ce9055e14f21deb9c0
|
4
|
+
data.tar.gz: 2b3c094ca15d06ac17c6746673ca31e40b7ca41b2217bd3c0f0ea8476c27f4c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7286e1ea17e30d46e942a7c8d1a9107c57a11d0158dc7bb979b1ac09c0b85a94159480b8b568b197c73d922369c90c0c85ca8e356e6648b501cc007c28a7fab
|
7
|
+
data.tar.gz: 7480daecb2a3c584302b6296597bc3d0f8583286ace082d6106daf6555c28705ecc73e6d28c0e8b92d41374fedf210f5cac156f5c1e431fa9f33f6709774272d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 3.3.2
|
2
|
+
- Fix: when converting to `float` and `float_eu`, explicitly support same range of inputs as their integer counterparts; eliminates a regression introduced in 3.3.1 in which support for non-string inputs was inadvertently removed.
|
3
|
+
|
1
4
|
## 3.3.1
|
2
5
|
- Fix: Number strings using a **decimal comma** (e.g. 1,23), added convert support to specify integer_eu and float_eu.
|
3
6
|
|
data/docs/index.asciidoc
CHANGED
@@ -62,31 +62,38 @@ Convert a field's value to a different type, like turning a string to an
|
|
62
62
|
integer. If the field value is an array, all members will be converted.
|
63
63
|
If the field is a hash no action will be taken.
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
*
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
e.g
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
65
|
+
Valid conversion targets, and their expected behaviour with different inputs are:
|
66
|
+
|
67
|
+
* `integer`:
|
68
|
+
- strings are parsed; comma-separators are supported (e.g., the string `"1,000"` produces an integer with value of one thousand); when strings have decimal parts, they are _truncated_.
|
69
|
+
- floats and decimals are _truncated_ (e.g., `3.99` becomes `3`, `-2.7` becomes `-2`)
|
70
|
+
- boolean true and boolean false are converted to `1` and `0` respectively
|
71
|
+
* `integer_eu`:
|
72
|
+
- same as `integer`, except string values support dot-separators and comma-decimals (e.g., `"1.000"` produces an integer with value of one thousand)
|
73
|
+
* `float`:
|
74
|
+
- integers are converted to floats
|
75
|
+
- strings are parsed; comma-separators and dot-decimals are supported (e.g., `"1,000.5"` produces an integer with value of one thousand and one half)
|
76
|
+
- boolean true and boolean false are converted to `1.0` and `0.0` respectively
|
77
|
+
* `float_eu`:
|
78
|
+
- same as `float`, except string values support dot-separators and comma-decimals (e.g., `"1.000,5"` produces an integer with value of one thousand and one half)
|
79
|
+
* `string`:
|
80
|
+
- all values are stringified and encoded with UTF-8
|
81
|
+
* `boolean`:
|
82
|
+
- strings `"true"`, `"t"`, `"yes"`, `"y"`, and `"1"` are converted to boolean `true`
|
83
|
+
- strings `"false"`, `"f"`, `"no"`, `"n"`, and `"0"` are converted to boolean `false`
|
84
|
+
- empty strings are converted to boolean `false`
|
85
|
+
- all other values pass straight through without conversion and log a warning message
|
86
|
+
|
87
|
+
This plugin can convert multiple fields in the same document, see the example below.
|
84
88
|
|
85
89
|
Example:
|
86
90
|
[source,ruby]
|
87
91
|
filter {
|
88
92
|
mutate {
|
89
|
-
convert => {
|
93
|
+
convert => {
|
94
|
+
"fieldname" => "integer"
|
95
|
+
"booleanfield" => "boolean"
|
96
|
+
}
|
90
97
|
}
|
91
98
|
}
|
92
99
|
|
@@ -341,22 +341,29 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
|
|
341
341
|
end
|
342
342
|
|
343
343
|
def convert_float(value)
|
344
|
-
|
344
|
+
return 1.0 if value == true
|
345
|
+
return 0.0 if value == false
|
346
|
+
value = value.delete(",") if value.kind_of?(String)
|
347
|
+
value.to_f
|
345
348
|
end
|
346
349
|
|
347
350
|
def convert_integer_eu(value)
|
348
|
-
|
349
|
-
|
350
|
-
cnv_replace_eu(value).to_i
|
351
|
+
us_value = cnv_replace_eu(value)
|
352
|
+
convert_integer(us_value)
|
351
353
|
end
|
352
354
|
|
353
355
|
def convert_float_eu(value)
|
354
|
-
cnv_replace_eu(value)
|
356
|
+
us_value = cnv_replace_eu(value)
|
357
|
+
convert_float(us_value)
|
355
358
|
end
|
356
359
|
|
360
|
+
# When given a String, returns a new String whose contents have been converted from
|
361
|
+
# EU-style comma-decimals and dot-separators to US-style dot-decimals and comma-separators.
|
362
|
+
#
|
363
|
+
# For all other values, returns value unmodified.
|
357
364
|
def cnv_replace_eu(value)
|
358
365
|
return value if !value.is_a?(String)
|
359
|
-
value.tr("
|
366
|
+
value.tr(",.", ".,")
|
360
367
|
end
|
361
368
|
|
362
369
|
def gsub(event)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-filter-mutate'
|
4
|
-
s.version = '3.3.
|
4
|
+
s.version = '3.3.2'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Performs mutations on fields"
|
7
7
|
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"
|
data/spec/filters/mutate_spec.rb
CHANGED
@@ -415,6 +415,152 @@ describe LogStash::Filters::Mutate do
|
|
415
415
|
end
|
416
416
|
end
|
417
417
|
|
418
|
+
describe "convert to float" do
|
419
|
+
|
420
|
+
config <<-CONFIG
|
421
|
+
filter {
|
422
|
+
mutate {
|
423
|
+
convert => {
|
424
|
+
"field" => "float"
|
425
|
+
}
|
426
|
+
}
|
427
|
+
}
|
428
|
+
CONFIG
|
429
|
+
|
430
|
+
context 'when field is a string with no separator and dot decimal' do
|
431
|
+
sample({'field' => '3141.5926'}) do
|
432
|
+
expect(subject.get('field')).to be_within(0.0001).of(3141.5926)
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
context 'when field is a string with a comma separator and dot decimal' do
|
437
|
+
sample({'field' => '3,141.5926'}) do
|
438
|
+
expect(subject.get('field')).to be_within(0.0001).of(3141.5926)
|
439
|
+
end
|
440
|
+
end
|
441
|
+
|
442
|
+
context 'when field is a string comma separator and no decimal' do
|
443
|
+
sample({'field' => '3,141'}) do
|
444
|
+
expect(subject.get('field')).to be_within(0.0001).of(3141.0)
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
context 'when field is a string no separator and no decimal' do
|
449
|
+
sample({'field' => '3141'}) do
|
450
|
+
expect(subject.get('field')).to be_within(0.0001).of(3141.0)
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
context 'when field is a float' do
|
455
|
+
sample({'field' => 3.1415926}) do
|
456
|
+
expect(subject.get('field')).to be_within(0.000001).of(3.1415926)
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
context 'when field is an integer' do
|
461
|
+
sample({'field' => 3}) do
|
462
|
+
expect(subject.get('field')).to be_within(0.000001).of(3)
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
context 'when field is the true value' do
|
467
|
+
sample('field' => true) do
|
468
|
+
expect(subject.get('field')).to eq(1.0)
|
469
|
+
end
|
470
|
+
end
|
471
|
+
|
472
|
+
context 'when field is the false value' do
|
473
|
+
sample('field' => false) do
|
474
|
+
expect(subject.get('field')).to eq(0.0)
|
475
|
+
end
|
476
|
+
end
|
477
|
+
|
478
|
+
context 'when field is nil' do
|
479
|
+
sample('field' => nil) do
|
480
|
+
expect(subject.get('field')).to be_nil
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
context 'when field is not set' do
|
485
|
+
sample('field' => nil) do
|
486
|
+
expect(subject.get('field')).to be_nil
|
487
|
+
end
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
|
492
|
+
describe "convert to float_eu" do
|
493
|
+
config <<-CONFIG
|
494
|
+
filter {
|
495
|
+
mutate {
|
496
|
+
convert => {
|
497
|
+
"field" => "float_eu"
|
498
|
+
}
|
499
|
+
}
|
500
|
+
}
|
501
|
+
CONFIG
|
502
|
+
|
503
|
+
context 'when field is a string with no separator and comma decimal' do
|
504
|
+
sample({'field' => '3141,5926'}) do
|
505
|
+
expect(subject.get('field')).to be_within(0.0001).of(3141.5926)
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
context 'when field is a string with a dot separator and comma decimal' do
|
510
|
+
sample({'field' => '3.141,5926'}) do
|
511
|
+
expect(subject.get('field')).to be_within(0.0001).of(3141.5926)
|
512
|
+
end
|
513
|
+
end
|
514
|
+
|
515
|
+
context 'when field is a string dot separator and no decimal' do
|
516
|
+
sample({'field' => '3.141'}) do
|
517
|
+
expect(subject.get('field')).to be_within(0.0001).of(3141.0)
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
521
|
+
context 'when field is a string no separator and no decimal' do
|
522
|
+
sample({'field' => '3141'}) do
|
523
|
+
expect(subject.get('field')).to be_within(0.0001).of(3141.0)
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
527
|
+
context 'when field is a float' do
|
528
|
+
sample({'field' => 3.1415926}) do
|
529
|
+
expect(subject.get('field')).to be_within(0.000001).of(3.1415926)
|
530
|
+
end
|
531
|
+
end
|
532
|
+
|
533
|
+
context 'when field is an integer' do
|
534
|
+
sample({'field' => 3}) do
|
535
|
+
expect(subject.get('field')).to be_within(0.000001).of(3)
|
536
|
+
end
|
537
|
+
end
|
538
|
+
|
539
|
+
context 'when field is the true value' do
|
540
|
+
sample('field' => true) do
|
541
|
+
expect(subject.get('field')).to eq(1.0)
|
542
|
+
end
|
543
|
+
end
|
544
|
+
|
545
|
+
context 'when field is the false value' do
|
546
|
+
sample('field' => false) do
|
547
|
+
expect(subject.get('field')).to eq(0.0)
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
551
|
+
context 'when field is nil' do
|
552
|
+
sample('field' => nil) do
|
553
|
+
expect(subject.get('field')).to be_nil
|
554
|
+
end
|
555
|
+
end
|
556
|
+
|
557
|
+
context 'when field is not set' do
|
558
|
+
sample('field' => nil) do
|
559
|
+
expect(subject.get('field')).to be_nil
|
560
|
+
end
|
561
|
+
end
|
562
|
+
end
|
563
|
+
|
418
564
|
describe "gsub on a String" do
|
419
565
|
config '
|
420
566
|
filter {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-mutate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|