refactor Ruby Event getter and setter

refactor wip gemfiles

refactor Java Event getter and setter

bump plugin-api to 2.0

use plugin-api 2.0

switch to core-event-java

include logstash-core-event-java.jar jar file so that gem dependency using the source tree work

updated core plugins to core-api 2.0

added grok for refactor branch

fix rebased specs

remove temp plugins github paths

remove commented out tmp alias_method
This commit is contained in:
Colin Surprenant 2016-04-21 17:38:03 -04:00
parent 5c667620e2
commit ee2c8af8c8
17 changed files with 481 additions and 340 deletions

View file

@ -4,7 +4,7 @@
source "https://rubygems.org" source "https://rubygems.org"
gem "logstash-core", "5.0.0.dev", :path => "./logstash-core" gem "logstash-core", "5.0.0.dev", :path => "./logstash-core"
gem "logstash-core-event-java", "5.0.0.dev", :path => "./logstash-core-event-java" gem "logstash-core-event-java", "5.0.0.dev", :path => "./logstash-core-event-java"
gem "logstash-core-plugin-api", "1.0.0", :path => "./logstash-core-plugin-api" gem "logstash-core-plugin-api", "2.0.0", :path => "./logstash-core-plugin-api"
gem "file-dependencies", "0.1.6" gem "file-dependencies", "0.1.6"
gem "ci_reporter_rspec", "1.0.0", :group => :development gem "ci_reporter_rspec", "1.0.0", :group => :development
gem "simplecov", :group => :development gem "simplecov", :group => :development
@ -14,10 +14,10 @@ gem "coveralls", :group => :development
# 1.6 is the last supported version on jruby. # 1.6 is the last supported version on jruby.
gem "tins", "1.6", :group => :development gem "tins", "1.6", :group => :development
gem "rspec", "~> 3.1.0", :group => :development gem "rspec", "~> 3.1.0", :group => :development
gem "logstash-devutils", "~> 0.0.15", :group => :development gem "logstash-devutils", :group => :development
gem "benchmark-ips", :group => :development gem "benchmark-ips", :group => :development
gem "octokit", "3.8.0", :group => :build gem "octokit", "3.8.0", :group => :build
gem "stud", "~> 0.0.21", :group => :build gem "stud", "~> 0.0.22", :group => :build
gem "fpm", "~> 1.3.3", :group => :build gem "fpm", "~> 1.3.3", :group => :build
gem "rubyzip", "~> 1.1.7", :group => :build gem "rubyzip", "~> 1.1.7", :group => :build
gem "gems", "~> 0.8.3", :group => :build gem "gems", "~> 0.8.3", :group => :build

View file

@ -1,3 +1,136 @@
GIT
remote: git://github.com/elastic/logstash-devutils.git
revision: e9af3a24824a41d0f19b025ca359e0735e820251
branch: feature/plugin-api-2_0
specs:
logstash-devutils (0.0.19-java)
fivemat
gem_publisher
insist (= 1.0.0)
kramdown
minitar
rake
rspec (~> 3.1.0)
rspec-wait
stud (>= 0.0.20)
GIT
remote: git://github.com/logstash-plugins/logstash-codec-json.git
revision: 141d488f3a73706d5ae08dd41468fed285fbbdf9
branch: feature/plugin-api-2_0
specs:
logstash-codec-json (2.1.4)
logstash-core-plugin-api (~> 2.0)
GIT
remote: git://github.com/logstash-plugins/logstash-codec-json_lines.git
revision: f1a3fda4d1affaa6da4b037eec78ee5f10287eb8
branch: feature/plugin-api-2_0
specs:
logstash-codec-json_lines (2.1.3)
logstash-codec-line (>= 2.1.0)
logstash-core-plugin-api (~> 2.0)
GIT
remote: git://github.com/logstash-plugins/logstash-codec-line.git
revision: f912b6ca5137bef914ea0e605cb34520b0f172d4
branch: feature/plugin-api-2_0
specs:
logstash-codec-line (2.1.2)
logstash-core-plugin-api (~> 2.0)
GIT
remote: git://github.com/logstash-plugins/logstash-codec-plain.git
revision: 5c5424905d5e06d7f7adc888411057c8a5681194
branch: feature/plugin-api-2_0
specs:
logstash-codec-plain (2.0.4)
logstash-core-plugin-api (~> 2.0)
GIT
remote: git://github.com/logstash-plugins/logstash-filter-clone.git
revision: 4da247817809ff68a47557f022c8049536651564
branch: feature/plugin-api-2_0
specs:
logstash-filter-clone (2.0.6)
logstash-core-plugin-api (~> 2.0)
GIT
remote: git://github.com/logstash-plugins/logstash-filter-grok.git
revision: 284dc6614b0cac6770cda2c18a52f8405146f1eb
branch: feature/plugin-api-2_0
specs:
logstash-filter-grok (2.0.5)
jls-grok (~> 0.11.1)
logstash-core-plugin-api (~> 2.0)
logstash-patterns-core
GIT
remote: git://github.com/logstash-plugins/logstash-filter-multiline.git
revision: fd1da31b7d1e0b44319c0f2865c767b36440583d
branch: feature/plugin-api-2_0
specs:
logstash-filter-multiline (2.0.5)
jls-grok (~> 0.11.0)
logstash-core-plugin-api (~> 2.0)
logstash-patterns-core
GIT
remote: git://github.com/logstash-plugins/logstash-filter-mutate.git
revision: f9624cc0a05354c308b2d22a5895c737eceaa08b
branch: feature/plugin-api-2_0
specs:
logstash-filter-mutate (2.0.6)
logstash-core-plugin-api (~> 2.0)
GIT
remote: git://github.com/logstash-plugins/logstash-input-generator.git
revision: 2557a4e7da667d6e801cac47e27ff297b6ecc79a
branch: feature/plugin-api-2_0
specs:
logstash-input-generator (2.0.4)
logstash-codec-plain
logstash-core-plugin-api (~> 2.0)
GIT
remote: git://github.com/logstash-plugins/logstash-input-stdin.git
revision: cca193c505f931500bd0f6be45afada2af0578ed
branch: feature/plugin-api-2_0
specs:
logstash-input-stdin (2.0.4)
concurrent-ruby
logstash-codec-line
logstash-core-plugin-api (~> 2.0)
GIT
remote: git://github.com/logstash-plugins/logstash-input-tcp.git
revision: b6f2705d7fc226c08dd0905561ef9373d2801a58
branch: feature/plugin-api-2_0
specs:
logstash-input-tcp (3.0.5)
logstash-codec-json
logstash-codec-json_lines
logstash-codec-line
logstash-codec-plain
logstash-core-plugin-api (~> 2.0)
GIT
remote: git://github.com/logstash-plugins/logstash-output-stdout.git
revision: c150cb4f560b047372e15887e8b6bf421af22fc9
branch: feature/plugin-api-2_0
specs:
logstash-output-stdout (2.0.6)
logstash-codec-line
logstash-core-plugin-api (~> 2.0)
GIT
remote: git://github.com/logstash-plugins/logstash-patterns-core.git
revision: e039ba2d3db6a01b6501fe0cab8a82453c6dc45f
branch: feature/plugin-api-2_0
specs:
logstash-patterns-core (2.0.5)
logstash-core-plugin-api (~> 2.0)
PATH PATH
remote: ./logstash-core remote: ./logstash-core
specs: specs:
@ -10,8 +143,8 @@ PATH
gems (~> 0.8.3) gems (~> 0.8.3)
i18n (= 0.6.9) i18n (= 0.6.9)
jrjackson (~> 0.3.7) jrjackson (~> 0.3.7)
jruby-monitoring (~> 0.1) jruby-monitoring (~> 0.3.1)
jruby-openssl (= 0.9.13) jruby-openssl (= 0.9.16)
logstash-core-event-java (~> 5.0.0.dev) logstash-core-event-java (~> 5.0.0.dev)
minitar (~> 0.5.4) minitar (~> 0.5.4)
pry (~> 0.10.1) pry (~> 0.10.1)
@ -32,7 +165,7 @@ PATH
PATH PATH
remote: ./logstash-core-plugin-api remote: ./logstash-core-plugin-api
specs: specs:
logstash-core-plugin-api (1.0.0-java) logstash-core-plugin-api (2.0.0-java)
logstash-core (= 5.0.0.dev) logstash-core (= 5.0.0.dev)
GEM GEM
@ -42,7 +175,7 @@ GEM
arr-pm (0.0.10) arr-pm (0.0.10)
cabin (> 0) cabin (> 0)
backports (3.6.8) backports (3.6.8)
benchmark-ips (2.5.0) benchmark-ips (2.6.1)
builder (3.2.2) builder (3.2.2)
cabin (0.8.1) cabin (0.8.1)
childprocess (0.5.9) childprocess (0.5.9)
@ -71,6 +204,7 @@ GEM
file-dependencies (0.1.6) file-dependencies (0.1.6)
minitar minitar
filesize (0.0.4) filesize (0.0.4)
fivemat (1.3.2)
flores (0.0.6) flores (0.0.6)
fpm (1.3.3) fpm (1.3.3)
arr-pm (~> 0.0.9) arr-pm (~> 0.0.9)
@ -85,20 +219,13 @@ GEM
i18n (0.6.9) i18n (0.6.9)
insist (1.0.0) insist (1.0.0)
jar-dependencies (0.3.2) jar-dependencies (0.3.2)
jrjackson (0.3.8) jls-grok (0.11.2)
jruby-monitoring (0.3.0) cabin (>= 0.6.0)
jruby-openssl (0.9.13-java) jrjackson (0.3.9-java)
jruby-monitoring (0.3.1)
jruby-openssl (0.9.16-java)
json (1.8.3-java) json (1.8.3-java)
kramdown (1.10.0) kramdown (1.10.0)
logstash-devutils (0.0.18-java)
gem_publisher
insist (= 1.0.0)
kramdown
minitar
rake
rspec (~> 3.1.0)
rspec-wait
stud (>= 0.0.20)
method_source (0.8.2) method_source (0.8.2)
minitar (0.5.4) minitar (0.5.4)
multipart-post (2.0.0) multipart-post (2.0.0)
@ -173,14 +300,27 @@ DEPENDENCIES
flores (~> 0.0.6) flores (~> 0.0.6)
fpm (~> 1.3.3) fpm (~> 1.3.3)
gems (~> 0.8.3) gems (~> 0.8.3)
logstash-codec-json!
logstash-codec-json_lines!
logstash-codec-line!
logstash-codec-plain!
logstash-core (= 5.0.0.dev)! logstash-core (= 5.0.0.dev)!
logstash-core-event-java (= 5.0.0.dev)! logstash-core-event-java (= 5.0.0.dev)!
logstash-core-plugin-api (= 1.0.0)! logstash-core-plugin-api (= 2.0.0)!
logstash-devutils (~> 0.0.15) logstash-devutils!
logstash-filter-clone!
logstash-filter-grok!
logstash-filter-multiline!
logstash-filter-mutate!
logstash-input-generator!
logstash-input-stdin!
logstash-input-tcp!
logstash-output-stdout!
logstash-patterns-core!
octokit (= 3.8.0) octokit (= 3.8.0)
rack-test rack-test
rspec (~> 3.1.0) rspec (~> 3.1.0)
rubyzip (~> 1.1.7) rubyzip (~> 1.1.7)
simplecov simplecov
stud (~> 0.0.21) stud (~> 0.0.22)
tins (= 1.6) tins (= 1.6)

