fluent-plugin-lookup 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fluent-plugin-lookup.gemspec +1 -1
- data/lib/fluent/plugin/out_lookup.rb +59 -5
- data/test/plugin/test_out_lookup.rb +95 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ac6a0b2172ab5435936e89fa771c3612039d93c
|
4
|
+
data.tar.gz: f7646ff1776bc57cb6519adc9b29e09f07d042fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7aed8a806f45ba877107089297bcf8770dcc3e4e49f878e5ec2372c40294915d2953516bf3138211e64f74a92d4a8b9caa0c1f68f3feaf3ba0cce7fe204ea3e
|
7
|
+
data.tar.gz: fcebd49bb86c18a85503bd68dd0743b9cc5f3a2c8ddc36d4ff6a79c1868de07af4cdf444b99bbee3a69c2b7801d35c91f8fcccc13f9fff68a712044ba059bfcc
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "fluent-plugin-lookup"
|
3
|
-
spec.version = "0.0.
|
3
|
+
spec.version = "0.0.2"
|
4
4
|
spec.authors = ["Neozaru"]
|
5
5
|
spec.email = ["neozaru@mailoo.org"]
|
6
6
|
spec.description = %q{Fluentd custom plugin to replace fields values using lookup table file}
|
@@ -58,8 +58,18 @@ module Fluent
|
|
58
58
|
end
|
59
59
|
|
60
60
|
@lookup_table = create_lookup_table(table_file)
|
61
|
-
@field = field
|
62
|
-
|
61
|
+
@field = field.split(".")
|
62
|
+
|
63
|
+
if (output_field.nil?)
|
64
|
+
@filter_method = method(:filter_no_output)
|
65
|
+
else
|
66
|
+
@output_field = output_field.split(".")
|
67
|
+
@filter_method = method(:filter_with_output)
|
68
|
+
end
|
69
|
+
|
70
|
+
@assign_method = method(:assign)
|
71
|
+
@assign_self_method = method(:assign_self)
|
72
|
+
@return_method = method(:return)
|
63
73
|
|
64
74
|
end
|
65
75
|
|
@@ -75,12 +85,56 @@ module Fluent
|
|
75
85
|
|
76
86
|
private
|
77
87
|
|
88
|
+
def assign_self(record, key, value)
|
89
|
+
assign(record, key, record[key])
|
90
|
+
end
|
91
|
+
|
92
|
+
def assign(record, key, value)
|
93
|
+
record[key] = process(value) || value
|
94
|
+
end
|
95
|
+
|
96
|
+
def return(record, key, value)
|
97
|
+
return record[key]
|
98
|
+
end
|
99
|
+
|
100
|
+
|
78
101
|
def filter_record(tag, time, record)
|
79
102
|
super(tag, time, record)
|
80
|
-
|
81
|
-
|
103
|
+
@filter_method.call(record)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Same input/output : Get and set (dig once)
|
107
|
+
def filter_no_output(record)
|
108
|
+
dig_cb(record, @field, nil, false, @assign_self_method)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Different input/output : Get, then set (dig twice)
|
112
|
+
def filter_with_output(record)
|
113
|
+
value = dig_cb(record, @field, nil, false, @return_method)
|
114
|
+
if (!value.nil?)
|
115
|
+
dig_cb(record, @output_field, value, true, @assign_method)
|
82
116
|
end
|
83
|
-
|
117
|
+
end
|
118
|
+
|
119
|
+
# Generic function to dig into map.
|
120
|
+
def dig_cb(record, path, value, alter, cb)
|
121
|
+
digged_record = record
|
122
|
+
path.each_with_index {|key, index|
|
123
|
+
# If enabled, creates new path in the record
|
124
|
+
if (!digged_record.has_key?(key))
|
125
|
+
if (!alter)
|
126
|
+
return nil
|
127
|
+
end
|
128
|
+
digged_record[key] = {}
|
129
|
+
end
|
130
|
+
|
131
|
+
if (index == path.length - 1)
|
132
|
+
return cb.call(digged_record, key, value)
|
133
|
+
else
|
134
|
+
digged_record = digged_record[key]
|
135
|
+
end
|
136
|
+
}
|
137
|
+
return nil
|
84
138
|
end
|
85
139
|
|
86
140
|
def process(value)
|
@@ -33,8 +33,7 @@ class LookupOutputTest < Test::Unit::TestCase
|
|
33
33
|
])
|
34
34
|
|
35
35
|
assert_equal 'lookup.', d.instance.add_tag_prefix
|
36
|
-
assert_equal 'key1', d.instance.field
|
37
|
-
assert_equal 'key2', d.instance.output_field
|
36
|
+
assert_equal ['key1'], d.instance.field
|
38
37
|
assert_equal true, d.instance.strict
|
39
38
|
assert_equal @correct_file, d.instance.table_file
|
40
39
|
|
@@ -48,8 +47,7 @@ class LookupOutputTest < Test::Unit::TestCase
|
|
48
47
|
])
|
49
48
|
|
50
49
|
assert_equal 'lookup.', d.instance.add_tag_prefix
|
51
|
-
assert_equal 'key1', d.instance.field
|
52
|
-
assert_equal 'key2', d.instance.output_field
|
50
|
+
assert_equal ['key1'], d.instance.field
|
53
51
|
assert_equal false, d.instance.strict
|
54
52
|
assert_equal @correct_file, d.instance.table_file
|
55
53
|
|
@@ -63,8 +61,7 @@ class LookupOutputTest < Test::Unit::TestCase
|
|
63
61
|
])
|
64
62
|
|
65
63
|
assert_equal 'lookup.', d.instance.add_tag_prefix
|
66
|
-
assert_equal 'key1', d.instance.field
|
67
|
-
assert_equal 'key1', d.instance.output_field
|
64
|
+
assert_equal ['key1'], d.instance.field
|
68
65
|
assert_equal true, d.instance.strict
|
69
66
|
assert_equal @correct_file, d.instance.table_file
|
70
67
|
|
@@ -79,8 +76,7 @@ class LookupOutputTest < Test::Unit::TestCase
|
|
79
76
|
])
|
80
77
|
|
81
78
|
assert_equal 'lookup.', d.instance.add_tag_prefix
|
82
|
-
assert_equal 'key1', d.instance.field
|
83
|
-
assert_equal 'key2', d.instance.output_field
|
79
|
+
assert_equal ['key1'], d.instance.field
|
84
80
|
assert_equal false, d.instance.strict
|
85
81
|
assert_equal @duplicates_file, d.instance.table_file
|
86
82
|
|
@@ -95,8 +91,7 @@ class LookupOutputTest < Test::Unit::TestCase
|
|
95
91
|
])
|
96
92
|
|
97
93
|
assert_equal 'lookup.', d.instance.add_tag_prefix
|
98
|
-
assert_equal 'key1', d.instance.field
|
99
|
-
assert_equal 'key2', d.instance.output_field
|
94
|
+
assert_equal ['key1'], d.instance.field
|
100
95
|
assert_equal false, d.instance.strict
|
101
96
|
assert_equal @empty_file, d.instance.table_file
|
102
97
|
|
@@ -352,6 +347,96 @@ class LookupOutputTest < Test::Unit::TestCase
|
|
352
347
|
assert_equal 'cage', emits[0][2]['key1']
|
353
348
|
end
|
354
349
|
|
350
|
+
|
351
|
+
|
352
|
+
def test_emit_nested_without_output_field
|
353
|
+
d = create_driver(%[
|
354
|
+
add_tag_prefix lookup.
|
355
|
+
table_file #{@correct_file}
|
356
|
+
field nested.key1
|
357
|
+
])
|
358
|
+
|
359
|
+
record = {
|
360
|
+
'nested' => {
|
361
|
+
'key1' => "nicolas",
|
362
|
+
},
|
363
|
+
'foo' => "bar"
|
364
|
+
}
|
365
|
+
|
366
|
+
d.run { d.emit(record) }
|
367
|
+
emits = d.emits
|
368
|
+
|
369
|
+
assert_equal 1, emits.count
|
370
|
+
assert_equal 'lookup.test', emits[0][0]
|
371
|
+
assert_equal 'cage', emits[0][2]['nested']['key1']
|
372
|
+
end
|
373
|
+
|
374
|
+
|
375
|
+
def test_emit_nested_with_non_existing_output_field
|
376
|
+
d = create_driver(%[
|
377
|
+
add_tag_prefix lookup.
|
378
|
+
table_file #{@correct_file}
|
379
|
+
field nested.key1
|
380
|
+
output_field new.foo
|
381
|
+
])
|
382
|
+
|
383
|
+
record = {
|
384
|
+
'nested' => {
|
385
|
+
'key1' => "nicolas",
|
386
|
+
},
|
387
|
+
'foo' => "bar"
|
388
|
+
}
|
389
|
+
|
390
|
+
d.run { d.emit(record) }
|
391
|
+
emits = d.emits
|
392
|
+
|
393
|
+
assert_equal 1, emits.count
|
394
|
+
assert_equal 'lookup.test', emits[0][0]
|
395
|
+
assert_equal 'cage', emits[0][2]['new']['foo']
|
396
|
+
end
|
397
|
+
|
398
|
+
# Checks that the record is not modified if the input_field is not found
|
399
|
+
def test_emit_nested_with_non_existing_input_field
|
400
|
+
d = create_driver(%[
|
401
|
+
add_tag_prefix lookup.
|
402
|
+
table_file #{@correct_file}
|
403
|
+
field nested.key1
|
404
|
+
output_field new.foo
|
405
|
+
])
|
406
|
+
|
407
|
+
record = {
|
408
|
+
'foo' => "bar"
|
409
|
+
}
|
410
|
+
|
411
|
+
d.run { d.emit(record) }
|
412
|
+
emits = d.emits
|
413
|
+
|
414
|
+
assert_equal 1, emits.count
|
415
|
+
assert_equal 'lookup.test', emits[0][0]
|
416
|
+
assert_equal nil, emits[0][2]['nested']
|
417
|
+
assert_equal nil, emits[0][2]['new']
|
418
|
+
end
|
419
|
+
|
420
|
+
# Checks that the record is not modified if the input_field is not found
|
421
|
+
def test_emit_nested_with_non_existing_input_field_no_output
|
422
|
+
d = create_driver(%[
|
423
|
+
add_tag_prefix lookup.
|
424
|
+
table_file #{@correct_file}
|
425
|
+
field nested.key1
|
426
|
+
])
|
427
|
+
|
428
|
+
record = {
|
429
|
+
'foo' => "bar"
|
430
|
+
}
|
431
|
+
|
432
|
+
d.run { d.emit(record) }
|
433
|
+
emits = d.emits
|
434
|
+
|
435
|
+
assert_equal 1, emits.count
|
436
|
+
assert_equal 'lookup.test', emits[0][0]
|
437
|
+
assert_equal nil, emits[0][2]['nested']
|
438
|
+
end
|
439
|
+
|
355
440
|
def test_emit_without_output_field_no_correspondance
|
356
441
|
d = create_driver(%[
|
357
442
|
add_tag_prefix lookup.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-lookup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neozaru
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|