logstash-core-event 2.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/logstash-core-event.rb +1 -0
- data/lib/logstash-core-event/logstash-core-event.rb +5 -0
- data/lib/logstash-core-event/version.rb +8 -0
- data/lib/logstash/event.rb +278 -0
- data/lib/logstash/string_interpolation.rb +150 -0
- data/lib/logstash/timestamp.rb +97 -0
- data/lib/logstash/util/accessors.rb +123 -0
- data/logstash-core-event.gemspec +23 -0
- data/spec/logstash/event_spec.rb +533 -0
- data/spec/logstash/timestamp_spec.rb +109 -0
- data/spec/logstash/util/accessors_spec.rb +179 -0
- metadata +62 -0
@@ -0,0 +1,109 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
require "logstash/timestamp"
|
4
|
+
|
5
|
+
describe LogStash::Timestamp do
|
6
|
+
|
7
|
+
it "should parse its own iso8601 output" do
|
8
|
+
t = Time.now
|
9
|
+
ts = LogStash::Timestamp.new(t)
|
10
|
+
expect(LogStash::Timestamp.parse_iso8601(ts.to_iso8601).to_i).to eq(t.to_i)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should coerce iso8601 string" do
|
14
|
+
t = Time.now
|
15
|
+
ts = LogStash::Timestamp.new(t)
|
16
|
+
expect(LogStash::Timestamp.coerce(ts.to_iso8601).to_i).to eq(t.to_i)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should coerce Time" do
|
20
|
+
t = Time.now
|
21
|
+
expect(LogStash::Timestamp.coerce(t).to_i).to eq(t.to_i)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should coerce Timestamp" do
|
25
|
+
t = LogStash::Timestamp.now
|
26
|
+
expect(LogStash::Timestamp.coerce(t).to_i).to eq(t.to_i)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should raise on invalid string coerce" do
|
30
|
+
expect{LogStash::Timestamp.coerce("foobar")}.to raise_error LogStash::TimestampParserError
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return nil on invalid object coerce" do
|
34
|
+
expect(LogStash::Timestamp.coerce(:foobar)).to be_nil
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should support to_json" do
|
38
|
+
expect(LogStash::Timestamp.parse_iso8601("2014-09-23T00:00:00-0800").to_json).to eq("\"2014-09-23T08:00:00.000Z\"")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should support to_json and ignore arguments" do
|
42
|
+
expect(LogStash::Timestamp.parse_iso8601("2014-09-23T00:00:00-0800").to_json(:some => 1, :argumnents => "test")).to eq("\"2014-09-23T08:00:00.000Z\"")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should support timestamp comparaison" do
|
46
|
+
current = LogStash::Timestamp.new(Time.now)
|
47
|
+
future = LogStash::Timestamp.new(Time.now + 100)
|
48
|
+
|
49
|
+
expect(future > current).to eq(true)
|
50
|
+
expect(future < current).to eq(false)
|
51
|
+
expect(current == current).to eq(true)
|
52
|
+
|
53
|
+
expect(current <=> current).to eq(0)
|
54
|
+
expect(current <=> future).to eq(-1)
|
55
|
+
expect(future <=> current).to eq(1)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should allow unary operation +" do
|
59
|
+
current = Time.now
|
60
|
+
t = LogStash::Timestamp.new(current) + 10
|
61
|
+
expect(t).to eq(current + 10)
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "subtraction" do
|
65
|
+
it "should work on a timestamp object" do
|
66
|
+
t = Time.now
|
67
|
+
current = LogStash::Timestamp.new(t)
|
68
|
+
future = LogStash::Timestamp.new(t + 10)
|
69
|
+
expect(future - current).to eq(10)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should work on with time object" do
|
73
|
+
current = Time.now
|
74
|
+
t = LogStash::Timestamp.new(current + 10)
|
75
|
+
expect(t - current).to eq(10)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should work with numeric value" do
|
79
|
+
current = Time.now
|
80
|
+
t = LogStash::Timestamp.new(current + 10)
|
81
|
+
expect(t - 10).to eq(current)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "identity methods" do
|
86
|
+
subject { LogStash::Timestamp.new }
|
87
|
+
|
88
|
+
it "should support utc" do
|
89
|
+
expect(subject.utc).to eq(subject)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should support gmtime" do
|
93
|
+
expect(subject.gmtime).to eq(subject)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "numeric casting methods" do
|
98
|
+
let (:now) {Time.now}
|
99
|
+
subject { LogStash::Timestamp.new(now) }
|
100
|
+
|
101
|
+
it "should support to_i" do
|
102
|
+
expect(subject.to_i).to eq(now.to_i)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should support to_f" do
|
106
|
+
expect(subject.to_f).to eq(now.to_f)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
# this is to skip specs when running agains an alternate logstash-core-event implementation
|
5
|
+
# that does not define the Accessors class. For example, in logstash-core-event-java
|
6
|
+
# the Accessors class does not exists in the Ruby namespace.
|
7
|
+
class_exists = begin
|
8
|
+
require "logstash/util/accessors"
|
9
|
+
true
|
10
|
+
rescue LoadError
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "LogStash::Util::Accessors", :if => class_exists do
|
15
|
+
|
16
|
+
context "using simple field" do
|
17
|
+
|
18
|
+
it "should get value of word key" do
|
19
|
+
str = "hello"
|
20
|
+
data = { "hello" => "world" }
|
21
|
+
accessors = LogStash::Util::Accessors.new(data)
|
22
|
+
expect(accessors.get(str)).to eq(data[str])
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should get value of key with spaces" do
|
26
|
+
str = "hel lo"
|
27
|
+
data = { "hel lo" => "world" }
|
28
|
+
accessors = LogStash::Util::Accessors.new(data)
|
29
|
+
expect(accessors.get(str)).to eq(data[str])
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should get value of numeric key string" do
|
33
|
+
str = "1"
|
34
|
+
data = { "1" => "world" }
|
35
|
+
accessors = LogStash::Util::Accessors.new(data)
|
36
|
+
expect(accessors.get(str)).to eq(data[str])
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should handle delete" do
|
40
|
+
str = "simple"
|
41
|
+
data = { "simple" => "things" }
|
42
|
+
accessors = LogStash::Util::Accessors.new(data)
|
43
|
+
expect(accessors.del(str)).to eq("things")
|
44
|
+
expect(data).to be_empty
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should handle delete on non-existent field" do
|
48
|
+
str = "[foo][bar]"
|
49
|
+
data = { "hello" => "world" }
|
50
|
+
accessors = LogStash::Util::Accessors.new(data)
|
51
|
+
expect(accessors.del(str)).to be_nil
|
52
|
+
expect(data).not_to be_empty
|
53
|
+
# assert no side effects
|
54
|
+
expect(accessors.get("foo")).to be_nil
|
55
|
+
expect(accessors.get("hello")).to eq("world")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should set string value" do
|
59
|
+
str = "simple"
|
60
|
+
data = {}
|
61
|
+
accessors = LogStash::Util::Accessors.new(data)
|
62
|
+
expect(accessors.set(str, "things")).to eq("things")
|
63
|
+
expect(data).to eq({ "simple" => "things" })
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should set array value" do
|
67
|
+
str = "simple"
|
68
|
+
data = {}
|
69
|
+
accessors = LogStash::Util::Accessors.new(data)
|
70
|
+
expect(accessors.set(str, ["foo", "bar"])).to eq(["foo", "bar"])
|
71
|
+
expect(data).to eq({ "simple" => ["foo", "bar"]})
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "using field path" do
|
76
|
+
|
77
|
+
it "should get shallow string value of word key" do
|
78
|
+
str = "[hello]"
|
79
|
+
data = { "hello" => "world" }
|
80
|
+
accessors = LogStash::Util::Accessors.new(data)
|
81
|
+
expect(accessors.get(str)).to eq("world")
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should get shallow string value of key with spaces" do
|
85
|
+
str = "[hel lo]"
|
86
|
+
data = { "hel lo" => "world" }
|
87
|
+
accessors = LogStash::Util::Accessors.new(data)
|
88
|
+
expect(accessors.get(str)).to eq("world")
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should get shallow string value of numeric key string" do
|
92
|
+
str = "[1]"
|
93
|
+
data = { "1" => "world" }
|
94
|
+
accessors = LogStash::Util::Accessors.new(data)
|
95
|
+
expect(accessors.get(str)).to eq("world")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should get deep string value" do
|
99
|
+
str = "[hello][world]"
|
100
|
+
data = { "hello" => { "world" => "foo", "bar" => "baz" } }
|
101
|
+
accessors = LogStash::Util::Accessors.new(data)
|
102
|
+
expect(accessors.get(str)).to eq(data["hello"]["world"])
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should return nil when getting a non-existant field (with no side-effects on original data)" do
|
106
|
+
str = "[hello][world]"
|
107
|
+
data = {}
|
108
|
+
accessors = LogStash::Util::Accessors.new(data)
|
109
|
+
expect(accessors.get(str)).to be_nil
|
110
|
+
expect(data).to be_empty
|
111
|
+
expect(accessors.set(str, "foo")).to eq("foo")
|
112
|
+
expect(data).to eq({ "hello" => {"world" => "foo"} })
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should handle delete" do
|
116
|
+
str = "[hello][world]"
|
117
|
+
data = { "hello" => { "world" => "foo", "bar" => "baz" } }
|
118
|
+
accessors = LogStash::Util::Accessors.new(data)
|
119
|
+
expect(accessors.del(str)).to eq("foo")
|
120
|
+
|
121
|
+
# Make sure the "world" key is removed.
|
122
|
+
expect(data["hello"]).to eq({ "bar" => "baz" })
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should set shallow string value" do
|
126
|
+
str = "[hello]"
|
127
|
+
data = {}
|
128
|
+
accessors = LogStash::Util::Accessors.new(data)
|
129
|
+
expect(accessors.set(str, "foo")).to eq("foo")
|
130
|
+
expect(data).to eq({ "hello" => "foo" })
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should set deep string value" do
|
134
|
+
str = "[hello][world]"
|
135
|
+
data = {}
|
136
|
+
accessors = LogStash::Util::Accessors.new(data)
|
137
|
+
expect(accessors.set(str, "foo")).to eq("foo")
|
138
|
+
expect(data).to eq({ "hello" => { "world" => "foo" } })
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should set deep array value" do
|
142
|
+
str = "[hello][world]"
|
143
|
+
data = {}
|
144
|
+
accessors = LogStash::Util::Accessors.new(data)
|
145
|
+
expect(accessors.set(str, ["foo", "bar"])).to eq(["foo", "bar"])
|
146
|
+
expect(data).to eq({ "hello" => { "world" => ["foo", "bar"] } })
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should set element within array value" do
|
150
|
+
str = "[hello][0]"
|
151
|
+
data = {"hello" => ["foo", "bar"]}
|
152
|
+
accessors = LogStash::Util::Accessors.new(data)
|
153
|
+
expect(accessors.set(str, "world") ).to eq("world")
|
154
|
+
expect(data).to eq({"hello" => ["world", "bar"]})
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should retrieve array item" do
|
158
|
+
data = { "hello" => { "world" => ["a", "b"], "bar" => "baz" } }
|
159
|
+
accessors = LogStash::Util::Accessors.new(data)
|
160
|
+
expect(accessors.get("[hello][world][0]")).to eq(data["hello"]["world"][0])
|
161
|
+
expect(accessors.get("[hello][world][1]")).to eq(data["hello"]["world"][1])
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should retrieve array item containing hash" do
|
165
|
+
data = { "hello" => { "world" => [ { "a" => 123 }, { "b" => 345 } ], "bar" => "baz" } }
|
166
|
+
accessors = LogStash::Util::Accessors.new(data)
|
167
|
+
expect(accessors.get("[hello][world][0][a]")).to eq(data["hello"]["world"][0]["a"])
|
168
|
+
expect(accessors.get("[hello][world][1][b]")).to eq(data["hello"]["world"][1]["b"])
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should handle delete of array element" do
|
172
|
+
str = "[geocoords][0]"
|
173
|
+
data = { "geocoords" => [4, 2] }
|
174
|
+
accessors = LogStash::Util::Accessors.new(data)
|
175
|
+
expect(accessors.del(str)).to eq(4)
|
176
|
+
expect(data).to eq({ "geocoords" => [2] })
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-core-event
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.2.0
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- Jordan Sissel
|
8
|
+
- Pete Fritchman
|
9
|
+
- Elasticsearch
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2016-02-01 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: The core event component of logstash, the scalable log and event management tool
|
16
|
+
email:
|
17
|
+
- jls@semicomplete.com
|
18
|
+
- petef@databits.net
|
19
|
+
- info@elasticsearch.com
|
20
|
+
executables: []
|
21
|
+
extensions: []
|
22
|
+
extra_rdoc_files: []
|
23
|
+
files:
|
24
|
+
- lib/logstash-core-event.rb
|
25
|
+
- lib/logstash-core-event/logstash-core-event.rb
|
26
|
+
- lib/logstash-core-event/version.rb
|
27
|
+
- lib/logstash/event.rb
|
28
|
+
- lib/logstash/string_interpolation.rb
|
29
|
+
- lib/logstash/timestamp.rb
|
30
|
+
- lib/logstash/util/accessors.rb
|
31
|
+
- logstash-core-event.gemspec
|
32
|
+
- spec/logstash/event_spec.rb
|
33
|
+
- spec/logstash/timestamp_spec.rb
|
34
|
+
- spec/logstash/util/accessors_spec.rb
|
35
|
+
homepage: http://www.elastic.co/guide/en/logstash/current/index.html
|
36
|
+
licenses:
|
37
|
+
- Apache License (2.0)
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 2.4.5
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: logstash-core-event - The core event component of logstash
|
59
|
+
test_files:
|
60
|
+
- spec/logstash/event_spec.rb
|
61
|
+
- spec/logstash/timestamp_spec.rb
|
62
|
+
- spec/logstash/util/accessors_spec.rb
|