View file

@ -26,10 +26,10 @@ describe LogStash::Event do
it "should serialize deep hash from field reference assignments" do it "should serialize deep hash from field reference assignments" do
e = LogStash::Event.new({TIMESTAMP => "2015-05-28T23:02:05.350Z"}) e = LogStash::Event.new({TIMESTAMP => "2015-05-28T23:02:05.350Z"})
e["foo"] = "bar" e.set("foo", "bar")
e["bar"] = 1 e.set("bar", 1)
e["baz"] = 1.0 e.set("baz", 1.0)
e["[fancy][pants][socks]"] = "shoes" e.set("[fancy][pants][socks]", "shoes")
expect(JSON.parse(e.to_json)).to eq(JSON.parse("{\"@timestamp\":\"2015-05-28T23:02:05.350Z\",\"@version\":\"1\",\"foo\":\"bar\",\"bar\":1,\"baz\":1.0,\"fancy\":{\"pants\":{\"socks\":\"shoes\"}}}")) expect(JSON.parse(e.to_json)).to eq(JSON.parse("{\"@timestamp\":\"2015-05-28T23:02:05.350Z\",\"@version\":\"1\",\"foo\":\"bar\",\"bar\":1,\"baz\":1.0,\"fancy\":{\"pants\":{\"socks\":\"shoes\"}}}"))
end end
end end
@ -37,79 +37,79 @@ describe LogStash::Event do
context "[]" do context "[]" do
it "should get simple values" do it "should get simple values" do
e = LogStash::Event.new({"foo" => "bar", "bar" => 1, "baz" => 1.0, TIMESTAMP => "2015-05-28T23:02:05.350Z"}) e = LogStash::Event.new({"foo" => "bar", "bar" => 1, "baz" => 1.0, TIMESTAMP => "2015-05-28T23:02:05.350Z"})
expect(e["foo"]).to eq("bar") expect(e.get("foo")).to eq("bar")
expect(e["[foo]"]).to eq("bar") expect(e.get("[foo]")).to eq("bar")
expect(e["bar"]).to eq(1) expect(e.get("bar")).to eq(1)
expect(e["[bar]"]).to eq(1) expect(e.get("[bar]")).to eq(1)
expect(e["baz"]).to eq(1.0) expect(e.get("baz")).to eq(1.0)
expect(e["[baz]"]).to eq(1.0) expect(e.get("[baz]")).to eq(1.0)
expect(e[TIMESTAMP].to_s).to eq("2015-05-28T23:02:05.350Z") expect(e.get(TIMESTAMP).to_s).to eq("2015-05-28T23:02:05.350Z")
expect(e["[#{TIMESTAMP}]"].to_s).to eq("2015-05-28T23:02:05.350Z") expect(e.get("[#{TIMESTAMP}]").to_s).to eq("2015-05-28T23:02:05.350Z")
end end
it "should get deep hash values" do it "should get deep hash values" do
e = LogStash::Event.new({"foo" => {"bar" => 1, "baz" => 1.0}}) e = LogStash::Event.new({"foo" => {"bar" => 1, "baz" => 1.0}})
expect(e["[foo][bar]"]).to eq(1) expect(e.get("[foo][bar]")).to eq(1)
expect(e["[foo][baz]"]).to eq(1.0) expect(e.get("[foo][baz]")).to eq(1.0)
end end
it "should get deep array values" do it "should get deep array values" do
e = LogStash::Event.new({"foo" => ["bar", 1, 1.0]}) e = LogStash::Event.new({"foo" => ["bar", 1, 1.0]})
expect(e["[foo][0]"]).to eq("bar") expect(e.get("[foo][0]")).to eq("bar")
expect(e["[foo][1]"]).to eq(1) expect(e.get("[foo][1]")).to eq(1)
expect(e["[foo][2]"]).to eq(1.0) expect(e.get("[foo][2]")).to eq(1.0)
expect(e["[foo][3]"]).to be_nil expect(e.get("[foo][3]")).to be_nil
end end
end end
context "[]=" do context "[]=" do
it "should set simple values" do it "should set simple values" do
e = LogStash::Event.new() e = LogStash::Event.new()
expect(e["foo"] = "bar").to eq("bar") expect(e.set("foo", "bar")).to eq("bar")
expect(e["foo"]).to eq("bar") expect(e.get("foo")).to eq("bar")
e = LogStash::Event.new({"foo" => "test"}) e = LogStash::Event.new({"foo" => "test"})
expect(e["foo"] = "bar").to eq("bar") expect(e.set("foo", "bar")).to eq("bar")
expect(e["foo"]).to eq("bar") expect(e.get("foo")).to eq("bar")
end end
it "should set deep hash values" do it "should set deep hash values" do
e = LogStash::Event.new() e = LogStash::Event.new()
expect(e["[foo][bar]"] = "baz").to eq("baz") expect(e.set("[foo][bar]", "baz")).to eq("baz")
expect(e["[foo][bar]"]).to eq("baz") expect(e.get("[foo][bar]")).to eq("baz")
expect(e["[foo][baz]"]).to be_nil expect(e.get("[foo][baz]")).to be_nil
end end
it "should set deep array values" do it "should set deep array values" do
e = LogStash::Event.new() e = LogStash::Event.new()
expect(e["[foo][0]"] = "bar").to eq("bar") expect(e.set("[foo][0]", "bar")).to eq("bar")
expect(e["[foo][0]"]).to eq("bar") expect(e.get("[foo][0]")).to eq("bar")
expect(e["[foo][1]"] = 1).to eq(1) expect(e.set("[foo][1]", 1)).to eq(1)
expect(e["[foo][1]"]).to eq(1) expect(e.get("[foo][1]")).to eq(1)
expect(e["[foo][2]"] = 1.0 ).to eq(1.0) expect(e.set("[foo][2]", 1.0)).to eq(1.0)
expect(e["[foo][2]"]).to eq(1.0) expect(e.get("[foo][2]")).to eq(1.0)
expect(e["[foo][3]"]).to be_nil expect(e.get("[foo][3]")).to be_nil
end end
it "should add key when setting nil value" do it "should add key when setting nil value" do
e = LogStash::Event.new() e = LogStash::Event.new()
e["[foo]"] = nil e.set("[foo]", nil)
expect(e.to_hash).to include("foo" => nil) expect(e.to_hash).to include("foo" => nil)
end end
# BigDecinal is now natively converted by JRuby, see https://github.com/elastic/logstash/pull/4838 # BigDecinal is now natively converted by JRuby, see https://github.com/elastic/logstash/pull/4838
it "should set BigDecimal" do it "should set BigDecimal" do
e = LogStash::Event.new() e = LogStash::Event.new()
e["[foo]"] = BigDecimal.new(1) e.set("[foo]", BigDecimal.new(1))
expect(e["foo"]).to be_kind_of(BigDecimal) expect(e.get("foo")).to be_kind_of(BigDecimal)
expect(e["foo"]).to eq(BigDecimal.new(1)) expect(e.get("foo")).to eq(BigDecimal.new(1))
end end
it "should set RubyBignum" do it "should set RubyBignum" do
e = LogStash::Event.new() e = LogStash::Event.new()
e["[foo]"] = -9223372036854776000 e.set("[foo]", -9223372036854776000)
expect(e["foo"]).to be_kind_of(Bignum) expect(e.get("foo")).to be_kind_of(Bignum)
expect(e["foo"]).to eq(-9223372036854776000) expect(e.get("foo")).to eq(-9223372036854776000)
end end
end end
@ -117,7 +117,7 @@ describe LogStash::Event do
it "getters should present a Ruby LogStash::Timestamp" do it "getters should present a Ruby LogStash::Timestamp" do
e = LogStash::Event.new() e = LogStash::Event.new()
expect(e.timestamp.class).to eq(LogStash::Timestamp) expect(e.timestamp.class).to eq(LogStash::Timestamp)
expect(e[TIMESTAMP].class).to eq(LogStash::Timestamp) expect(e.get(TIMESTAMP).class).to eq(LogStash::Timestamp)
end end
it "to_hash should inject a Ruby LogStash::Timestamp" do it "to_hash should inject a Ruby LogStash::Timestamp" do
@ -134,9 +134,9 @@ describe LogStash::Event do
it "should set timestamp" do it "should set timestamp" do
e = LogStash::Event.new e = LogStash::Event.new
now = Time.now now = Time.now
e["@timestamp"] = LogStash::Timestamp.at(now.to_i) e.set("@timestamp", LogStash::Timestamp.at(now.to_i))
expect(e.timestamp.to_i).to eq(now.to_i) expect(e.timestamp.to_i).to eq(now.to_i)
expect(e["@timestamp"].to_i).to eq(now.to_i) expect(e.get("@timestamp").to_i).to eq(now.to_i)
end end
end end
@ -144,16 +144,16 @@ describe LogStash::Event do
it "should append" do it "should append" do
event = LogStash::Event.new("message" => "hello world") event = LogStash::Event.new("message" => "hello world")
event.append(LogStash::Event.new("message" => "another thing")) event.append(LogStash::Event.new("message" => "another thing"))
expect(event["message"]).to eq(["hello world", "another thing"]) expect(event.get("message")).to eq(["hello world", "another thing"])
end end
end end
context "tags" do context "tags" do
it "should tag" do it "should tag" do
event = LogStash::Event.new("message" => "hello world") event = LogStash::Event.new("message" => "hello world")
expect(event["tags"]).to be_nil expect(event.get("tags")).to be_nil
event["tags"] = ["foo"] event.tag("foo")
expect(event["tags"]).to eq(["foo"]) expect(event.get("tags")).to eq(["foo"])
end end
end end
@ -258,8 +258,8 @@ describe LogStash::Event do
expect(LogStash::Event.from_json(source_json).size).to eq(1) expect(LogStash::Event.from_json(source_json).size).to eq(1)
event = LogStash::Event.from_json(source_json)[0] event = LogStash::Event.from_json(source_json)[0]
expect(event["[foo]"]).to eq(1) expect(event.get("[foo]")).to eq(1)
expect(event["[bar]"]).to eq("baz") expect(event.get("[bar]")).to eq("baz")
end end
it "should ignore blank strings" do it "should ignore blank strings" do

