Skip to content

Commit ccd4204

Browse files
committed
update to new event api
1 parent 17d4add commit ccd4204

File tree

4 files changed

+38
-26
lines changed

4 files changed

+38
-26
lines changed

.travis.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
---
12
sudo: false
23
language: ruby
34
cache: bundler
45
rvm:
5-
- jruby-1.7.23
6-
script:
7-
- bundle exec rspec spec
6+
- jruby-1.7.25
7+
script:
8+
- bundle exec rspec spec
9+
jdk: oraclejdk8
10+
before_install:
11+
- git clone -b feature/event_interface https://github.com/elastic/logstash

Gemfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
source 'https://rubygems.org'
2-
gemspec
2+
gemspec
3+
gem "logstash-core", :path => "./logstash/logstash-core"
4+
gem "logstash-core-plugin-api", :path => "./logstash/logstash-core-plugin-api"
5+
gem "logstash-core-event-java", :path => "./logstash/logstash-core-event-java"
6+
gem "logstash-devutils", :github => "elastic/logstash-devutils", :branch => "feature/plugin-api-2_0"
7+
gem "logstash-codec-json_lines", :github => "logstash-plugins/logstash-codec-json_lines", :branch => "feature/plugin-api-2_0"
8+
gem "logstash-codec-line", :github => "logstash-plugins/logstash-codec-line", :branch => "feature/plugin-api-2_0"
9+
gem "logstash-input-generator", :github => "logstash-plugins/logstash-input-generator", :branch => "feature/plugin-api-2_0"
10+
gem "logstash-codec-plain", :github => "logstash-plugins/logstash-codec-plain", :branch => "feature/plugin-api-2_0"

logstash-output-file.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
2020
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
2121

2222
# Gem dependencies
23-
s.add_runtime_dependency "logstash-core-plugin-api", "~> 1.0"
23+
s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
2424
s.add_runtime_dependency 'logstash-codec-json_lines'
2525
s.add_runtime_dependency 'logstash-codec-line'
2626

spec/outputs/file_spec.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333

3434
# Now check all events for order and correctness.
3535
events = tmp_file.map {|line| LogStash::Event.new(LogStash::Json.load(line))}
36-
sorted = events.sort_by {|e| e['sequence']}
36+
sorted = events.sort_by {|e| e.get('sequence')}
3737
sorted.each do |event|
38-
insist {event["message"]} == "hello world"
39-
insist {event["sequence"]} == line_num
38+
insist {event.get("message")} == "hello world"
39+
insist {event.get("sequence")} == line_num
4040
line_num += 1
4141
end
4242

@@ -68,10 +68,10 @@
6868
line_num = 0
6969
# Now check all events for order and correctness.
7070
events = Zlib::GzipReader.open(tmp_file.path).map {|line| LogStash::Event.new(LogStash::Json.load(line)) }
71-
sorted = events.sort_by {|e| e["sequence"]}
71+
sorted = events.sort_by {|e| e.get("sequence")}
7272
sorted.each do |event|
73-
insist {event["message"]} == "hello world"
74-
insist {event["sequence"]} == line_num
73+
insist {event.get("message")} == "hello world"
74+
insist {event.get("sequence")} == line_num
7575
line_num += 1
7676
end
7777
insist {line_num} == event_count
@@ -165,7 +165,7 @@
165165
context "when trying to write outside the files root directory" do
166166
let(:bad_event) do
167167
event = LogStash::Event.new
168-
event['error'] = '../uncool/directory'
168+
event.set('error', '../uncool/directory')
169169
event
170170
end
171171

@@ -178,7 +178,7 @@
178178

179179
# Trying to write outside the file root
180180
outside_path = "#{'../' * path.split(File::SEPARATOR).size}notcool"
181-
bad_event["error"] = outside_path
181+
bad_event.set("error", outside_path)
182182

183183

184184
output = LogStash::Outputs::File.new(config)
@@ -200,10 +200,10 @@
200200
output = LogStash::Outputs::File.new({ "path" => "/#{path}/%{error}"})
201201
output.register
202202

203-
bad_event['error'] = encoded_once
203+
bad_event.set('error', encoded_once)
204204
output.receive(bad_event)
205205

