test-jq 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES.md +4 -0
- data/CONTRIBUTING.md +11 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +70 -0
- data/LICENSE +202 -0
- data/Makefile +10 -0
- data/README.md +214 -0
- data/Rakefile +25 -0
- data/VERSION +1 -0
- data/example/Dockerfile +19 -0
- data/example/fluent.conf +42 -0
- data/example/statsd.sample +4 -0
- data/fluent-plugin-jq.gemspec +28 -0
- data/lib/fluent/plugin/filter_jq_transformer.rb +41 -0
- data/lib/fluent/plugin/formatter_jq.rb +57 -0
- data/lib/fluent/plugin/jq_mixin.rb +50 -0
- data/lib/fluent/plugin/out_jq.rb +52 -0
- data/lib/fluent/plugin/parser_jq.rb +42 -0
- data/run_ci.sh +5 -0
- data/test/helper.rb +10 -0
- data/test/plugin/test_filter_jq_transformer.rb +74 -0
- data/test/plugin/test_formatter_jq.rb +57 -0
- data/test/plugin/test_out_jq.rb +58 -0
- data/test/plugin/test_parser_jq.rb +48 -0
- metadata +163 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "fluent/test/driver/formatter"
|
3
|
+
require "fluent/plugin/formatter_jq"
|
4
|
+
|
5
|
+
class JqFormatterTest < Test::Unit::TestCase
|
6
|
+
setup do
|
7
|
+
Fluent::Test.setup
|
8
|
+
end
|
9
|
+
|
10
|
+
teardown do
|
11
|
+
@driver.instance.shutdown if @driver
|
12
|
+
end
|
13
|
+
|
14
|
+
test "it should require jq parameter" do
|
15
|
+
assert_raise(Fluent::ConfigError) { create_driver '' }
|
16
|
+
end
|
17
|
+
|
18
|
+
test "it should raise error on invalid jq parameter" do
|
19
|
+
e = assert_raise(Fluent::ConfigError) { create_driver 'jq blah' }
|
20
|
+
assert_match(/compile error/, e.message)
|
21
|
+
end
|
22
|
+
|
23
|
+
test "it should work" do
|
24
|
+
d = create_driver 'jq .log'
|
25
|
+
record = {"log" => "this is a log", "source" => "stdout"}
|
26
|
+
text = d.instance.format("some.tag", event_time, record)
|
27
|
+
assert_equal record["log"], text
|
28
|
+
end
|
29
|
+
|
30
|
+
test "it should ignore error by default" do
|
31
|
+
d = create_driver 'jq .[1]'
|
32
|
+
record = {"log" => "some message"}
|
33
|
+
text = d.instance.format "some.tag", event_time, record
|
34
|
+
assert_equal record.to_json, text
|
35
|
+
end
|
36
|
+
|
37
|
+
test "it can skip on error" do
|
38
|
+
d = create_driver "jq .[1]\non_error skip"
|
39
|
+
record = {"log" => "some message"}
|
40
|
+
text = d.instance.format "some.tag", event_time, record
|
41
|
+
assert_equal '', text
|
42
|
+
end
|
43
|
+
|
44
|
+
test "it can raise error on error" do
|
45
|
+
d = create_driver "jq .[1]\non_error raise_error"
|
46
|
+
record = {"log" => "some message"}
|
47
|
+
assert_raise(RuntimeError) {
|
48
|
+
d.instance.format "some.tag", event_time, record
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def create_driver(conf)
|
55
|
+
@driver = Fluent::Test::Driver::Formatter.new(Fluent::Plugin::JqFormatter).configure(conf).tap { |d| d.instance.start }
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "helper"
|
4
|
+
require "fluent/test/driver/output"
|
5
|
+
require "fluent/plugin/out_jq"
|
6
|
+
|
7
|
+
class JqOutputTest < Test::Unit::TestCase
|
8
|
+
setup do
|
9
|
+
Fluent::Test.setup
|
10
|
+
end
|
11
|
+
|
12
|
+
test "it should require jq" do
|
13
|
+
assert_raise(Fluent::ConfigError) { create_driver '' }
|
14
|
+
end
|
15
|
+
|
16
|
+
test "it should raise error on invalid jq program" do
|
17
|
+
e = assert_raise(Fluent::ConfigError) { create_driver 'jq blah' }
|
18
|
+
assert_match(/compile error/, e.message)
|
19
|
+
end
|
20
|
+
|
21
|
+
test "it should work on tag" do
|
22
|
+
events = create_driver('jq "{tag}"').events
|
23
|
+
assert_equal events.size, 1
|
24
|
+
assert_equal events[0][2]["tag"], "some.tag"
|
25
|
+
end
|
26
|
+
|
27
|
+
test "it should work on time" do
|
28
|
+
events = create_driver('jq "{time: .time | gmtime }"').events
|
29
|
+
assert_equal events.size, 1
|
30
|
+
assert_equal events[0][2]["time"][0..5], [2018, 2, 22, 1, 23, 45]
|
31
|
+
end
|
32
|
+
|
33
|
+
test "it should support array" do
|
34
|
+
events = create_driver('jq ".record | to_entries"').events.map { |evt| evt[2] }
|
35
|
+
assert_equal events.size, 2
|
36
|
+
assert_include events, {"key" => "log", "value" => "this is a log"}
|
37
|
+
assert_include events, {"key" => "source", "value" => "stdout"}
|
38
|
+
end
|
39
|
+
|
40
|
+
test "it should remove specified tag prefix" do
|
41
|
+
events = create_driver(<<~CONF).events
|
42
|
+
jq ".record"
|
43
|
+
remove_tag_prefix some
|
44
|
+
CONF
|
45
|
+
|
46
|
+
assert_equal events.size, 1
|
47
|
+
assert_equal events[0][0], "tag"
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def create_driver(conf)
|
53
|
+
Fluent::Test::Driver::Output.new(Fluent::Plugin::JqOutput).configure(conf).tap { |d|
|
54
|
+
time = event_time("2018-03-22 01:23:45 UTC")
|
55
|
+
d.run { d.feed "some.tag", time, {"log" => "this is a log", "source" => "stdout"} }
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "helper"
|
4
|
+
require "fluent/test/driver/parser"
|
5
|
+
require "fluent/plugin/parser_jq"
|
6
|
+
|
7
|
+
class JqParserTest < Test::Unit::TestCase
|
8
|
+
setup do
|
9
|
+
Fluent::Test.setup
|
10
|
+
end
|
11
|
+
|
12
|
+
teardown do
|
13
|
+
@driver.instance.shutdown if @driver
|
14
|
+
end
|
15
|
+
|
16
|
+
test "it should require jq" do
|
17
|
+
assert_raise(Fluent::ConfigError) { create_driver '' }
|
18
|
+
end
|
19
|
+
|
20
|
+
test "it should raise error on invalid jq program" do
|
21
|
+
e = assert_raise(Fluent::ConfigError) { create_driver 'jq blah' }
|
22
|
+
assert_match(/compile error/, e.message)
|
23
|
+
end
|
24
|
+
|
25
|
+
test "it should work" do
|
26
|
+
d = create_driver 'jq split(",") | reduce .[] as $item ({}; ($item | split(":")) as $pair | .[$pair[0]] = $pair[1])'
|
27
|
+
text = "name:jq,type:parser,author:Gimi"
|
28
|
+
expected_record = {"name" => "jq", "type" => "parser", "author" => "Gimi"}
|
29
|
+
d.instance.parse(text) { |time, record|
|
30
|
+
assert_equal expected_record, record
|
31
|
+
}
|
32
|
+
assert_nil d.instance.log.logs.find { |log| log =~ /\[error\]/ }
|
33
|
+
end
|
34
|
+
|
35
|
+
test "it should skip if it does not return a hash" do
|
36
|
+
d = create_driver 'jq split(",")'
|
37
|
+
text = "name:jq,type:parser,author:Gimi"
|
38
|
+
expected_record = {"name": "jq", "type": "parser", "author": "Gimi"}
|
39
|
+
d.instance.parse(text) { |time, record| assert false }
|
40
|
+
assert d.instance.log.logs.any? { |log| log =~ /\[error\]/ }
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def create_driver(conf)
|
46
|
+
@driver = Fluent::Test::Driver::Parser.new(Fluent::Plugin::JqParser).configure(conf).tap { |d| d.instance.start }
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: test-jq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rock
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '12.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: fluentd
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.14.10
|
76
|
+
- - "<"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '2'
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.14.10
|
86
|
+
- - "<"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: multi_json
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.13'
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '1.13'
|
103
|
+
description: fluent-plungin-jq is a collection of fluentd plugins which uses the jq
|
104
|
+
engine to transform or format fluentd events.
|
105
|
+
email:
|
106
|
+
- rbaek@splunk.com
|
107
|
+
executables: []
|
108
|
+
extensions: []
|
109
|
+
extra_rdoc_files: []
|
110
|
+
files:
|
111
|
+
- CHANGES.md
|
112
|
+
- CONTRIBUTING.md
|
113
|
+
- Gemfile
|
114
|
+
- Gemfile.lock
|
115
|
+
- LICENSE
|
116
|
+
- Makefile
|
117
|
+
- README.md
|
118
|
+
- Rakefile
|
119
|
+
- VERSION
|
120
|
+
- example/Dockerfile
|
121
|
+
- example/fluent.conf
|
122
|
+
- example/statsd.sample
|
123
|
+
- fluent-plugin-jq.gemspec
|
124
|
+
- lib/fluent/plugin/filter_jq_transformer.rb
|
125
|
+
- lib/fluent/plugin/formatter_jq.rb
|
126
|
+
- lib/fluent/plugin/jq_mixin.rb
|
127
|
+
- lib/fluent/plugin/out_jq.rb
|
128
|
+
- lib/fluent/plugin/parser_jq.rb
|
129
|
+
- run_ci.sh
|
130
|
+
- test/helper.rb
|
131
|
+
- test/plugin/test_filter_jq_transformer.rb
|
132
|
+
- test/plugin/test_formatter_jq.rb
|
133
|
+
- test/plugin/test_out_jq.rb
|
134
|
+
- test/plugin/test_parser_jq.rb
|
135
|
+
homepage: https://github.com/rockb1017/fluent-plugin-jq
|
136
|
+
licenses:
|
137
|
+
- Apache-2.0
|
138
|
+
metadata: {}
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
requirements: []
|
154
|
+
rubygems_version: 3.0.6
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Fluentd plugins uses the jq engine.
|
158
|
+
test_files:
|
159
|
+
- test/helper.rb
|
160
|
+
- test/plugin/test_formatter_jq.rb
|
161
|
+
- test/plugin/test_parser_jq.rb
|
162
|
+
- test/plugin/test_filter_jq_transformer.rb
|
163
|
+
- test/plugin/test_out_jq.rb
|