View file

@ -140,14 +140,14 @@ public class JrubyEventExtLibrary implements Library {
return context.nil; return context.nil;
} }
@JRubyMethod(name = "[]", required = 1) @JRubyMethod(name = "get", required = 1)
public IRubyObject ruby_get_field(ThreadContext context, RubyString reference) public IRubyObject ruby_get_field(ThreadContext context, RubyString reference)
{ {
Object value = this.event.getField(reference.asJavaString()); Object value = this.event.getField(reference.asJavaString());
return Rubyfier.deep(context.runtime, value); return Rubyfier.deep(context.runtime, value);
} }
@JRubyMethod(name = "[]=", required = 2) @JRubyMethod(name = "set", required = 2)
public IRubyObject ruby_set_field(ThreadContext context, RubyString reference, IRubyObject value) public IRubyObject ruby_set_field(ThreadContext context, RubyString reference, IRubyObject value)
{ {
String r = reference.asJavaString(); String r = reference.asJavaString();

View file

@ -54,6 +54,7 @@ class LogStash::Event
VERSION_ONE = "1" VERSION_ONE = "1"
TIMESTAMP_FAILURE_TAG = "_timestampparsefailure" TIMESTAMP_FAILURE_TAG = "_timestampparsefailure"
TIMESTAMP_FAILURE_FIELD = "_@timestamp" TIMESTAMP_FAILURE_FIELD = "_@timestamp"
TAGS = "tags".freeze
METADATA = "@metadata".freeze METADATA = "@metadata".freeze
METADATA_BRACKETS = "[#{METADATA}]".freeze METADATA_BRACKETS = "[#{METADATA}]".freeze
@ -113,7 +114,7 @@ class LogStash::Event
@data[TIMESTAMP] = val @data[TIMESTAMP] = val
end end
def [](fieldref) def get(fieldref)
if fieldref.start_with?(METADATA_BRACKETS) if fieldref.start_with?(METADATA_BRACKETS)
@metadata_accessors.get(fieldref[METADATA_BRACKETS.length .. -1]) @metadata_accessors.get(fieldref[METADATA_BRACKETS.length .. -1])
elsif fieldref == METADATA elsif fieldref == METADATA
@ -123,7 +124,7 @@ class LogStash::Event
end end
end end
def []=(fieldref, value) def set(fieldref, value)
if fieldref == TIMESTAMP && !value.is_a?(LogStash::Timestamp) if fieldref == TIMESTAMP && !value.is_a?(LogStash::Timestamp)
raise TypeError, "The field '@timestamp' must be a (LogStash::Timestamp, not a #{value.class} (#{value})" raise TypeError, "The field '@timestamp' must be a (LogStash::Timestamp, not a #{value.class} (#{value})"
end end
@ -201,8 +202,9 @@ class LogStash::Event
def tag(value) def tag(value)
# Generalize this method for more usability # Generalize this method for more usability
self["tags"] ||= [] tags = @accessors.get(TAGS) || []
self["tags"] << value unless self["tags"].include?(value) tags << value unless tags.include?(value)
@accessors.set(TAGS, tags)
end end
def to_hash_with_metadata def to_hash_with_metadata
@ -269,9 +271,8 @@ class LogStash::Event
logger.warn("Error parsing #{TIMESTAMP} string, setting current time to #{TIMESTAMP}, original in #{TIMESTAMP_FAILURE_FIELD} field", :value => o.inspect, :exception => e.message) logger.warn("Error parsing #{TIMESTAMP} string, setting current time to #{TIMESTAMP}, original in #{TIMESTAMP_FAILURE_FIELD} field", :value => o.inspect, :exception => e.message)
end end
@data["tags"] ||= [] tag(TIMESTAMP_FAILURE_TAG)
@data["tags"] << TIMESTAMP_FAILURE_TAG unless @data["tags"].include?(TIMESTAMP_FAILURE_TAG) @accessors.set(TIMESTAMP_FAILURE_FIELD, o)
@data[TIMESTAMP_FAILURE_FIELD] = o
LogStash::Timestamp.now LogStash::Timestamp.now
end end

View file

@ -115,7 +115,7 @@ module LogStash
end end
def evaluate(event) def evaluate(event)
value = event[@key] value = event.get(@key)
case value case value
when nil when nil

View file

@ -8,68 +8,68 @@ describe LogStash::Event do
shared_examples "all event tests" do shared_examples "all event tests" do
context "[]=" do context "[]=" do
it "should raise an exception if you attempt to set @timestamp to a value type other than a Time object" do it "should raise an exception if you attempt to set @timestamp to a value type other than a Time object" do
expect{subject["@timestamp"] = "crash!"}.to raise_error(TypeError) expect{subject.set("@timestamp", "crash!")}.to raise_error(TypeError)
end end
it "should assign simple fields" do it "should assign simple fields" do
expect(subject["foo"]).to be_nil expect(subject.get("foo")).to be_nil
expect(subject["foo"] = "bar").to eq("bar") expect(subject.set("foo", "bar")).to eq("bar")
expect(subject["foo"]).to eq("bar") expect(subject.get("foo")).to eq("bar")
end end
it "should overwrite simple fields" do it "should overwrite simple fields" do
expect(subject["foo"]).to be_nil expect(subject.get("foo")).to be_nil
expect(subject["foo"] = "bar").to eq("bar") expect(subject.set("foo", "bar")).to eq("bar")
expect(subject["foo"]).to eq("bar") expect(subject.get("foo")).to eq("bar")
expect(subject["foo"] = "baz").to eq("baz") expect(subject.set("foo", "baz")).to eq("baz")
expect(subject["foo"]).to eq("baz") expect(subject.get("foo")).to eq("baz")
end end
it "should assign deep fields" do it "should assign deep fields" do
expect(subject["[foo][bar]"]).to be_nil expect(subject.get("[foo][bar]")).to be_nil
expect(subject["[foo][bar]"] = "baz").to eq("baz") expect(subject.set("[foo][bar]", "baz")).to eq("baz")
expect(subject["[foo][bar]"]).to eq("baz") expect(subject.get("[foo][bar]")).to eq("baz")
end end
it "should overwrite deep fields" do it "should overwrite deep fields" do
expect(subject["[foo][bar]"]).to be_nil expect(subject.get("[foo][bar]")).to be_nil
expect(subject["[foo][bar]"] = "baz").to eq("baz") expect(subject.set("[foo][bar]", "baz")).to eq("baz")
expect(subject["[foo][bar]"]).to eq("baz") expect(subject.get("[foo][bar]")).to eq("baz")
expect(subject["[foo][bar]"] = "zab").to eq("zab") expect(subject.set("[foo][bar]", "zab")).to eq("zab")
expect(subject["[foo][bar]"]).to eq("zab") expect(subject.get("[foo][bar]")).to eq("zab")
end end
it "allow to set the @metadata key to a hash" do it "allow to set the @metadata key to a hash" do
subject["@metadata"] = { "action" => "index" } subject.set("@metadata", { "action" => "index" })
expect(subject["[@metadata][action]"]).to eq("index") expect(subject.get("[@metadata][action]")).to eq("index")
end end
it "should add key when setting nil value" do it "should add key when setting nil value" do
subject["[baz]"] = nil subject.set("[baz]", nil)
expect(subject.to_hash).to include("baz" => nil) expect(subject.to_hash).to include("baz" => nil)
end end
it "should set nil element within existing array value" do it "should set nil element within existing array value" do
subject["[foo]"] = ["bar", "baz"] subject.set("[foo]", ["bar", "baz"])
expect(subject["[foo][0]"] = nil).to eq(nil) expect(subject.set("[foo][0]", nil)).to eq(nil)
expect(subject["[foo]"]).to eq([nil, "baz"]) expect(subject.get("[foo]")).to eq([nil, "baz"])
end end
it "should set nil in first element within empty array" do it "should set nil in first element within empty array" do
subject["[foo]"] = [] subject.set("[foo]", [])
expect(subject["[foo][0]"] = nil).to eq(nil) expect(subject.set("[foo][0]", nil)).to eq(nil)
expect(subject["[foo]"]).to eq([nil]) expect(subject.get("[foo]")).to eq([nil])
end end
it "should set nil in second element within empty array" do it "should set nil in second element within empty array" do
subject["[foo]"] = [] subject.set("[foo]", [])
expect(subject["[foo][1]"] = nil).to eq(nil) expect(subject.set("[foo][1]", nil)).to eq(nil)
expect(subject["[foo]"]).to eq([nil, nil]) expect(subject.get("[foo]")).to eq([nil, nil])
end end
end end
@ -79,7 +79,7 @@ describe LogStash::Event do
event = LogStash::Event.new({ "reference" => data }) event = LogStash::Event.new({ "reference" => data })
LogStash::Util::Decorators.add_fields({"reference_test" => "%{reference}"}, event, "dummy-plugin") LogStash::Util::Decorators.add_fields({"reference_test" => "%{reference}"}, event, "dummy-plugin")
data.downcase! data.downcase!
expect(event["reference_test"]).not_to eq(data) expect(event.get("reference_test")).not_to eq(data)
end end
it "should not return a Fixnum reference" do it "should not return a Fixnum reference" do
@ -87,7 +87,7 @@ describe LogStash::Event do
event = LogStash::Event.new({ "reference" => data }) event = LogStash::Event.new({ "reference" => data })
LogStash::Util::Decorators.add_fields({"reference_test" => "%{reference}"}, event, "dummy-plugin") LogStash::Util::Decorators.add_fields({"reference_test" => "%{reference}"}, event, "dummy-plugin")
data += 41 data += 41
expect(event["reference_test"]).to eq("1") expect(event.get("reference_test")).to eq("1")
end end
it "should report a unix timestamp for %{+%s}" do it "should report a unix timestamp for %{+%s}" do
@ -124,7 +124,7 @@ describe LogStash::Event do
it "should report fields with %{field} syntax" do it "should report fields with %{field} syntax" do
expect(subject.sprintf("%{type}")).to eq("sprintf") expect(subject.sprintf("%{type}")).to eq("sprintf")
expect(subject.sprintf("%{message}")).to eq(subject["message"]) expect(subject.sprintf("%{message}")).to eq(subject.get("message"))
end end
it "should print deep fields" do it "should print deep fields" do
@ -153,35 +153,35 @@ describe LogStash::Event do
end end
it "should render nil array values as leading empty string" do it "should render nil array values as leading empty string" do
expect(subject["foo"] = [nil, "baz"]).to eq([nil, "baz"]) expect(subject.set("foo", [nil, "baz"])).to eq([nil, "baz"])
expect(subject["[foo][0]"]).to be_nil expect(subject.get("[foo][0]")).to be_nil
expect(subject["[foo][1]"]).to eq("baz") expect(subject.get("[foo][1]")).to eq("baz")
expect(subject.sprintf("%{[foo]}")).to eq(",baz") expect(subject.sprintf("%{[foo]}")).to eq(",baz")
end end
it "should render nil array values as middle empty string" do it "should render nil array values as middle empty string" do
expect(subject["foo"] = ["bar", nil, "baz"]).to eq(["bar", nil, "baz"]) expect(subject.set("foo", ["bar", nil, "baz"])).to eq(["bar", nil, "baz"])
expect(subject["[foo][0]"]).to eq("bar") expect(subject.get("[foo][0]")).to eq("bar")
expect(subject["[foo][1]"]).to be_nil expect(subject.get("[foo][1]")).to be_nil
expect(subject["[foo][2]"]).to eq("baz") expect(subject.get("[foo][2]")).to eq("baz")
expect(subject.sprintf("%{[foo]}")).to eq("bar,,baz") expect(subject.sprintf("%{[foo]}")).to eq("bar,,baz")
end end
it "should render nil array values as trailing empty string" do it "should render nil array values as trailing empty string" do
expect(subject["foo"] = ["bar", nil]).to eq(["bar", nil]) expect(subject.set("foo", ["bar", nil])).to eq(["bar", nil])
expect(subject["[foo][0]"]).to eq("bar") expect(subject.get("[foo][0]")).to eq("bar")
expect(subject["[foo][1]"]).to be_nil expect(subject.get("[foo][1]")).to be_nil
expect(subject.sprintf("%{[foo]}")).to eq("bar,") expect(subject.sprintf("%{[foo]}")).to eq("bar,")
end end
it "should render deep arrays with nil value" do it "should render deep arrays with nil value" do
subject["[foo]"] = [[12, nil], 56] subject.set("[foo]", [[12, nil], 56])
expect(subject.sprintf("%{[foo]}")).to eq("12,,56") expect(subject.sprintf("%{[foo]}")).to eq("12,,56")
end end
@ -198,18 +198,18 @@ describe LogStash::Event do
context "#[]" do context "#[]" do
it "should fetch data" do it "should fetch data" do
expect(subject["type"]).to eq("sprintf") expect(subject.get("type")).to eq("sprintf")
end end
it "should fetch fields" do it "should fetch fields" do
expect(subject["a"]).to eq("b") expect(subject.get("a")).to eq("b")
expect(subject['c']['d']).to eq("f") expect(subject.get('c')['d']).to eq("f")
end end
it "should fetch deep fields" do it "should fetch deep fields" do
expect(subject["[j][k1]"]).to eq("v") expect(subject.get("[j][k1]")).to eq("v")
expect(subject["[c][d]"]).to eq("f") expect(subject.get("[c][d]")).to eq("f")
expect(subject['[f][g][h]']).to eq("i") expect(subject.get('[f][g][h]')).to eq("i")
expect(subject['[j][k3][4]']).to eq("m") expect(subject.get('[j][k3][4]')).to eq("m")
expect(subject['[j][5]']).to eq(7) expect(subject.get('[j][5]')).to eq(7)
end end
@ -217,7 +217,7 @@ describe LogStash::Event do
count = 1000000 count = 1000000
2.times do 2.times do
start = Time.now start = Time.now
count.times { subject["[j][k1]"] } count.times { subject.get("[j][k1]") }
duration = Time.now - start duration = Time.now - start
puts "event #[] rate: #{"%02.0f/sec" % (count / duration)}, elapsed: #{duration}s" puts "event #[] rate: #{"%02.0f/sec" % (count / duration)}, elapsed: #{duration}s"
end end
@ -263,11 +263,11 @@ describe LogStash::Event do
) )
subject.overwrite(new_event) subject.overwrite(new_event)
expect(subject["message"]).to eq("foo bar") expect(subject.get("message")).to eq("foo bar")
expect(subject["type"]).to eq("new") expect(subject.get("type")).to eq("new")
["tags", "source", "a", "c", "f", "j"].each do |field| ["tags", "source", "a", "c", "f", "j"].each do |field|
expect(subject[field]).to be_nil expect(subject.get(field)).to be_nil
end end
end end
end end
@ -275,7 +275,7 @@ describe LogStash::Event do
context "#append" do context "#append" do
it "should append strings to an array" do it "should append strings to an array" do
subject.append(LogStash::Event.new("message" => "another thing")) subject.append(LogStash::Event.new("message" => "another thing"))
expect(subject["message"]).to eq([ "hello world", "another thing" ]) expect(subject.get("message")).to eq([ "hello world", "another thing" ])
end end
it "should concatenate tags" do it "should concatenate tags" do
@ -283,54 +283,54 @@ describe LogStash::Event do
# added to_a for when array is a Java Collection when produced from json input # added to_a for when array is a Java Collection when produced from json input
# TODO: we have to find a better way to handle this in tests. maybe override # TODO: we have to find a better way to handle this in tests. maybe override
# rspec eq or == to do an explicit to_a when comparing arrays? # rspec eq or == to do an explicit to_a when comparing arrays?
expect(subject["tags"].to_a).to eq([ "tag1", "tag2" ]) expect(subject.get("tags").to_a).to eq([ "tag1", "tag2" ])
end end
context "when event field is nil" do context "when event field is nil" do
it "should add single value as string" do it "should add single value as string" do
subject.append(LogStash::Event.new({"field1" => "append1"})) subject.append(LogStash::Event.new({"field1" => "append1"}))
expect(subject[ "field1" ]).to eq("append1") expect(subject.get("field1")).to eq("append1")
end end
it "should add multi values as array" do it "should add multi values as array" do
subject.append(LogStash::Event.new({"field1" => [ "append1","append2" ]})) subject.append(LogStash::Event.new({"field1" => [ "append1","append2" ]}))
expect(subject[ "field1" ]).to eq([ "append1","append2" ]) expect(subject.get("field1")).to eq([ "append1","append2" ])
end end
end end
context "when event field is a string" do context "when event field is a string" do
before { subject[ "field1" ] = "original1" } before { subject.set("field1", "original1") }
it "should append string to values, if different from current" do it "should append string to values, if different from current" do
subject.append(LogStash::Event.new({"field1" => "append1"})) subject.append(LogStash::Event.new({"field1" => "append1"}))
expect(subject[ "field1" ]).to eq([ "original1", "append1" ]) expect(subject.get("field1")).to eq([ "original1", "append1" ])
end end
it "should not change value, if appended value is equal current" do it "should not change value, if appended value is equal current" do
subject.append(LogStash::Event.new({"field1" => "original1"})) subject.append(LogStash::Event.new({"field1" => "original1"}))
expect(subject[ "field1" ]).to eq("original1") expect(subject.get("field1")).to eq("original1")
end end
it "should concatenate values in an array" do it "should concatenate values in an array" do
subject.append(LogStash::Event.new({"field1" => [ "append1" ]})) subject.append(LogStash::Event.new({"field1" => [ "append1" ]}))
expect(subject[ "field1" ]).to eq([ "original1", "append1" ]) expect(subject.get("field1")).to eq([ "original1", "append1" ])
end end
it "should join array, removing duplicates" do it "should join array, removing duplicates" do
subject.append(LogStash::Event.new({"field1" => [ "append1","original1" ]})) subject.append(LogStash::Event.new({"field1" => [ "append1","original1" ]}))
expect(subject[ "field1" ]).to eq([ "original1", "append1" ]) expect(subject.get("field1")).to eq([ "original1", "append1" ])
end end
end end
context "when event field is an array" do context "when event field is an array" do
before { subject[ "field1" ] = [ "original1", "original2" ] } before { subject.set("field1", [ "original1", "original2" ] )}
it "should append string values to array, if not present in array" do it "should append string values to array, if not present in array" do
subject.append(LogStash::Event.new({"field1" => "append1"})) subject.append(LogStash::Event.new({"field1" => "append1"}))
expect(subject[ "field1" ]).to eq([ "original1", "original2", "append1" ]) expect(subject.get("field1")).to eq([ "original1", "original2", "append1" ])
end end
it "should not append string values, if the array already contains it" do it "should not append string values, if the array already contains it" do
subject.append(LogStash::Event.new({"field1" => "original1"})) subject.append(LogStash::Event.new({"field1" => "original1"}))
expect(subject[ "field1" ]).to eq([ "original1", "original2" ]) expect(subject.get("field1")).to eq([ "original1", "original2" ])
end end
it "should join array, removing duplicates" do it "should join array, removing duplicates" do
subject.append(LogStash::Event.new({"field1" => [ "append1","original1" ]})) subject.append(LogStash::Event.new({"field1" => [ "append1","original1" ]}))
expect(subject[ "field1" ]).to eq([ "original1", "original2", "append1" ]) expect(subject.get("field1")).to eq([ "original1", "original2", "append1" ])
end end
end end
@ -342,7 +342,7 @@ describe LogStash::Event do
data = { "@timestamp" => "2013-12-21T07:25:06.605Z" } data = { "@timestamp" => "2013-12-21T07:25:06.605Z" }
event = LogStash::Event.new(data) event = LogStash::Event.new(data)
expect(event["@timestamp"]).to be_a(LogStash::Timestamp) expect(event.get("@timestamp")).to be_a(LogStash::Timestamp)
duration = 0 duration = 0
[warmup, count].each do |i| [warmup, count].each do |i|
@ -411,13 +411,13 @@ describe LogStash::Event do
it "should tag for invalid value" do it "should tag for invalid value" do
event = LogStash::Event.new("@timestamp" => "foo") event = LogStash::Event.new("@timestamp" => "foo")
expect(event.timestamp.to_i).to be_within(1).of Time.now.to_i expect(event.timestamp.to_i).to be_within(1).of Time.now.to_i
expect(event["tags"]).to eq([LogStash::Event::TIMESTAMP_FAILURE_TAG]) expect(event.get("tags")).to eq([LogStash::Event::TIMESTAMP_FAILURE_TAG])
expect(event[LogStash::Event::TIMESTAMP_FAILURE_FIELD]).to eq("foo") expect(event.get(LogStash::Event::TIMESTAMP_FAILURE_FIELD)).to eq("foo")
event = LogStash::Event.new("@timestamp" => 666) event = LogStash::Event.new("@timestamp" => 666)
expect(event.timestamp.to_i).to be_within(1).of Time.now.to_i expect(event.timestamp.to_i).to be_within(1).of Time.now.to_i
expect(event["tags"]).to eq([LogStash::Event::TIMESTAMP_FAILURE_TAG]) expect(event.get("tags")).to eq([LogStash::Event::TIMESTAMP_FAILURE_TAG])
expect(event[LogStash::Event::TIMESTAMP_FAILURE_FIELD]).to eq(666) expect(event.get(LogStash::Event::TIMESTAMP_FAILURE_FIELD)).to eq(666)
end end
it "should warn for invalid value" do it "should warn for invalid value" do
@ -432,8 +432,8 @@ describe LogStash::Event do
it "should tag for invalid string format" do it "should tag for invalid string format" do
event = LogStash::Event.new("@timestamp" => "foo") event = LogStash::Event.new("@timestamp" => "foo")
expect(event.timestamp.to_i).to be_within(1).of Time.now.to_i expect(event.timestamp.to_i).to be_within(1).of Time.now.to_i
expect(event["tags"]).to eq([LogStash::Event::TIMESTAMP_FAILURE_TAG]) expect(event.get("tags")).to eq([LogStash::Event::TIMESTAMP_FAILURE_TAG])
expect(event[LogStash::Event::TIMESTAMP_FAILURE_FIELD]).to eq("foo") expect(event.get(LogStash::Event::TIMESTAMP_FAILURE_FIELD)).to eq("foo")
end end
it "should warn for invalid string format" do it "should warn for invalid string format" do
@ -478,7 +478,7 @@ describe LogStash::Event do
end end
it "should still allow normal field access" do it "should still allow normal field access" do
expect(subject["hello"]).to eq("world") expect(subject.get("hello")).to eq("world")
end end
end end
@ -491,15 +491,15 @@ describe LogStash::Event do
expect(fieldref).to start_with("[@metadata]") expect(fieldref).to start_with("[@metadata]")
# Set it. # Set it.
subject[fieldref] = value subject.set(fieldref, value)
end end
it "should still allow normal field access" do it "should still allow normal field access" do
expect(subject["normal"]).to eq("normal") expect(subject.get("normal")).to eq("normal")
end end
it "should allow getting" do it "should allow getting" do
expect(subject[fieldref]).to eq(value) expect(subject.get(fieldref)).to eq(value)
end end
it "should be hidden from .to_json" do it "should be hidden from .to_json" do
@ -522,10 +522,10 @@ describe LogStash::Event do
context "with no metadata" do context "with no metadata" do
subject { LogStash::Event.new("foo" => "bar") } subject { LogStash::Event.new("foo" => "bar") }
it "should have no metadata" do it "should have no metadata" do
expect(subject["@metadata"]).to be_empty expect(subject.get("@metadata")).to be_empty
end end
it "should still allow normal field access" do it "should still allow normal field access" do
expect(subject["foo"]).to eq("bar") expect(subject.get("foo")).to eq("bar")
end end
it "should not include the @metadata key" do it "should not include the @metadata key" do
@ -599,7 +599,7 @@ describe LogStash::Event do
end end
it "return the string containing the timestamp, the host and the message" do it "return the string containing the timestamp, the host and the message" do
expect(event1.to_s).to eq("#{timestamp.to_iso8601} #{event1["host"]} #{event1["message"]}") expect(event1.to_s).to eq("#{timestamp.to_iso8601} #{event1.get("host")} #{event1.get("message")}")
end end
end end
@ -607,27 +607,27 @@ describe LogStash::Event do
let(:event) { LogStash::Event.new({ "message" => "foo" }) } let(:event) { LogStash::Event.new({ "message" => "foo" }) }
it "should invalidate target caching" do it "should invalidate target caching" do
expect(event["[a][0]"]).to be_nil expect(event.get("[a][0]")).to be_nil
expect(event["[a][0]"] = 42).to eq(42) expect(event.set("[a][0]", 42)).to eq(42)
expect(event["[a][0]"]).to eq(42) expect(event.get("[a][0]")).to eq(42)
expect(event["[a]"]).to eq({"0" => 42}) expect(event.get("[a]")).to eq({"0" => 42})
expect(event["[a]"] = [42, 24]).to eq([42, 24]) expect(event.set("[a]", [42, 24])).to eq([42, 24])
expect(event["[a]"]).to eq([42, 24]) expect(event.get("[a]")).to eq([42, 24])
expect(event["[a][0]"]).to eq(42) expect(event.get("[a][0]")).to eq(42)
expect(event["[a]"] = [24, 42]).to eq([24, 42]) expect(event.set("[a]", [24, 42])).to eq([24, 42])
expect(event["[a][0]"]).to eq(24) expect(event.get("[a][0]")).to eq(24)
expect(event["[a][0]"] = {"a "=> 99, "b" => 98}).to eq({"a "=> 99, "b" => 98}) expect(event.set("[a][0]", {"a "=> 99, "b" => 98})).to eq({"a "=> 99, "b" => 98})
expect(event["[a][0]"]).to eq({"a "=> 99, "b" => 98}) expect(event.get("[a][0]")).to eq({"a "=> 99, "b" => 98})
expect(event["[a]"]).to eq([{"a "=> 99, "b" => 98}, 42]) expect(event.get("[a]")).to eq([{"a "=> 99, "b" => 98}, 42])
expect(event["[a][0]"]).to eq({"a "=> 99, "b" => 98}) expect(event.get("[a][0]")).to eq({"a "=> 99, "b" => 98})
expect(event["[a][1]"]).to eq(42) expect(event.get("[a][1]")).to eq(42)
expect(event["[a][0][b]"]).to eq(98) expect(event.get("[a][0][b]")).to eq(98)
end end
end end
end end

