logstash-core 5.6.16-java → 6.0.0.alpha1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gemspec_jars.rb +4 -7
- data/lib/logstash-core/logstash-core.jar +0 -0
- data/lib/logstash-core/version.rb +4 -8
- data/lib/logstash-core_jars.rb +12 -26
- data/lib/logstash/agent.rb +261 -246
- data/lib/logstash/api/commands/default_metadata.rb +1 -1
- data/lib/logstash/api/commands/hot_threads_reporter.rb +5 -11
- data/lib/logstash/api/commands/node.rb +3 -2
- data/lib/logstash/api/commands/stats.rb +3 -2
- data/lib/logstash/bootstrap_check/bad_java.rb +16 -0
- data/lib/logstash/bootstrap_check/bad_ruby.rb +12 -0
- data/lib/logstash/bootstrap_check/default_config.rb +17 -0
- data/lib/logstash/compiler.rb +38 -0
- data/lib/logstash/compiler/lscl.rb +566 -0
- data/lib/logstash/compiler/lscl/lscl_grammar.rb +3503 -0
- data/lib/logstash/compiler/treetop_monkeypatches.rb +92 -0
- data/lib/logstash/config/config_ast.rb +4 -82
- data/lib/logstash/config/mixin.rb +73 -41
- data/lib/logstash/config/pipeline_config.rb +48 -0
- data/lib/logstash/config/source/base.rb +16 -0
- data/lib/logstash/config/source/local.rb +215 -0
- data/lib/logstash/config/source_loader.rb +125 -0
- data/lib/logstash/converge_result.rb +103 -0
- data/lib/logstash/environment.rb +6 -19
- data/lib/logstash/errors.rb +2 -0
- data/lib/logstash/execution_context.rb +4 -7
- data/lib/logstash/filter_delegator.rb +6 -9
- data/lib/logstash/inputs/base.rb +0 -2
- data/lib/logstash/instrument/collector.rb +5 -7
- data/lib/logstash/instrument/metric_store.rb +12 -12
- data/lib/logstash/instrument/metric_type/mean.rb +0 -5
- data/lib/logstash/instrument/namespaced_metric.rb +0 -4
- data/lib/logstash/instrument/namespaced_null_metric.rb +0 -4
- data/lib/logstash/instrument/null_metric.rb +0 -10
- data/lib/logstash/instrument/periodic_poller/cgroup.rb +85 -168
- data/lib/logstash/instrument/periodic_poller/jvm.rb +5 -5
- data/lib/logstash/instrument/periodic_poller/pq.rb +3 -7
- data/lib/logstash/instrument/periodic_pollers.rb +1 -3
- data/lib/logstash/instrument/wrapped_write_client.rb +24 -33
- data/lib/logstash/logging/logger.rb +15 -47
- data/lib/logstash/namespace.rb +0 -1
- data/lib/logstash/output_delegator.rb +5 -7
- data/lib/logstash/outputs/base.rb +0 -2
- data/lib/logstash/pipeline.rb +159 -87
- data/lib/logstash/pipeline_action.rb +13 -0
- data/lib/logstash/pipeline_action/base.rb +29 -0
- data/lib/logstash/pipeline_action/create.rb +47 -0
- data/lib/logstash/pipeline_action/reload.rb +48 -0
- data/lib/logstash/pipeline_action/stop.rb +23 -0
- data/lib/logstash/plugin.rb +0 -1
- data/lib/logstash/plugins/hooks_registry.rb +6 -0
- data/lib/logstash/plugins/registry.rb +0 -1
- data/lib/logstash/program.rb +14 -0
- data/lib/logstash/queue_factory.rb +5 -1
- data/lib/logstash/runner.rb +58 -80
- data/lib/logstash/settings.rb +3 -27
- data/lib/logstash/state_resolver.rb +41 -0
- data/lib/logstash/util/java_version.rb +6 -0
- data/lib/logstash/util/safe_uri.rb +12 -148
- data/lib/logstash/util/thread_dump.rb +4 -7
- data/lib/logstash/util/wrapped_acked_queue.rb +36 -39
- data/lib/logstash/util/wrapped_synchronous_queue.rb +29 -39
- data/lib/logstash/version.rb +10 -8
- data/locales/en.yml +3 -54
- data/logstash-core.gemspec +8 -35
- data/spec/{logstash/api/modules → api/lib/api}/logging_spec.rb +10 -1
- data/spec/{logstash/api/modules → api/lib/api}/node_plugins_spec.rb +2 -1
- data/spec/{logstash/api/modules → api/lib/api}/node_spec.rb +3 -3
- data/spec/{logstash/api/modules → api/lib/api}/node_stats_spec.rb +3 -7
- data/spec/{logstash/api/modules → api/lib/api}/plugins_spec.rb +3 -4
- data/spec/{logstash/api/modules → api/lib/api}/root_spec.rb +2 -2
- data/spec/api/lib/api/support/resource_dsl_methods.rb +87 -0
- data/spec/{logstash/api/commands/stats_spec.rb → api/lib/commands/stats.rb} +2 -7
- data/spec/{logstash/api → api/lib}/errors_spec.rb +1 -1
- data/spec/{logstash/api → api/lib}/rack_app_spec.rb +0 -0
- data/spec/api/spec_helper.rb +106 -0
- data/spec/logstash/agent/converge_spec.rb +286 -0
- data/spec/logstash/agent/metrics_spec.rb +244 -0
- data/spec/logstash/agent_spec.rb +213 -225
- data/spec/logstash/compiler/compiler_spec.rb +584 -0
- data/spec/logstash/config/config_ast_spec.rb +8 -47
- data/spec/logstash/config/mixin_spec.rb +2 -42
- data/spec/logstash/config/pipeline_config_spec.rb +75 -0
- data/spec/logstash/config/source/local_spec.rb +395 -0
- data/spec/logstash/config/source_loader_spec.rb +122 -0
- data/spec/logstash/converge_result_spec.rb +179 -0
- data/spec/logstash/event_spec.rb +0 -66
- data/spec/logstash/execution_context_spec.rb +8 -12
- data/spec/logstash/filter_delegator_spec.rb +12 -24
- data/spec/logstash/inputs/base_spec.rb +7 -5
- data/spec/logstash/instrument/periodic_poller/cgroup_spec.rb +92 -225
- data/spec/logstash/instrument/periodic_poller/jvm_spec.rb +1 -1
- data/spec/logstash/instrument/periodic_poller/os_spec.rb +32 -29
- data/spec/logstash/instrument/wrapped_write_client_spec.rb +33 -33
- data/spec/logstash/legacy_ruby_event_spec.rb +13 -4
- data/spec/logstash/output_delegator_spec.rb +11 -20
- data/spec/logstash/outputs/base_spec.rb +7 -5
- data/spec/logstash/pipeline_action/create_spec.rb +83 -0
- data/spec/logstash/pipeline_action/reload_spec.rb +83 -0
- data/spec/logstash/pipeline_action/stop_spec.rb +37 -0
- data/spec/logstash/pipeline_pq_file_spec.rb +1 -1
- data/spec/logstash/pipeline_spec.rb +81 -137
- data/spec/logstash/plugin_spec.rb +2 -1
- data/spec/logstash/plugins/hooks_registry_spec.rb +6 -0
- data/spec/logstash/queue_factory_spec.rb +13 -1
- data/spec/logstash/runner_spec.rb +29 -140
- data/spec/logstash/settings/writable_directory_spec.rb +10 -13
- data/spec/logstash/settings_spec.rb +0 -91
- data/spec/logstash/state_resolver_spec.rb +156 -0
- data/spec/logstash/timestamp_spec.rb +2 -6
- data/spec/logstash/util/java_version_spec.rb +22 -0
- data/spec/logstash/util/safe_uri_spec.rb +0 -56
- data/spec/logstash/util/wrapped_synchronous_queue_spec.rb +22 -0
- data/spec/support/helpers.rb +9 -11
- data/spec/support/matchers.rb +96 -6
- data/spec/support/mocks_classes.rb +80 -0
- data/spec/support/shared_contexts.rb +2 -27
- metadata +100 -149
- data/lib/logstash/config/loader.rb +0 -107
- data/lib/logstash/config/modules_common.rb +0 -103
- data/lib/logstash/config/source/modules.rb +0 -55
- data/lib/logstash/config/string_escape.rb +0 -27
- data/lib/logstash/dependency_report.rb +0 -131
- data/lib/logstash/dependency_report_runner.rb +0 -17
- data/lib/logstash/elasticsearch_client.rb +0 -142
- data/lib/logstash/instrument/global_metrics.rb +0 -13
- data/lib/logstash/instrument/periodic_poller/dlq.rb +0 -24
- data/lib/logstash/modules/cli_parser.rb +0 -74
- data/lib/logstash/modules/elasticsearch_config.rb +0 -22
- data/lib/logstash/modules/elasticsearch_importer.rb +0 -37
- data/lib/logstash/modules/elasticsearch_resource.rb +0 -10
- data/lib/logstash/modules/file_reader.rb +0 -36
- data/lib/logstash/modules/kibana_base.rb +0 -24
- data/lib/logstash/modules/kibana_client.rb +0 -124
- data/lib/logstash/modules/kibana_config.rb +0 -105
- data/lib/logstash/modules/kibana_dashboards.rb +0 -36
- data/lib/logstash/modules/kibana_importer.rb +0 -17
- data/lib/logstash/modules/kibana_resource.rb +0 -10
- data/lib/logstash/modules/kibana_settings.rb +0 -40
- data/lib/logstash/modules/logstash_config.rb +0 -120
- data/lib/logstash/modules/resource_base.rb +0 -38
- data/lib/logstash/modules/scaffold.rb +0 -52
- data/lib/logstash/modules/settings_merger.rb +0 -23
- data/lib/logstash/modules/util.rb +0 -17
- data/lib/logstash/util/dead_letter_queue_manager.rb +0 -61
- data/lib/logstash/util/environment_variables.rb +0 -43
- data/spec/logstash/config/loader_spec.rb +0 -38
- data/spec/logstash/config/string_escape_spec.rb +0 -24
- data/spec/logstash/instrument/periodic_poller/dlq_spec.rb +0 -17
- data/spec/logstash/modules/logstash_config_spec.rb +0 -56
- data/spec/logstash/modules/scaffold_spec.rb +0 -234
- data/spec/logstash/pipeline_dlq_commit_spec.rb +0 -109
- data/spec/logstash/settings/splittable_string_array_spec.rb +0 -51
- data/spec/logstash/util/wrapped_acked_queue_spec.rb +0 -49
- data/versions-gem-copy.yml +0 -12
@@ -0,0 +1,584 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "logstash/compiler"
|
3
|
+
require "support/helpers"
|
4
|
+
java_import Java::OrgLogstashConfigIr::DSL
|
5
|
+
|
6
|
+
describe LogStash::Compiler do
|
7
|
+
def j
|
8
|
+
Java::OrgLogstashConfigIr::DSL
|
9
|
+
end
|
10
|
+
|
11
|
+
# Static import of these useful enums
|
12
|
+
INPUT = Java::OrgLogstashConfigIr::PluginDefinition::Type::INPUT
|
13
|
+
FILTER = Java::OrgLogstashConfigIr::PluginDefinition::Type::FILTER
|
14
|
+
OUTPUT = Java::OrgLogstashConfigIr::PluginDefinition::Type::OUTPUT
|
15
|
+
CODEC = Java::OrgLogstashConfigIr::PluginDefinition::Type::OUTPUT
|
16
|
+
|
17
|
+
describe "compiling to Pipeline" do
|
18
|
+
subject(:source_file) { "fake_sourcefile" }
|
19
|
+
subject(:compiled) { described_class.compile_pipeline(source, source_file) }
|
20
|
+
|
21
|
+
describe "complex configs" do
|
22
|
+
shared_examples_for "compilable LSCL files" do |path|
|
23
|
+
describe "parsing #{path}" do
|
24
|
+
let(:source) { File.read(path) }
|
25
|
+
|
26
|
+
it "should compile" do
|
27
|
+
expect(compiled).to be_java_kind_of(Java::OrgLogstashConfigIr::Pipeline)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should have a hash" do
|
31
|
+
expect(compiled.uniqueHash)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Dir.glob(File.join(SUPPORT_DIR, "lscl_configs", "*.conf")).each do |path|
|
37
|
+
it_should_behave_like "compilable LSCL files", path
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "compiling imperative" do
|
43
|
+
let(:source_file) { "fake_sourcefile" }
|
44
|
+
subject(:compiled) { described_class.compile_imperative(source, source_file) }
|
45
|
+
|
46
|
+
describe "an empty file" do
|
47
|
+
let(:source) { "input {} output {}" }
|
48
|
+
|
49
|
+
it "should have an empty input block" do
|
50
|
+
expect(compiled[:input]).to ir_eql(j.noop)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should have an empty filter block" do
|
54
|
+
expect(compiled[:filter]).to ir_eql(j.noop)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should have an empty output block" do
|
58
|
+
expect(compiled[:output]).to ir_eql(j.noop)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "SourceMetadata" do
|
63
|
+
let(:source) { "input { generator {} } output { }" }
|
64
|
+
|
65
|
+
it "should attach correct source text for components" do
|
66
|
+
expect(compiled[:input].get_meta.getText).to eql("generator {}")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "plugins" do
|
71
|
+
subject(:c_plugin) { compiled[:input] }
|
72
|
+
let(:source) { "input { #{plugin_source} } " }
|
73
|
+
|
74
|
+
describe "a simple plugin" do
|
75
|
+
let(:plugin_source) { "generator {}" }
|
76
|
+
|
77
|
+
it "should contain the plugin" do
|
78
|
+
expect(c_plugin).to ir_eql(j.iPlugin(INPUT, "generator"))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "a plugin with mixed parameter types" do
|
83
|
+
let(:plugin_source) { "generator { aarg => [1] hasharg => {foo => bar} iarg => 123 farg => 123.123 sarg => 'hello'}" }
|
84
|
+
let(:expected_plugin_args) do
|
85
|
+
{
|
86
|
+
"aarg" => [1],
|
87
|
+
"hasharg" => {"foo" => "bar"},
|
88
|
+
"iarg" => 123,
|
89
|
+
"farg" => 123.123,
|
90
|
+
"sarg" => 'hello'
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should contain the plugin" do
|
95
|
+
expect(c_plugin).to ir_eql(j.iPlugin(INPUT, "generator", expected_plugin_args))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "inputs" do
|
101
|
+
subject(:input) { compiled[:input] }
|
102
|
+
|
103
|
+
describe "a single input" do
|
104
|
+
let(:source) { "input { generator {} }" }
|
105
|
+
|
106
|
+
it "should contain the single input" do
|
107
|
+
expect(input).to ir_eql(j.iPlugin(INPUT, "generator"))
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "two inputs" do
|
112
|
+
let(:source) { "input { generator { count => 1 } generator { count => 2 } } output { }" }
|
113
|
+
|
114
|
+
it "should contain both inputs" do
|
115
|
+
expect(input).to ir_eql(j.iComposeParallel(
|
116
|
+
j.iPlugin(INPUT, "generator", {"count" => 1}),
|
117
|
+
j.iPlugin(INPUT, "generator", {"count" => 2})
|
118
|
+
))
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
shared_examples_for "complex grammar" do |section|
|
124
|
+
let(:section_name_enum) {
|
125
|
+
case section
|
126
|
+
when :input
|
127
|
+
INPUT
|
128
|
+
when :filter
|
129
|
+
FILTER
|
130
|
+
when :output
|
131
|
+
OUTPUT
|
132
|
+
else
|
133
|
+
raise "Unknown section"
|
134
|
+
end
|
135
|
+
}
|
136
|
+
|
137
|
+
let(:section) { section }
|
138
|
+
let (:compiled_section) { compiled[section] }
|
139
|
+
|
140
|
+
def splugin(*args)
|
141
|
+
j.iPlugin(section_name_enum, *args)
|
142
|
+
end
|
143
|
+
|
144
|
+
def compose(*statements)
|
145
|
+
if section == :filter
|
146
|
+
j.iComposeSequence(*statements)
|
147
|
+
else
|
148
|
+
j.iComposeParallel(*statements)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "multiple section declarations" do
|
153
|
+
let(:source) do
|
154
|
+
<<-EOS
|
155
|
+
#{section} {
|
156
|
+
aplugin { count => 1 }
|
157
|
+
}
|
158
|
+
|
159
|
+
#{section} {
|
160
|
+
aplugin { count => 2 }
|
161
|
+
}
|
162
|
+
EOS
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
it "should contain both section declarations, in order" do
|
167
|
+
expect(compiled_section).to ir_eql(compose(
|
168
|
+
splugin("aplugin", {"count" => 1}),
|
169
|
+
splugin("aplugin", {"count" => 2})
|
170
|
+
))
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe "two plugins" do
|
175
|
+
let(:source) do
|
176
|
+
# We care about line/column for this test, hence the indentation
|
177
|
+
<<-EOS
|
178
|
+
#{section} {
|
179
|
+
aplugin { count => 1 }
|
180
|
+
aplugin { count => 2 }
|
181
|
+
}
|
182
|
+
EOS
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should contain both" do
|
186
|
+
expect(compiled_section).to ir_eql(compose(
|
187
|
+
splugin("aplugin", {"count" => 1}),
|
188
|
+
splugin("aplugin", {"count" => 2})
|
189
|
+
))
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should attach source_with_metadata with correct info to the statements" do
|
193
|
+
meta = compiled_section.statements.first.meta
|
194
|
+
expect(meta.text).to eql("aplugin { count => 1 }")
|
195
|
+
expect(meta.line).to eql(2)
|
196
|
+
expect(meta.column).to eql(13)
|
197
|
+
expect(meta.id).to eql(source_file)
|
198
|
+
expect(compiled_section.statements.first.meta)
|
199
|
+
expect(compiled_section)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
describe "if conditions" do
|
204
|
+
describe "conditional expressions" do
|
205
|
+
let(:source) { "#{section} { if (#{expression}) { aplugin {} } }" }
|
206
|
+
let(:c_expression) { compiled_section.getBooleanExpression }
|
207
|
+
|
208
|
+
describe "logical expressions" do
|
209
|
+
describe "simple and" do
|
210
|
+
let(:expression) { "2 > 1 and 1 < 2" }
|
211
|
+
|
212
|
+
it "should compile correctly" do
|
213
|
+
expect(c_expression).to ir_eql(
|
214
|
+
j.eAnd(
|
215
|
+
j.eGt(j.eValue(2), j.eValue(1)),
|
216
|
+
j.eLt(j.eValue(1), j.eValue(2))
|
217
|
+
))
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "'in' array" do
|
222
|
+
let(:expression) { "'foo' in ['foo', 'bar']" }
|
223
|
+
|
224
|
+
it "should compile correctly" do
|
225
|
+
expect(c_expression).to ir_eql(
|
226
|
+
j.eIn(
|
227
|
+
j.eValue('foo'),
|
228
|
+
j.eValue(['foo', 'bar'])
|
229
|
+
))
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe "'not in' array" do
|
234
|
+
let(:expression) { "'foo' not in ['foo', 'bar']" }
|
235
|
+
|
236
|
+
it "should compile correctly" do
|
237
|
+
expect(c_expression).to ir_eql(
|
238
|
+
j.eNot(
|
239
|
+
j.eIn(
|
240
|
+
j.eValue('foo'),
|
241
|
+
j.eValue(['foo', 'bar'])
|
242
|
+
)))
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe "'not'" do
|
247
|
+
let(:expression) { "!(1 > 2)" }
|
248
|
+
|
249
|
+
it "should compile correctly" do
|
250
|
+
expect(c_expression).to ir_eql(j.eNot(j.eGt(j.eValue(1), j.eValue(2))))
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe "and or precedence" do
|
255
|
+
let(:expression) { "2 > 1 and 1 < 2 or 3 < 2" }
|
256
|
+
|
257
|
+
it "should compile correctly" do
|
258
|
+
expect(c_expression).to ir_eql(
|
259
|
+
j.eOr(
|
260
|
+
j.eAnd(
|
261
|
+
j.eGt(j.eValue(2), j.eValue(1)),
|
262
|
+
j.eLt(j.eValue(1), j.eValue(2))
|
263
|
+
),
|
264
|
+
j.eLt(j.eValue(3), j.eValue(2))
|
265
|
+
)
|
266
|
+
)
|
267
|
+
end
|
268
|
+
|
269
|
+
describe "multiple or" do
|
270
|
+
let(:expression) { "2 > 1 or 1 < 2 or 3 < 2" }
|
271
|
+
|
272
|
+
it "should compile correctly" do
|
273
|
+
expect(c_expression).to ir_eql(
|
274
|
+
j.eOr(
|
275
|
+
j.eGt(j.eValue(2), j.eValue(1)),
|
276
|
+
j.eOr(
|
277
|
+
j.eLt(j.eValue(1), j.eValue(2)),
|
278
|
+
j.eLt(j.eValue(3), j.eValue(2))
|
279
|
+
)
|
280
|
+
)
|
281
|
+
)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
describe "a complex expression" do
|
286
|
+
let(:expression) { "1 > 2 and 3 > 4 or 6 > 7 and 8 > 9" }
|
287
|
+
false and false or true and true
|
288
|
+
|
289
|
+
it "should compile correctly" do
|
290
|
+
expect(c_expression).to ir_eql(
|
291
|
+
j.eOr(
|
292
|
+
j.eAnd(
|
293
|
+
j.eGt(j.eValue(1), j.eValue(2)),
|
294
|
+
j.eGt(j.eValue(3), j.eValue(4))
|
295
|
+
),
|
296
|
+
j.eAnd(
|
297
|
+
j.eGt(j.eValue(6), j.eValue(7)),
|
298
|
+
j.eGt(j.eValue(8), j.eValue(9))
|
299
|
+
)
|
300
|
+
)
|
301
|
+
)
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
describe "a complex nested expression" do
|
306
|
+
let(:expression) { "1 > 2 and (1 > 2 and 3 > 4 or 6 > 7 and 8 > 9) or 6 > 7 and 8 > 9" }
|
307
|
+
false and false or true and true
|
308
|
+
|
309
|
+
it "should compile correctly" do
|
310
|
+
expect(c_expression).to ir_eql(
|
311
|
+
j.eOr(
|
312
|
+
j.eAnd(
|
313
|
+
j.eGt(j.eValue(1), j.eValue(2)),
|
314
|
+
j.eOr(
|
315
|
+
j.eAnd(
|
316
|
+
j.eGt(j.eValue(1), j.eValue(2)),
|
317
|
+
j.eGt(j.eValue(3), j.eValue(4))
|
318
|
+
),
|
319
|
+
j.eAnd(
|
320
|
+
j.eGt(j.eValue(6), j.eValue(7)),
|
321
|
+
j.eGt(j.eValue(8), j.eValue(9))
|
322
|
+
)
|
323
|
+
)
|
324
|
+
),
|
325
|
+
j.eAnd(
|
326
|
+
j.eGt(j.eValue(6), j.eValue(7)),
|
327
|
+
j.eGt(j.eValue(8), j.eValue(9))
|
328
|
+
)
|
329
|
+
)
|
330
|
+
)
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
describe "comparisons" do
|
337
|
+
describe "field not null" do
|
338
|
+
let(:expression) { "[foo]"}
|
339
|
+
|
340
|
+
it "should compile correctly" do
|
341
|
+
expect(c_expression).to ir_eql(j.eTruthy(j.eEventValue("[foo]")))
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
describe "'=='" do
|
346
|
+
let(:expression) { "[foo] == 5"}
|
347
|
+
|
348
|
+
it "should compile correctly" do
|
349
|
+
expect(c_expression).to ir_eql(j.eEq(j.eEventValue("[foo]"), j.eValue(5.to_java)))
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
describe "'!='" do
|
354
|
+
let(:expression) { "[foo] != 5"}
|
355
|
+
|
356
|
+
it "should compile correctly" do
|
357
|
+
expect(c_expression).to ir_eql(j.eNeq(j.eEventValue("[foo]"), j.eValue(5.to_java)))
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
describe "'>'" do
|
362
|
+
let(:expression) { "[foo] > 5"}
|
363
|
+
|
364
|
+
it "should compile correctly" do
|
365
|
+
expect(c_expression).to ir_eql(j.eGt(j.eEventValue("[foo]"), j.eValue(5.to_java)))
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
describe "'<'" do
|
370
|
+
let(:expression) { "[foo] < 5"}
|
371
|
+
|
372
|
+
it "should compile correctly" do
|
373
|
+
expect(c_expression).to ir_eql(j.eLt(j.eEventValue("[foo]"), j.eValue(5.to_java)))
|
374
|
+
end
|
375
|
+
end
|
376
|
+
|
377
|
+
describe "'>='" do
|
378
|
+
let(:expression) { "[foo] >= 5"}
|
379
|
+
|
380
|
+
it "should compile correctly" do
|
381
|
+
expect(c_expression).to ir_eql(j.eGte(j.eEventValue("[foo]"), j.eValue(5.to_java)))
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
describe "'<='" do
|
386
|
+
let(:expression) { "[foo] <= 5"}
|
387
|
+
|
388
|
+
it "should compile correctly" do
|
389
|
+
expect(c_expression).to ir_eql(j.eLte(j.eEventValue("[foo]"), j.eValue(5.to_java)))
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
describe "'=~'" do
|
394
|
+
let(:expression) { "[foo] =~ /^abc$/"}
|
395
|
+
|
396
|
+
it "should compile correctly" do
|
397
|
+
expect(c_expression).to ir_eql(j.eRegexEq(j.eEventValue("[foo]"), j.eRegex('^abc$')))
|
398
|
+
end
|
399
|
+
|
400
|
+
# Believe it or not, "\.\." is a valid regexp!
|
401
|
+
describe "when given a quoted regexp" do
|
402
|
+
let(:expression) { '[foo] =~ "\\.\\."' }
|
403
|
+
|
404
|
+
it "should compile correctly" do
|
405
|
+
expect(c_expression).to ir_eql(j.eRegexEq(j.eEventValue("[foo]"), j.eRegex('\\.\\.')))
|
406
|
+
end
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
describe "'!~'" do
|
411
|
+
let(:expression) { "[foo] !~ /^abc$/"}
|
412
|
+
|
413
|
+
it "should compile correctly" do
|
414
|
+
expect(c_expression).to ir_eql(j.eRegexNeq(j.eEventValue("[foo]"), j.eRegex('^abc$')))
|
415
|
+
end
|
416
|
+
end
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
describe "only true branch" do
|
421
|
+
let (:source) { "#{section} { if [foo] == [bar] { grok {} } }" }
|
422
|
+
|
423
|
+
it "should compile correctly" do
|
424
|
+
expect(compiled_section).to ir_eql(j.iIf(
|
425
|
+
j.eEq(j.eEventValue("[foo]"), j.eEventValue("[bar]")),
|
426
|
+
splugin("grok")
|
427
|
+
)
|
428
|
+
)
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
describe "only false branch" do
|
433
|
+
let (:source) { "#{section} { if [foo] == [bar] { } else { fplugin {} } }" }
|
434
|
+
|
435
|
+
it "should compile correctly" do
|
436
|
+
expect(compiled_section).to ir_eql(j.iIf(
|
437
|
+
j.eEq(j.eEventValue("[foo]"), j.eEventValue("[bar]")),
|
438
|
+
j.noop,
|
439
|
+
splugin("fplugin"),
|
440
|
+
)
|
441
|
+
)
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
describe "empty if statement" do
|
446
|
+
let (:source) { "#{section} { if [foo] == [bar] { } }" }
|
447
|
+
|
448
|
+
it "should compile correctly" do
|
449
|
+
expect(compiled_section).to ir_eql(j.iIf(
|
450
|
+
j.eEq(j.eEventValue("[foo]"), j.eEventValue("[bar]")),
|
451
|
+
j.noop,
|
452
|
+
j.noop
|
453
|
+
)
|
454
|
+
)
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
describe "if else" do
|
459
|
+
let (:source) { "#{section} { if [foo] == [bar] { tplugin {} } else { fplugin {} } }" }
|
460
|
+
|
461
|
+
it "should compile correctly" do
|
462
|
+
expect(compiled_section).to ir_eql(j.iIf(
|
463
|
+
j.eEq(j.eEventValue("[foo]"), j.eEventValue("[bar]")),
|
464
|
+
splugin("tplugin"),
|
465
|
+
splugin("fplugin")
|
466
|
+
)
|
467
|
+
)
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
471
|
+
describe "if elsif else" do
|
472
|
+
let (:source) { "#{section} { if [foo] == [bar] { tplugin {} } else if [bar] == [baz] { eifplugin {} } else { fplugin {} } }" }
|
473
|
+
|
474
|
+
it "should compile correctly" do
|
475
|
+
expect(compiled_section).to ir_eql(j.iIf(
|
476
|
+
j.eEq(j.eEventValue("[foo]"), j.eEventValue("[bar]")),
|
477
|
+
splugin("tplugin"),
|
478
|
+
j.iIf(
|
479
|
+
j.eEq(j.eEventValue("[bar]"), j.eEventValue("[baz]")),
|
480
|
+
splugin("eifplugin"),
|
481
|
+
splugin("fplugin")
|
482
|
+
)
|
483
|
+
)
|
484
|
+
)
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
describe "if elsif elsif else" do
|
489
|
+
let (:source) do
|
490
|
+
<<-EOS
|
491
|
+
#{section} {
|
492
|
+
if [foo] == [bar] { tplugin {} }
|
493
|
+
else if [bar] == [baz] { eifplugin {} }
|
494
|
+
else if [baz] == [bot] { eeifplugin {} }
|
495
|
+
else { fplugin {} }
|
496
|
+
}
|
497
|
+
EOS
|
498
|
+
end
|
499
|
+
|
500
|
+
it "should compile correctly" do
|
501
|
+
expect(compiled_section).to ir_eql(j.iIf(
|
502
|
+
j.eEq(j.eEventValue("[foo]"), j.eEventValue("[bar]")),
|
503
|
+
splugin("tplugin"),
|
504
|
+
j.iIf(
|
505
|
+
j.eEq(j.eEventValue("[bar]"), j.eEventValue("[baz]")),
|
506
|
+
splugin("eifplugin"),
|
507
|
+
j.iIf(
|
508
|
+
j.eEq(j.eEventValue("[baz]"), j.eEventValue("[bot]")),
|
509
|
+
splugin("eeifplugin"),
|
510
|
+
splugin("fplugin")
|
511
|
+
)
|
512
|
+
)
|
513
|
+
)
|
514
|
+
)
|
515
|
+
end
|
516
|
+
|
517
|
+
describe "nested ifs" do
|
518
|
+
let (:source) do
|
519
|
+
<<-EOS
|
520
|
+
#{section} {
|
521
|
+
if [foo] == [bar] {
|
522
|
+
if [bar] == [baz] { aplugin {} }
|
523
|
+
} else {
|
524
|
+
if [bar] == [baz] { bplugin {} }
|
525
|
+
else if [baz] == [bot] { cplugin {} }
|
526
|
+
else { dplugin {} }
|
527
|
+
}
|
528
|
+
}
|
529
|
+
EOS
|
530
|
+
end
|
531
|
+
|
532
|
+
it "should compile correctly" do
|
533
|
+
expect(compiled_section).to ir_eql(j.iIf(
|
534
|
+
j.eEq(j.eEventValue("[foo]"), j.eEventValue("[bar]")),
|
535
|
+
j.iIf(j.eEq(j.eEventValue("[bar]"), j.eEventValue("[baz]")),
|
536
|
+
splugin("aplugin"),
|
537
|
+
j.noop
|
538
|
+
),
|
539
|
+
j.iIf(
|
540
|
+
j.eEq(j.eEventValue("[bar]"), j.eEventValue("[baz]")),
|
541
|
+
splugin("bplugin"),
|
542
|
+
j.iIf(
|
543
|
+
j.eEq(j.eEventValue("[baz]"), j.eEventValue("[bot]")),
|
544
|
+
splugin("cplugin"),
|
545
|
+
splugin("dplugin")
|
546
|
+
)
|
547
|
+
)
|
548
|
+
)
|
549
|
+
)
|
550
|
+
end
|
551
|
+
end
|
552
|
+
end
|
553
|
+
end
|
554
|
+
end
|
555
|
+
|
556
|
+
context "filters" do
|
557
|
+
subject(:filter) { compiled[:filter] }
|
558
|
+
|
559
|
+
describe "a single filter" do
|
560
|
+
let(:source) { "input { } filter { grok {} } output { }" }
|
561
|
+
|
562
|
+
it "should contain the single input" do
|
563
|
+
expect(filter).to ir_eql(j.iPlugin(FILTER, "grok"))
|
564
|
+
end
|
565
|
+
end
|
566
|
+
|
567
|
+
it_should_behave_like "complex grammar", :filter
|
568
|
+
end
|
569
|
+
|
570
|
+
context "outputs" do
|
571
|
+
subject(:output) { compiled[:output] }
|
572
|
+
|
573
|
+
describe "a single output" do
|
574
|
+
let(:source) { "input { } output { stdout {} }" }
|
575
|
+
|
576
|
+
it "should contain the single input" do
|
577
|
+
expect(output).to ir_eql(j.iPlugin(OUTPUT, "stdout"))
|
578
|
+
end
|
579
|
+
end
|
580
|
+
|
581
|
+
it_should_behave_like "complex grammar", :output
|
582
|
+
end
|
583
|
+
end
|
584
|
+
end
|