206-
bad_event['error'] = encoded_twice
206+
bad_event.set('error', encoded_twice)
207207
output.receive(bad_event)
208208

209209
expect(Dir.glob(File.join(path, "*")).size).to eq(2)
@@ -216,7 +216,7 @@
216216
output = LogStash::Outputs::File.new({ "path" => "/#{path}/%{error}"})
217217
output.register
218218

219-
bad_event['error'] = '../..//test'
219+
bad_event.set('error', '../..//test')
220220
output.receive(bad_event)
221221

222222
expect(Dir.glob(File.join(path, "*")).size).to eq(1)
@@ -228,15 +228,15 @@
228228
context 'when trying to write inside the file root directory' do
229229
it 'write the event to the generated filename' do
230230
good_event = LogStash::Event.new
231-
good_event['error'] = '42.txt'
231+
good_event.set('error', '42.txt')
232232

233233
Stud::Temporary.directory do |path|
234234
config = { "path" => "#{path}/%{error}" }
235235
output = LogStash::Outputs::File.new(config)
236236
output.register
237237
output.receive(good_event)
238238

239-
good_file = File.join(path, good_event['error'])
239+
good_file = File.join(path, good_event.get('error'))
240240
expect(File.exist?(good_file)).to eq(true)
241241
output.close
242242
end
@@ -284,15 +284,15 @@
284284

285285
it 'write the event to the generated filename with multiple deep' do
286286
good_event = LogStash::Event.new
287-
good_event['error'] = '/inside/errors/42.txt'
287+
good_event.set('error', '/inside/errors/42.txt')
288288

289289
Stud::Temporary.directory do |path|
290290
config = { "path" => "#{path}/%{error}" }
291291
output = LogStash::Outputs::File.new(config)
292292
output.register
293293
output.receive(good_event)
294294

295-
good_file = File.join(path, good_event['error'])
295+
good_file = File.join(path, good_event.get('error'))
296296
expect(File.exist?(good_file)).to eq(true)
297297
output.close
298298
end
@@ -303,7 +303,7 @@
303303
context "when using default configuration" do
304304
it 'write the event as a json line' do
305305
good_event = LogStash::Event.new
306-
good_event['message'] = 'hello world'
306+
good_event.set('message', 'hello world')
307307

308308
Stud::Temporary.directory do |path|
309309
config = { "path" => "#{path}/output.txt" }
@@ -315,15 +315,15 @@
315315
output.close #teardown first to allow reading the file
316316
File.open(good_file) {|f|
317317
event = LogStash::Event.new(LogStash::Json.load(f.readline))
318-
expect(event["message"]).to eq("hello world")
318+
expect(event.get("message")).to eq("hello world")
319319
}
320320
end
321321
end
322322
end
323323
context "when using line codec" do
324324
it 'writes event using specified format' do
325325
good_event = LogStash::Event.new
326-
good_event['message'] = "hello world"
326+
good_event.set('message', "hello world")
327327

328328
Stud::Temporary.directory do |path|
329329
config = { "path" => "#{path}/output.txt" }
@@ -344,7 +344,7 @@
344344
context "when using deprecated message_format config" do
345345
it 'falls back to line codec' do
346346
good_event = LogStash::Event.new
347-
good_event['message'] = 'hello world'
347+
good_event.set('message', 'hello world')
348348

349349
Stud::Temporary.directory do |path|
350350
config = { "path" => "#{path}/output.txt", "message_format" => "Custom format: %{message}" }
@@ -364,7 +364,7 @@
364364
context "when using file and dir modes" do
365365
it 'dirs and files are created with correct atypical permissions' do
366366
good_event = LogStash::Event.new
367-
good_event['message'] = "hello world"
367+
good_event.set('message', "hello world")
368368

369369
Stud::Temporary.directory do |path|
370370
config = {
@@ -385,7 +385,7 @@
385385
output.close #teardown first to allow reading the file
386386
File.open(good_file) {|f|
387387
event = LogStash::Event.new(LogStash::Json.load(f.readline))
388-
expect(event["message"]).to eq("hello world")
388+
expect(event.get("message")).to eq("hello world")
389389
}
390390
end
391391
end

0 commit comments

Comments
 (0)