View file

@ -1,2 +1,2 @@
# encoding: utf-8 # encoding: utf-8
LOGSTASH_CORE_PLUGIN_API = "1.0.0" LOGSTASH_CORE_PLUGIN_API = "2.0.0"

View file

@ -512,7 +512,7 @@ module LogStash; module Config; module AST
end end
class Selector < RValue class Selector < RValue
def compile def compile
return "event[#{text_value.inspect}]" return "event.get(#{text_value.inspect})"
end end
end end
class SelectorElement < Node; end class SelectorElement < Node; end

View file

@ -187,12 +187,12 @@ class LogStash::Filters::Base < LogStash::Plugin
# this is important because a construct like event["tags"].delete(tag) will not work # this is important because a construct like event["tags"].delete(tag) will not work
# in the current Java event implementation. see https://github.com/elastic/logstash/issues/4140 # in the current Java event implementation. see https://github.com/elastic/logstash/issues/4140
@remove_tag.each do |tag| @remove_tag.each do |tag|
tags = event["tags"] tags = event.get("tags")
break if tags.nil? || tags.empty? break if tags.nil? || tags.empty?
tag = event.sprintf(tag) tag = event.sprintf(tag)
@logger.debug? and @logger.debug("filters/#{self.class.name}: removing tag", :tag => tag) @logger.debug? and @logger.debug("filters/#{self.class.name}: removing tag", :tag => tag)
tags.delete(tag) tags.delete(tag)
event["tags"] = tags event.set("tags", tags)
end end
end # def filter_matched end # def filter_matched

