Skip to content

Commit 284dc66

Browse files
plugin-api 2.0 migration
1 parent a7fe806 commit 284dc66

File tree

5 files changed

+188
-179
lines changed

5 files changed

+188
-179
lines changed

.travis.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
sudo: false
2+
jdk:
3+
- oraclejdk8
24
language: ruby
35
cache: bundler
46
rvm:
5-
- jruby-1.7.23
6-
script:
7+
- jruby-1.7.25
8+
before_install:
9+
- git clone -b feature/event_interface https://github.com/elastic/logstash
10+
script:
711
- bundle exec rspec spec

Gemfile

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
source 'https://rubygems.org'
2-
gemspec
2+
gemspec
3+
4+
# this is temporary for the feature/plugin-api-2_0 branch and is meant for travis testing
5+
gem "logstash-core", :path => "./logstash/logstash-core"
6+
gem "logstash-core-plugin-api", :path => "./logstash/logstash-core-plugin-api"
7+
gem "logstash-core-event-java", :path => "./logstash/logstash-core-event-java"
8+
gem "logstash-devutils", :github => "elastic/logstash-devutils", :branch => "feature/plugin-api-2_0"
9+
gem "logstash-patterns-core", :github => "logstash-plugins/logstash-patterns-core", :branch => "feature/plugin-api-2_0"

lib/logstash/filters/grok.rb

+7-9
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def register
247247
# will let folks redefine built-in patterns at runtime.
248248
@patternfiles += patterns_files_from_paths(@@patterns_path.to_a, "*")
249249
@patternfiles += patterns_files_from_paths(@patterns_dir, @patterns_files_glob)
250-
250+
251251
@patterns = Hash.new { |h,k| h[k] = [] }
252252

253253
@logger.info? and @logger.info("Match data", :match => @match)
@@ -269,8 +269,6 @@ def register
269269

270270
public
271271
def filter(event)
272-
273-
274272
matched = false
275273
done = false
276274

@@ -294,7 +292,7 @@ def filter(event)
294292

295293
private
296294
def match(groks, field, event)
297-
input = event[field]
295+
input = event.get(field)
298296
if input.is_a?(Array)
299297
success = false
300298
input.each do |input|
@@ -327,21 +325,21 @@ def handle(field, value, event)
327325
return if (value.nil? || (value.is_a?(String) && value.empty?)) unless @keep_empty_captures
328326

329327
if @overwrite.include?(field)
330-
event[field] = value
328+
event.set(field, value)
331329
else
332-
v = event[field]
330+
v = event.get(field)
333331
if v.nil?
334-
event[field] = value
332+
event.set(field, value)
335333
elsif v.is_a?(Array)
336334
# do not replace the code below with:
337335
# event[field] << value
338336
# this assumes implementation specific feature of returning a mutable object
339337
# from a field ref which should not be assumed and will change in the future.
340338
v << value
341-
event[field] = v
339+
event.set(field, v)
342340
elsif v.is_a?(String)
343341
# Promote to array since we aren't overwriting.
344-
event[field] = [v, value]
342+
event.set(field, [v, value])
345343
end
346344
end
347345
end

logstash-filter-grok.gemspec

+1-1
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" => "filter" }
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

2525
s.add_runtime_dependency 'jls-grok', '~> 0.11.1'
2626
s.add_runtime_dependency 'logstash-patterns-core'

0 commit comments

Comments
 (0)