View file

@ -97,7 +97,7 @@ class LogStash::Inputs::Base < LogStash::Plugin
protected protected
def decorate(event) def decorate(event)
# Only set 'type' if not already set. This is backwards-compatible behavior # Only set 'type' if not already set. This is backwards-compatible behavior
event["type"] = @type if @type && !event.include?("type") event.set("type", @type) if @type && !event.include?("type")
LogStash::Util::Decorators.add_fields(@add_field,event,"inputs/#{self.class.name}") LogStash::Util::Decorators.add_fields(@add_field,event,"inputs/#{self.class.name}")
LogStash::Util::Decorators.add_tags(@tags,event,"inputs/#{self.class.name}") LogStash::Util::Decorators.add_tags(@tags,event,"inputs/#{self.class.name}")

View file

@ -22,11 +22,11 @@ module LogStash::Util
# note below that the array field needs to be updated then reassigned to the event. # note below that the array field needs to be updated then reassigned to the event.
# this is important because a construct like event[field] << v will not work # this is important because a construct like event[field] << v will not work
# in the current Java event implementation. see https://github.com/elastic/logstash/issues/4140 # in the current Java event implementation. see https://github.com/elastic/logstash/issues/4140
a = Array(event[field]) a = Array(event.get(field))
a << v a << v
event[field] = a event.set(field, a)
else else
event[field] = v event.set(field, v)
end end
@logger.debug? and @logger.debug("#{pluginname}: adding value to field", :field => field, :value => value) @logger.debug? and @logger.debug("#{pluginname}: adding value to field", :field => field, :value => value)
end end
@ -41,9 +41,9 @@ module LogStash::Util
# note below that the tags array field needs to be updated then reassigned to the event. # note below that the tags array field needs to be updated then reassigned to the event.
# this is important because a construct like event["tags"] << tag will not work # this is important because a construct like event["tags"] << tag will not work
# in the current Java event implementation. see https://github.com/elastic/logstash/issues/4140 # in the current Java event implementation. see https://github.com/elastic/logstash/issues/4140
tags = event["tags"] || [] tags = event.get("tags") || []
tags << tag tags << tag
event["tags"] = tags event.set("tags", tags)
end end
end end

View file

@ -64,24 +64,24 @@ describe "conditionals in filter" do
CONFIG CONFIG
sample({"foo" => "bar"}) do sample({"foo" => "bar"}) do
expect(subject["always"]).to eq("awesome") expect(subject.get("always")).to eq("awesome")
expect(subject["hello"]).to eq("world") expect(subject.get("hello")).to eq("world")
expect(subject["fancy"]).to be_nil expect(subject.get("fancy")).to be_nil
expect(subject["free"]).to be_nil expect(subject.get("free")).to be_nil
end end
sample({"notfoo" => "bar"}) do sample({"notfoo" => "bar"}) do
expect(subject["always"]).to eq("awesome") expect(subject.get("always")).to eq("awesome")
expect(subject["hello"]).to be_nil expect(subject.get("hello")).to be_nil
expect(subject["fancy"]).to be_nil expect(subject.get("fancy")).to be_nil
expect(subject["free"]).to eq("hugs") expect(subject.get("free")).to eq("hugs")
end end
sample({"bar" => "baz"}) do sample({"bar" => "baz"}) do
expect(subject["always"]).to eq("awesome") expect(subject.get("always")).to eq("awesome")
expect(subject["hello"]).to be_nil expect(subject.get("hello")).to be_nil
expect(subject["fancy"]).to eq("pants") expect(subject.get("fancy")).to eq("pants")
expect(subject["free"]).to be_nil expect(subject.get("free")).to be_nil
end end
end end
@ -102,31 +102,31 @@ describe "conditionals in filter" do
CONFIG CONFIG
sample("foo" => "bar", "nest" => 124) do sample("foo" => "bar", "nest" => 124) do
expect(subject["always"]).to be_nil expect(subject.get("always")).to be_nil
expect(subject["hello"]).to be_nil expect(subject.get("hello")).to be_nil
expect(subject["fancy"]).to be_nil expect(subject.get("fancy")).to be_nil
expect(subject["free"]).to be_nil expect(subject.get("free")).to be_nil
end end
sample("foo" => "bar", "nest" => 123) do sample("foo" => "bar", "nest" => 123) do
expect(subject["always"]).to eq("awesome") expect(subject.get("always")).to eq("awesome")
expect(subject["hello"]).to eq("world") expect(subject.get("hello")).to eq("world")
expect(subject["fancy"]).to be_nil expect(subject.get("fancy")).to be_nil
expect(subject["free"]).to be_nil expect(subject.get("free")).to be_nil
end end
sample("notfoo" => "bar", "nest" => 123) do sample("notfoo" => "bar", "nest" => 123) do
expect(subject["always"]).to eq("awesome") expect(subject.get("always")).to eq("awesome")
expect(subject["hello"]).to be_nil expect(subject.get("hello")).to be_nil
expect(subject["fancy"]).to be_nil expect(subject.get("fancy")).to be_nil
expect(subject["free"]).to eq("hugs") expect(subject.get("free")).to eq("hugs")
end end
sample("bar" => "baz", "nest" => 123) do sample("bar" => "baz", "nest" => 123) do
expect(subject["always"]).to eq("awesome") expect(subject.get("always")).to eq("awesome")
expect(subject["hello"]).to be_nil expect(subject.get("hello")).to be_nil
expect(subject["fancy"]).to eq("pants") expect(subject.get("fancy")).to eq("pants")
expect(subject["free"]).to be_nil expect(subject.get("free")).to be_nil
end end
end end
@ -140,7 +140,7 @@ describe "conditionals in filter" do
CONFIG CONFIG
sample("foo" => 123, "bar" => 123) do sample("foo" => 123, "bar" => 123) do
expect(subject["tags"] ).to include("woot") expect(subject.get("tags") ).to include("woot")
end end
end end
@ -169,12 +169,12 @@ describe "conditionals in filter" do
CONFIG CONFIG
sample("foo" => "foo", "foobar" => "foobar", "greeting" => "hello world") do sample("foo" => "foo", "foobar" => "foobar", "greeting" => "hello world") do
expect(subject["tags"]).to include("field in field") expect(subject.get("tags")).to include("field in field")
expect(subject["tags"]).to include("field in string") expect(subject.get("tags")).to include("field in string")
expect(subject["tags"]).to include("string in field") expect(subject.get("tags")).to include("string in field")
expect(subject["tags"]).to include("field in list") expect(subject.get("tags")).to include("field in list")
expect(subject["tags"]).not_to include("shouldnotexist") expect(subject.get("tags")).not_to include("shouldnotexist")
expect(subject["tags"]).to include("shouldexist") expect(subject.get("tags")).to include("shouldexist")
end end
end end
@ -192,107 +192,107 @@ describe "conditionals in filter" do
sample("foo" => "foo", "somelist" => [ "one", "two" ], "foobar" => "foobar", "greeting" => "hello world", "tags" => [ "fancypantsy" ]) do sample("foo" => "foo", "somelist" => [ "one", "two" ], "foobar" => "foobar", "greeting" => "hello world", "tags" => [ "fancypantsy" ]) do
# verify the original exists # verify the original exists
expect(subject["tags"]).to include("fancypantsy") expect(subject.get("tags")).to include("fancypantsy")
expect(subject["tags"]).to include("baz") expect(subject.get("tags")).to include("baz")
expect(subject["tags"]).not_to include("foo") expect(subject.get("tags")).not_to include("foo")
expect(subject["tags"]).to include("notfoo") expect(subject.get("tags")).to include("notfoo")
expect(subject["tags"]).to include("notsomelist") expect(subject.get("tags")).to include("notsomelist")
expect(subject["tags"]).not_to include("somelist") expect(subject.get("tags")).not_to include("somelist")
expect(subject["tags"]).to include("no string in missing field") expect(subject.get("tags")).to include("no string in missing field")
end end
end end
describe "operators" do describe "operators" do
conditional "[message] == 'sample'" do conditional "[message] == 'sample'" do
sample("sample") { expect(subject["tags"] ).to include("success") } sample("sample") { expect(subject.get("tags") ).to include("success") }
sample("different") { expect(subject["tags"] ).to include("failure") } sample("different") { expect(subject.get("tags") ).to include("failure") }
end end
conditional "[message] != 'sample'" do conditional "[message] != 'sample'" do
sample("sample") { expect(subject["tags"] ).to include("failure") } sample("sample") { expect(subject.get("tags") ).to include("failure") }
sample("different") { expect(subject["tags"] ).to include("success") } sample("different") { expect(subject.get("tags") ).to include("success") }
end end
conditional "[message] < 'sample'" do conditional "[message] < 'sample'" do
sample("apple") { expect(subject["tags"] ).to include("success") } sample("apple") { expect(subject.get("tags") ).to include("success") }
sample("zebra") { expect(subject["tags"] ).to include("failure") } sample("zebra") { expect(subject.get("tags") ).to include("failure") }
end end
conditional "[message] > 'sample'" do conditional "[message] > 'sample'" do
sample("zebra") { expect(subject["tags"] ).to include("success") } sample("zebra") { expect(subject.get("tags") ).to include("success") }
sample("apple") { expect(subject["tags"] ).to include("failure") } sample("apple") { expect(subject.get("tags") ).to include("failure") }
end end
conditional "[message] <= 'sample'" do conditional "[message] <= 'sample'" do
sample("apple") { expect(subject["tags"] ).to include("success") } sample("apple") { expect(subject.get("tags") ).to include("success") }
sample("zebra") { expect(subject["tags"] ).to include("failure") } sample("zebra") { expect(subject.get("tags") ).to include("failure") }
sample("sample") { expect(subject["tags"] ).to include("success") } sample("sample") { expect(subject.get("tags") ).to include("success") }
end end
conditional "[message] >= 'sample'" do conditional "[message] >= 'sample'" do
sample("zebra") { expect(subject["tags"] ).to include("success") } sample("zebra") { expect(subject.get("tags") ).to include("success") }
sample("sample") { expect(subject["tags"] ).to include("success") } sample("sample") { expect(subject.get("tags") ).to include("success") }
sample("apple") { expect(subject["tags"] ).to include("failure") } sample("apple") { expect(subject.get("tags") ).to include("failure") }
end end
conditional "[message] =~ /sample/" do conditional "[message] =~ /sample/" do
sample("apple") { expect(subject["tags"] ).to include("failure") } sample("apple") { expect(subject.get("tags") ).to include("failure") }
sample("sample") { expect(subject["tags"] ).to include("success") } sample("sample") { expect(subject.get("tags") ).to include("success") }
sample("some sample") { expect(subject["tags"] ).to include("success") } sample("some sample") { expect(subject.get("tags") ).to include("success") }
end end
conditional "[message] !~ /sample/" do conditional "[message] !~ /sample/" do
sample("apple") { expect(subject["tags"]).to include("success") } sample("apple") { expect(subject.get("tags")).to include("success") }
sample("sample") { expect(subject["tags"]).to include("failure") } sample("sample") { expect(subject.get("tags")).to include("failure") }
sample("some sample") { expect(subject["tags"]).to include("failure") } sample("some sample") { expect(subject.get("tags")).to include("failure") }
end end
end end
describe "negated expressions" do describe "negated expressions" do
conditional "!([message] == 'sample')" do conditional "!([message] == 'sample')" do
sample("sample") { expect(subject["tags"]).not_to include("success") } sample("sample") { expect(subject.get("tags")).not_to include("success") }
sample("different") { expect(subject["tags"]).not_to include("failure") } sample("different") { expect(subject.get("tags")).not_to include("failure") }
end end
conditional "!([message] != 'sample')" do conditional "!([message] != 'sample')" do
sample("sample") { expect(subject["tags"]).not_to include("failure") } sample("sample") { expect(subject.get("tags")).not_to include("failure") }
sample("different") { expect(subject["tags"]).not_to include("success") } sample("different") { expect(subject.get("tags")).not_to include("success") }
end end
conditional "!([message] < 'sample')" do conditional "!([message] < 'sample')" do
sample("apple") { expect(subject["tags"]).not_to include("success") } sample("apple") { expect(subject.get("tags")).not_to include("success") }
sample("zebra") { expect(subject["tags"]).not_to include("failure") } sample("zebra") { expect(subject.get("tags")).not_to include("failure") }
end end
conditional "!([message] > 'sample')" do conditional "!([message] > 'sample')" do
sample("zebra") { expect(subject["tags"]).not_to include("success") } sample("zebra") { expect(subject.get("tags")).not_to include("success") }
sample("apple") { expect(subject["tags"]).not_to include("failure") } sample("apple") { expect(subject.get("tags")).not_to include("failure") }
end end
conditional "!([message] <= 'sample')" do conditional "!([message] <= 'sample')" do
sample("apple") { expect(subject["tags"]).not_to include("success") } sample("apple") { expect(subject.get("tags")).not_to include("success") }
sample("zebra") { expect(subject["tags"]).not_to include("failure") } sample("zebra") { expect(subject.get("tags")).not_to include("failure") }
sample("sample") { expect(subject["tags"]).not_to include("success") } sample("sample") { expect(subject.get("tags")).not_to include("success") }
end end
conditional "!([message] >= 'sample')" do conditional "!([message] >= 'sample')" do
sample("zebra") { expect(subject["tags"]).not_to include("success") } sample("zebra") { expect(subject.get("tags")).not_to include("success") }
sample("sample") { expect(subject["tags"]).not_to include("success") } sample("sample") { expect(subject.get("tags")).not_to include("success") }
sample("apple") { expect(subject["tags"]).not_to include("failure") } sample("apple") { expect(subject.get("tags")).not_to include("failure") }
end end
conditional "!([message] =~ /sample/)" do conditional "!([message] =~ /sample/)" do
sample("apple") { expect(subject["tags"]).not_to include("failure") } sample("apple") { expect(subject.get("tags")).not_to include("failure") }
sample("sample") { expect(subject["tags"]).not_to include("success") } sample("sample") { expect(subject.get("tags")).not_to include("success") }
sample("some sample") { expect(subject["tags"]).not_to include("success") } sample("some sample") { expect(subject.get("tags")).not_to include("success") }
end end
conditional "!([message] !~ /sample/)" do conditional "!([message] !~ /sample/)" do
sample("apple") { expect(subject["tags"]).not_to include("success") } sample("apple") { expect(subject.get("tags")).not_to include("success") }
sample("sample") { expect(subject["tags"]).not_to include("failure") } sample("sample") { expect(subject.get("tags")).not_to include("failure") }
sample("some sample") { expect(subject["tags"]).not_to include("failure") } sample("some sample") { expect(subject.get("tags")).not_to include("failure") }
end end
end end
@ -300,47 +300,47 @@ describe "conditionals in filter" do
describe "value as an expression" do describe "value as an expression" do
# testing that a field has a value should be true. # testing that a field has a value should be true.
conditional "[message]" do conditional "[message]" do
sample("apple") { expect(subject["tags"]).to include("success") } sample("apple") { expect(subject.get("tags")).to include("success") }
sample("sample") { expect(subject["tags"]).to include("success") } sample("sample") { expect(subject.get("tags")).to include("success") }
sample("some sample") { expect(subject["tags"]).to include("success") } sample("some sample") { expect(subject.get("tags")).to include("success") }
end end
# testing that a missing field has a value should be false. # testing that a missing field has a value should be false.
conditional "[missing]" do conditional "[missing]" do
sample("apple") { expect(subject["tags"]).to include("failure") } sample("apple") { expect(subject.get("tags")).to include("failure") }
sample("sample") { expect(subject["tags"]).to include("failure") } sample("sample") { expect(subject.get("tags")).to include("failure") }
sample("some sample") { expect(subject["tags"]).to include("failure") } sample("some sample") { expect(subject.get("tags")).to include("failure") }
end end
end end
describe "logic operators" do describe "logic operators" do
describe "and" do describe "and" do
conditional "[message] and [message]" do conditional "[message] and [message]" do
sample("whatever") { expect(subject["tags"]).to include("success") } sample("whatever") { expect(subject.get("tags")).to include("success") }
end end
conditional "[message] and ![message]" do conditional "[message] and ![message]" do
sample("whatever") { expect(subject["tags"]).to include("failure") } sample("whatever") { expect(subject.get("tags")).to include("failure") }
end end
conditional "![message] and [message]" do conditional "![message] and [message]" do
sample("whatever") { expect(subject["tags"]).to include("failure") } sample("whatever") { expect(subject.get("tags")).to include("failure") }
end end
conditional "![message] and ![message]" do conditional "![message] and ![message]" do
sample("whatever") { expect(subject["tags"]).to include("failure") } sample("whatever") { expect(subject.get("tags")).to include("failure") }
end end
end end
describe "or" do describe "or" do
conditional "[message] or [message]" do conditional "[message] or [message]" do
sample("whatever") { expect(subject["tags"]).to include("success") } sample("whatever") { expect(subject.get("tags")).to include("success") }
end end
conditional "[message] or ![message]" do conditional "[message] or ![message]" do
sample("whatever") { expect(subject["tags"]).to include("success") } sample("whatever") { expect(subject.get("tags")).to include("success") }
end end
conditional "![message] or [message]" do conditional "![message] or [message]" do
sample("whatever") { expect(subject["tags"]).to include("success") } sample("whatever") { expect(subject.get("tags")).to include("success") }
end end
conditional "![message] or ![message]" do conditional "![message] or ![message]" do
sample("whatever") { expect(subject["tags"]).to include("failure") } sample("whatever") { expect(subject.get("tags")).to include("failure") }
end end
end end
end end
@ -348,19 +348,19 @@ describe "conditionals in filter" do
describe "field references" do describe "field references" do
conditional "[field with space]" do conditional "[field with space]" do
sample("field with space" => "hurray") do sample("field with space" => "hurray") do
expect(subject["tags"]).to include("success") expect(subject.get("tags")).to include("success")
end end
end end
conditional "[field with space] == 'hurray'" do conditional "[field with space] == 'hurray'" do
sample("field with space" => "hurray") do sample("field with space" => "hurray") do
expect(subject["tags"]).to include("success") expect(subject.get("tags")).to include("success")
end end
end end
conditional "[nested field][reference with][some spaces] == 'hurray'" do conditional "[nested field][reference with][some spaces] == 'hurray'" do
sample({"nested field" => { "reference with" => { "some spaces" => "hurray" } } }) do sample({"nested field" => { "reference with" => { "some spaces" => "hurray" } } }) do
expect(subject["tags"]).to include("success") expect(subject.get("tags")).to include("success")
end end
end end
end end
@ -385,13 +385,13 @@ describe "conditionals in filter" do
expect(subject).to be_an(Array) expect(subject).to be_an(Array)
expect(subject.length).to eq(2) expect(subject.length).to eq(2)
expect(subject[0]["type"]).to eq("original") expect(subject[0].get("type")).to eq("original")
expect(subject[0]["cond1"]).to eq("true") expect(subject[0].get("cond1")).to eq("true")
expect(subject[0]["cond2"]).to eq(nil) expect(subject[0].get("cond2")).to eq(nil)
expect(subject[1]["type"]).to eq("clone") expect(subject[1].get("type")).to eq("clone")
# expect(subject[1]["cond1"]).to eq(nil) # expect(subject[1].get("cond1")).to eq(nil)
# expect(subject[1]["cond2"]).to eq("true") # expect(subject[1].get("cond2")).to eq("true")
end end
end end
@ -413,16 +413,16 @@ describe "conditionals in filter" do
sample({"type" => "original"}) do sample({"type" => "original"}) do
# puts subject.inspect # puts subject.inspect
expect(subject[0]["cond1"]).to eq(nil) expect(subject[0].get("cond1")).to eq(nil)
expect(subject[0]["cond2"]).to eq(nil) expect(subject[0].get("cond2")).to eq(nil)
expect(subject[1]["type"]).to eq("clone1") expect(subject[1].get("type")).to eq("clone1")
expect(subject[1]["cond1"]).to eq("true") expect(subject[1].get("cond1")).to eq("true")
expect(subject[1]["cond2"]).to eq(nil) expect(subject[1].get("cond2")).to eq(nil)
expect(subject[2]["type"]).to eq("clone2") expect(subject[2].get("type")).to eq("clone2")
expect(subject[2]["cond1"]).to eq(nil) expect(subject[2].get("cond1")).to eq(nil)
expect(subject[2]["cond2"]).to eq("true") expect(subject[2].get("cond2")).to eq("true")
end end
end end

View file

@ -62,7 +62,7 @@ describe LogStash::Filters::NOOP do
CONFIG CONFIG
sample "example" do sample "example" do
insist { subject["new_field"] } == ["new_value", "new_value_2"] insist { subject.get("new_field") } == ["new_value", "new_value_2"]
end end
end end
@ -76,7 +76,7 @@ describe LogStash::Filters::NOOP do
CONFIG CONFIG
sample("type" => "noop") do sample("type" => "noop") do
insist { subject["tags"] } == ["test"] insist { subject.get("tags") } == ["test"]
end end
end end
@ -90,11 +90,11 @@ describe LogStash::Filters::NOOP do
CONFIG CONFIG
sample("type" => "noop") do sample("type" => "noop") do
insist { subject["tags"] } == ["test"] insist { subject.get("tags") } == ["test"]
end end
sample("type" => "noop", "tags" => ["t1", "t2"]) do sample("type" => "noop", "tags" => ["t1", "t2"]) do
insist { subject["tags"] } == ["t1", "t2", "test"] insist { subject.get("tags") } == ["t1", "t2", "test"]
end end
end end
@ -108,19 +108,19 @@ describe LogStash::Filters::NOOP do
CONFIG CONFIG
sample("type" => "noop") do sample("type" => "noop") do
insist { subject["tags"] } == ["test"] insist { subject.get("tags") } == ["test"]
end end
sample("type" => "noop", "tags" => ["t1"]) do sample("type" => "noop", "tags" => ["t1"]) do
insist { subject["tags"] } == ["t1", "test"] insist { subject.get("tags") } == ["t1", "test"]
end end
sample("type" => "noop", "tags" => ["t1", "t2"]) do sample("type" => "noop", "tags" => ["t1", "t2"]) do
insist { subject["tags"] } == ["t1", "t2", "test"] insist { subject.get("tags") } == ["t1", "t2", "test"]
end end
sample("type" => "noop", "tags" => ["t1", "t2", "t3"]) do sample("type" => "noop", "tags" => ["t1", "t2", "t3"]) do
insist { subject["tags"] } == ["t1", "t2", "t3", "test"] insist { subject.get("tags") } == ["t1", "t2", "t3", "test"]
end end
end end
@ -134,27 +134,27 @@ describe LogStash::Filters::NOOP do
CONFIG CONFIG
sample("type" => "noop", "tags" => ["t4"]) do sample("type" => "noop", "tags" => ["t4"]) do
insist { subject["tags"] } == ["t4"] insist { subject.get("tags") } == ["t4"]
end end
sample("type" => "noop", "tags" => ["t1", "t2", "t3"]) do sample("type" => "noop", "tags" => ["t1", "t2", "t3"]) do
insist { subject["tags"] } == ["t1"] insist { subject.get("tags") } == ["t1"]
end end
# also test from Json deserialized data to test the handling of native Java collections by JrJackson # also test from Json deserialized data to test the handling of native Java collections by JrJackson
# see https://github.com/elastic/logstash/issues/2261 # see https://github.com/elastic/logstash/issues/2261
sample(LogStash::Json.load("{\"type\":\"noop\", \"tags\":[\"t1\", \"t2\", \"t3\"]}")) do sample(LogStash::Json.load("{\"type\":\"noop\", \"tags\":[\"t1\", \"t2\", \"t3\"]}")) do
insist { subject["tags"] } == ["t1"] insist { subject.get("tags") } == ["t1"]
end end
sample("type" => "noop", "tags" => ["t1", "t2"]) do sample("type" => "noop", "tags" => ["t1", "t2"]) do
insist { subject["tags"] } == ["t1"] insist { subject.get("tags") } == ["t1"]
end end
# also test from Json deserialized data to test the handling of native Java collections by JrJackson # also test from Json deserialized data to test the handling of native Java collections by JrJackson
# see https://github.com/elastic/logstash/issues/2261 # see https://github.com/elastic/logstash/issues/2261
sample(LogStash::Json.load("{\"type\":\"noop\", \"tags\":[\"t1\", \"t2\"]}")) do sample(LogStash::Json.load("{\"type\":\"noop\", \"tags\":[\"t1\", \"t2\"]}")) do
insist { subject["tags"] } == ["t1"] insist { subject.get("tags") } == ["t1"]
end end
end end
@ -168,13 +168,13 @@ describe LogStash::Filters::NOOP do
CONFIG CONFIG
sample("type" => "noop", "tags" => ["t1", "goaway", "t3"], "blackhole" => "goaway") do sample("type" => "noop", "tags" => ["t1", "goaway", "t3"], "blackhole" => "goaway") do
insist { subject["tags"] } == ["t1", "t3"] insist { subject.get("tags") } == ["t1", "t3"]
end end
# also test from Json deserialized data to test the handling of native Java collections by JrJackson # also test from Json deserialized data to test the handling of native Java collections by JrJackson
# see https://github.com/elastic/logstash/issues/2261 # see https://github.com/elastic/logstash/issues/2261
sample(LogStash::Json.load("{\"type\":\"noop\", \"tags\":[\"t1\", \"goaway\", \"t3\"], \"blackhole\":\"goaway\"}")) do sample(LogStash::Json.load("{\"type\":\"noop\", \"tags\":[\"t1\", \"goaway\", \"t3\"], \"blackhole\":\"goaway\"}")) do
insist { subject["tags"] } == ["t1", "t3"] insist { subject.get("tags") } == ["t1", "t3"]
end end
end end
@ -230,7 +230,7 @@ describe LogStash::Filters::NOOP do
sample("type" => "noop", "t1" => ["t2", "t3"]) do sample("type" => "noop", "t1" => ["t2", "t3"]) do
insist { subject }.include?("t1") insist { subject }.include?("t1")
insist { subject["[t1][0]"] } == "t3" insist { subject.get("[t1][0]") } == "t3"
end end
end end

View file

@ -15,50 +15,50 @@ describe "LogStash::Inputs::Base#decorate" do
input = LogStash::Inputs::NOOP.new("tags" => "value") input = LogStash::Inputs::NOOP.new("tags" => "value")
evt = LogStash::Event.new({"type" => "noop"}) evt = LogStash::Event.new({"type" => "noop"})
input.instance_eval {decorate(evt)} input.instance_eval {decorate(evt)}
expect(evt["tags"]).to eq(["value"]) expect(evt.get("tags")).to eq(["value"])
end end
it "should add multiple tag" do it "should add multiple tag" do
input = LogStash::Inputs::NOOP.new("tags" => ["value1","value2"]) input = LogStash::Inputs::NOOP.new("tags" => ["value1","value2"])
evt = LogStash::Event.new({"type" => "noop"}) evt = LogStash::Event.new({"type" => "noop"})
input.instance_eval {decorate(evt)} input.instance_eval {decorate(evt)}
expect(evt["tags"]).to eq(["value1","value2"]) expect(evt.get("tags")).to eq(["value1","value2"])
end end
it "should allow duplicates tag" do it "should allow duplicates tag" do
input = LogStash::Inputs::NOOP.new("tags" => ["value","value"]) input = LogStash::Inputs::NOOP.new("tags" => ["value","value"])
evt = LogStash::Event.new({"type" => "noop"}) evt = LogStash::Event.new({"type" => "noop"})
input.instance_eval {decorate(evt)} input.instance_eval {decorate(evt)}
expect(evt["tags"]).to eq(["value","value"]) expect(evt.get("tags")).to eq(["value","value"])
end end
it "should add tag with sprintf" do it "should add tag with sprintf" do
input = LogStash::Inputs::NOOP.new("tags" => "%{type}") input = LogStash::Inputs::NOOP.new("tags" => "%{type}")
evt = LogStash::Event.new({"type" => "noop"}) evt = LogStash::Event.new({"type" => "noop"})
input.instance_eval {decorate(evt)} input.instance_eval {decorate(evt)}
expect(evt["tags"]).to eq(["noop"]) expect(evt.get("tags")).to eq(["noop"])
end end
it "should add single field" do it "should add single field" do
input = LogStash::Inputs::NOOP.new("add_field" => {"field" => "value"}) input = LogStash::Inputs::NOOP.new("add_field" => {"field" => "value"})
evt = LogStash::Event.new({"type" => "noop"}) evt = LogStash::Event.new({"type" => "noop"})
input.instance_eval {decorate(evt)} input.instance_eval {decorate(evt)}
expect(evt["field"]).to eq("value") expect(evt.get("field")).to eq("value")
end end
it "should add single field with sprintf" do it "should add single field with sprintf" do
input = LogStash::Inputs::NOOP.new("add_field" => {"%{type}" => "%{type}"}) input = LogStash::Inputs::NOOP.new("add_field" => {"%{type}" => "%{type}"})
evt = LogStash::Event.new({"type" => "noop"}) evt = LogStash::Event.new({"type" => "noop"})
input.instance_eval {decorate(evt)} input.instance_eval {decorate(evt)}
expect(evt["noop"]).to eq("noop") expect(evt.get("noop")).to eq("noop")
end end
it "should add multiple field" do it "should add multiple field" do
input = LogStash::Inputs::NOOP.new("add_field" => {"field" => ["value1", "value2"], "field2" => "value"}) input = LogStash::Inputs::NOOP.new("add_field" => {"field" => ["value1", "value2"], "field2" => "value"})
evt = LogStash::Event.new({"type" => "noop"}) evt = LogStash::Event.new({"type" => "noop"})
input.instance_eval {decorate(evt)} input.instance_eval {decorate(evt)}
expect(evt["field"]).to eq(["value1","value2"]) expect(evt.get("field")).to eq(["value1","value2"])
expect(evt["field2"]).to eq("value") expect(evt.get("field2")).to eq("value")
end end
end end

View file

@ -279,7 +279,7 @@ describe LogStash::Pipeline do
CONFIG CONFIG
sample("hello") do sample("hello") do
expect(subject["message"]).to eq("hello") expect(subject.get("message")).to eq("hello")
end end
end end
@ -299,10 +299,10 @@ describe LogStash::Pipeline do
sample(["foo", "bar"]) do sample(["foo", "bar"]) do
expect(subject.size).to eq(2) expect(subject.size).to eq(2)
expect(subject[0]["message"]).to eq("foo\nbar") expect(subject[0].get("message")).to eq("foo\nbar")
expect(subject[0]["type"]).to be_nil expect(subject[0].get("type")).to be_nil
expect(subject[1]["message"]).to eq("foo\nbar") expect(subject[1].get("message")).to eq("foo\nbar")
expect(subject[1]["type"]).to eq("clone1") expect(subject[1].get("type")).to eq("clone1")
end end
end end
end end
@ -354,17 +354,17 @@ describe LogStash::Pipeline do
sample("hello") do sample("hello") do
expect(subject.size).to eq(3) expect(subject.size).to eq(3)
expect(subject[0]["message"]).to eq("hello") expect(subject[0].get("message")).to eq("hello")
expect(subject[0]["type"]).to be_nil expect(subject[0].get("type")).to be_nil
expect(subject[0]["foo"]).to eq("bar") expect(subject[0].get("foo")).to eq("bar")
expect(subject[1]["message"]).to eq("hello") expect(subject[1].get("message")).to eq("hello")
expect(subject[1]["type"]).to eq("clone1") expect(subject[1].get("type")).to eq("clone1")
expect(subject[1]["foo"]).to eq("bar") expect(subject[1].get("foo")).to eq("bar")
expect(subject[2]["message"]).to eq("hello") expect(subject[2].get("message")).to eq("hello")
expect(subject[2]["type"]).to eq("clone2") expect(subject[2].get("type")).to eq("clone2")
expect(subject[2]["foo"]).to eq("bar") expect(subject[2].get("foo")).to eq("bar")
end end
end end
end end
@ -441,7 +441,7 @@ describe LogStash::Pipeline do
# give us a bit of time to flush the events # give us a bit of time to flush the events
wait(5).for do wait(5).for do
next unless output && output.events && output.events.first next unless output && output.events && output.events.first
output.events.first["message"].split("\n").count output.events.first.get("message").split("\n").count
end.to eq(number_of_events) end.to eq(number_of_events)
pipeline.shutdown pipeline.shutdown
end end